Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(lineage): Add test for scroll across lineage #8728

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ public LineageScrollResult scrollAcrossLineage(@Nonnull Urn sourceUrn, @Nonnull
List<LineageRelationship> lineageRelationships =
filterRelationships(lineageResult, new HashSet<>(entities), inputFilters);

return getScrollResultInBatches(lineageRelationships, input != null ? input : "*", inputFilters, sortCriterion,
Filter reducedFilters =
SearchUtils.removeCriteria(inputFilters, criterion -> criterion.getField().equals(DEGREE_FILTER_INPUT));
return getScrollResultInBatches(lineageRelationships, input != null ? input : "*", reducedFilters, sortCriterion,
scrollId, keepAlive, size, searchFlags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,83 @@ public void testSearchService() throws Exception {

}

@Test
public void testScrollAcrossLineage() throws Exception {
when(_graphService.getLineage(eq(TEST_URN), eq(LineageDirection.DOWNSTREAM), anyInt(), anyInt(),
anyInt(), eq(null), eq(null))).thenReturn(mockResult(Collections.emptyList()));
LineageScrollResult scrollResult = scrollAcrossLineage(null, TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertNull(scrollResult.getScrollId());
scrollResult = scrollAcrossLineage(null, TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertNull(scrollResult.getScrollId());
clearCache(false);

when(_graphService.getLineage(eq(TEST_URN), eq(LineageDirection.DOWNSTREAM), anyInt(), anyInt(),
anyInt(), eq(null), eq(null))).thenReturn(
mockResult(ImmutableList.of(new LineageRelationship().setEntity(TEST_URN).setType("test").setDegree(1))));
// just testing null input does not throw any exception
scrollAcrossLineage(null, null);

scrollResult = scrollAcrossLineage(null, TEST);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertNull(scrollResult.getScrollId());
scrollResult = scrollAcrossLineage(null, TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertNull(scrollResult.getScrollId());
clearCache(false);

Urn urn = new TestEntityUrn("test1", "urn1", "VALUE_1");
ObjectNode document = JsonNodeFactory.instance.objectNode();
document.set("urn", JsonNodeFactory.instance.textNode(urn.toString()));
document.set("keyPart1", JsonNodeFactory.instance.textNode("test"));
document.set("textFieldOverride", JsonNodeFactory.instance.textNode("textFieldOverride"));
document.set("browsePaths", JsonNodeFactory.instance.textNode("/a/b/c"));
_elasticSearchService.upsertDocument(ENTITY_NAME, document.toString(), urn.toString());
syncAfterWrite(_bulkProcessor);

when(_graphService.getLineage(eq(TEST_URN), eq(LineageDirection.DOWNSTREAM), anyInt(), anyInt(),
anyInt(), eq(null), eq(null))).thenReturn(mockResult(Collections.emptyList()));
scrollResult = scrollAcrossLineage(null, TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertEquals(scrollResult.getEntities().size(), 0);
assertNull(scrollResult.getScrollId());
clearCache(false);

when(_graphService.getLineage(eq(TEST_URN), eq(LineageDirection.DOWNSTREAM), anyInt(), anyInt(),
anyInt(), eq(null), eq(null))).thenReturn(
mockResult(ImmutableList.of(new LineageRelationship().setEntity(urn).setType("test").setDegree(1))));
scrollResult = scrollAcrossLineage(null, TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 1);
assertEquals(scrollResult.getEntities().get(0).getEntity(), urn);
assertEquals(scrollResult.getEntities().get(0).getDegree().intValue(), 1);
assertNull(scrollResult.getScrollId());

scrollResult = scrollAcrossLineage(QueryUtils.newFilter("degree.keyword", "1"), TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 1);
assertEquals(scrollResult.getEntities().get(0).getEntity(), urn);
assertEquals(scrollResult.getEntities().get(0).getDegree().intValue(), 1);
assertNull(scrollResult.getScrollId());

scrollResult = scrollAcrossLineage(QueryUtils.newFilter("degree.keyword", "2"), TEST1);
assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertEquals(scrollResult.getEntities().size(), 0);
assertNull(scrollResult.getScrollId());
clearCache(false);

// Cleanup
_elasticSearchService.deleteDocument(ENTITY_NAME, urn.toString());
syncAfterWrite(_bulkProcessor);

when(_graphService.getLineage(eq(TEST_URN), eq(LineageDirection.DOWNSTREAM), anyInt(), anyInt(),
anyInt())).thenReturn(
mockResult(ImmutableList.of(new LineageRelationship().setEntity(urn).setType("test1").setDegree(1))));
scrollResult = scrollAcrossLineage(null, TEST1);

assertEquals(scrollResult.getNumEntities().intValue(), 0);
assertNull(scrollResult.getScrollId());
}

@Test
public void testLightningSearchService() throws Exception {
// Mostly this test ensures the code path is exercised
Expand Down Expand Up @@ -731,6 +808,16 @@ private LineageSearchResult searchAcrossLineage(@Nullable Filter filter, @Nullab
new SearchFlags().setSkipCache(true));
}

private LineageScrollResult scrollAcrossLineage(@Nullable Filter filter, @Nullable String input, String scrollId, int size) {
return _lineageSearchService.scrollAcrossLineage(TEST_URN, LineageDirection.DOWNSTREAM, ImmutableList.of(), input,
null, filter, null, scrollId, "5m", size, null, null,
new SearchFlags().setSkipCache(true));
}

private LineageScrollResult scrollAcrossLineage(@Nullable Filter filter, @Nullable String input) {
return scrollAcrossLineage(filter, input, null, 10);
}

@Test
public void testCanDoLightning() throws Exception {
Map<String, Integer> platformCounts = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void testSearchFieldConfig() throws IOException {
// this is a subfield therefore cannot have a subfield
assertFalse(test.hasKeywordSubfield());
assertFalse(test.hasDelimitedSubfield());
assertFalse(test.hasWordGramSubfields());

String[] fieldAndSubfield = test.fieldName().split("[.]", 2);

Expand Down
Loading