@Test private void testListRRSs() { skipIfNoCredentials(); for (Zone zone : zones()) { for (ResourceRecordSet<?> geoRRS : geoApi(zone)) { assertNotNull(geoRRS.qualifier(), "Geo record sets should include a qualifier: " + geoRRS); checkGeoRRS(geoRRS); assertTrue(manager.provider().profileToRecordTypes().get("geo").contains(geoRRS.type())); getAnonymousLogger().info(format("%s ::: geoRRS: %s", manager, geoRRS)); recordTypeCounts.getUnchecked(geoRRS.type()).addAndGet(geoRRS.records().size()); geoRecordCounts.getUnchecked(geoRRS.geo()).addAndGet(geoRRS.records().size()); Iterator<ResourceRecordSet<?>> byNameAndType = geoApi(zone).iterateByNameAndType(geoRRS.name(), geoRRS.type()); assertTrue(byNameAndType.hasNext(), "could not list by name and type: " + geoRRS); assertTrue( Iterators.elementsEqual( geoApi(zone).iterateByNameAndType(geoRRS.name(), geoRRS.type()), byNameAndType)); ResourceRecordSet<?> byNameTypeAndQualifier = geoApi(zone) .getByNameTypeAndQualifier(geoRRS.name(), geoRRS.type(), geoRRS.qualifier()); assertNotNull( byNameTypeAndQualifier, "could not lookup by name, type, and qualifier: " + geoRRS); assertEquals(byNameTypeAndQualifier, geoRRS); } } logRecordSummary(); }
@Test public void testList() throws Exception { PageImpl<List<FieldValue>> tableDataPage = new PageImpl<>(null, "c", ROWS); expect(bigquery.listTableData(TABLE_ID1)).andReturn(tableDataPage); replay(bigquery); Page<List<FieldValue>> dataPage = table.list(); Iterator<List<FieldValue>> tableDataIterator = tableDataPage.values().iterator(); Iterator<List<FieldValue>> dataIterator = dataPage.values().iterator(); assertTrue(Iterators.elementsEqual(tableDataIterator, dataIterator)); }
/** * Determines whether two iterables contain equal elements in the same order. More specifically, * this method returns {@code true} if {@code iterable1} and {@code iterable2} contain the same * number of elements and every element of {@code iterable1} is equal to the corresponding element * of {@code iterable2}. */ public static boolean elementsEqual(Iterable<?> iterable1, Iterable<?> iterable2) { if (iterable1 instanceof Collection && iterable2 instanceof Collection) { Collection<?> collection1 = (Collection<?>) iterable1; Collection<?> collection2 = (Collection<?>) iterable2; if (collection1.size() != collection2.size()) { return false; } } return Iterators.elementsEqual(iterable1.iterator(), iterable2.iterator()); }
/** An implementation of {@link List#equals(Object)}. */ static boolean equalsImpl(List<?> thisList, Object other) { if (other == checkNotNull(thisList)) { return true; } if (!(other instanceof List)) { return false; } List<?> otherList = (List<?>) other; int size = thisList.size(); if (size != otherList.size()) { return false; } if (thisList instanceof RandomAccess && otherList instanceof RandomAccess) { // avoid allocation and use the faster loop for (int i = 0; i < size; i++) { if (!Objects.equal(thisList.get(i), otherList.get(i))) { return false; } } return true; } else { return Iterators.elementsEqual(thisList.iterator(), otherList.iterator()); } }