protected static SearchResponse assertResults(MetadataStorage mds, SearchRequest request, MetadataRecord firstResult, MetadataRecord... expectedResults) throws IOException { SearchResponse response = mds.search(request); Assert.assertEquals(ImmutableSet.<MetadataRecord>builder().add(firstResult).add(expectedResults).build(), ImmutableSet.copyOf(response.getResults())); return response; }
@Override public SearchResponse search(SearchRequest request) { return new SearchResponse(request, null, 0, Collections.emptyList()); } }
throw Throwables.propagate(e); Set<MetadataSearchResultRecord> resultRecords = result.getResults().stream() .map(record -> { Map<MetadataScope, co.cask.cdap.api.metadata.Metadata> metaMap = new HashMap<>(); .collect(toLinkedSet()); return new MetadataSearchResponse(sorting, request.getOffset(), request.getLimit(), Math.abs(request.getNumCursors()), result.getTotalResults(), resultRecords, result.getCursor() == null ? null : ImmutableList.of(result.getCursor()), request.shouldShowHidden(), request.getEntityScopes());
.setSorting(new Sorting(ENTITY_NAME_KEY, Sorting.Order.ASC)).build(), programRecord); Assert.assertNotNull(response.getCursor()); response = assertInOrder(mds, SearchRequest.of("*").addNamespace(ns1).setLimit(1).setCursorRequested(true) .setCursor(response.getCursor()).setSorting(new Sorting(ENTITY_NAME_KEY, Sorting.Order.ASC)) .build(), datasetRecord); Assert.assertNotNull(response.getCursor()); response = assertInOrder(mds, SearchRequest.of("*").addNamespace(ns1).setLimit(1).setCursorRequested(true) .setCursor(response.getCursor()).setSorting(new Sorting(ENTITY_NAME_KEY, Sorting.Order.ASC)) .build(), appRecord); Assert.assertNull(response.getCursor()); .setSorting(new Sorting(ENTITY_NAME_KEY, Sorting.Order.ASC)).build(), programRecord, datasetRecord); Assert.assertNotNull(response.getCursor()); Assert.assertEquals(3, response.getTotalResults()); response = assertInOrder(mds, SearchRequest.of("*").addNamespace(ns1).setLimit(2).setCursorRequested(true) .setCursor(response.getCursor()).setSorting(new Sorting(ENTITY_NAME_KEY, Sorting.Order.ASC)) .build(), appRecord); Assert.assertNull(response.getCursor());
protected static SearchResponse assertInOrder(MetadataStorage mds, SearchRequest request, MetadataRecord... expectedResults) throws IOException { SearchResponse response = mds.search(request); Assert.assertEquals(ImmutableList.copyOf(expectedResults), response.getResults()); return response; }
String cursor = response.getCursors() == null || response.getCursors().isEmpty() ? null : response.getCursors().get(0); return new SearchResponse(request, cursor, response.getTotal(), results);
private static void assertEmpty(MetadataStorage mds, SearchRequest request) throws IOException { Assert.assertTrue(mds.search(request).getResults().isEmpty()); }
Iterator<MetadataRecord> resultIter = response.getResults().iterator(); MetadataRecord[] results = { resultIter.next(), resultIter.next(), resultIter.next(), resultIter.next(), resultIter.next() };