github-advanced-security[bot] commented on code in PR #19374:
URL: https://github.com/apache/druid/pull/19374#discussion_r3146714201
##########
server/src/test/java/org/apache/druid/server/http/DataSourcesResourceTest.java:
##########
@@ -702,19 +722,180 @@
return ret;
}
};
- EasyMock.reset(inventoryView, databaseRuleManager);
+ EasyMock.reset(inventoryView, databaseRuleManager,
segmentsMetadataManager);
EasyMock.expect(databaseRuleManager.getRulesWithDefault(TestDataSource.WIKI))
.andReturn(ImmutableList.of(loadRule, dropRule))
.once();
+ EasyMock.expect(segmentsMetadataManager.getRecentDataSourcesSnapshot())
+
.andReturn(DataSourcesSnapshot.fromUsedSegments(ImmutableList.of(segment3)))
+ .once();
EasyMock.expect(inventoryView.getTimeline(new
TableDataSource(TestDataSource.WIKI)))
.andReturn(timeline)
.once();
- EasyMock.replay(inventoryView, databaseRuleManager);
+ EasyMock.replay(inventoryView, databaseRuleManager,
segmentsMetadataManager);
Response response3 =
dataSourcesResource.isHandOffComplete(TestDataSource.WIKI, interval3, 1, "v1");
Assert.assertTrue((boolean) response3.getEntity());
- EasyMock.verify(inventoryView, databaseRuleManager);
+ EasyMock.verify(inventoryView, databaseRuleManager,
segmentsMetadataManager);
+ }
+
+ @Test
+ public void testIsHandOffCompleteSegmentNotInMetadataReturnsTrue()
+ {
+ // A segment that hasn't been published to metadata yet (or has been
removed) is reported as definitively
+ // never-handed-off so the realtime task can move on.
+ MetadataRuleManager databaseRuleManager =
EasyMock.createMock(MetadataRuleManager.class);
+ Rule loadRule = new
IntervalLoadRule(Intervals.of("2013-01-01T00:00:00Z/2013-01-02T00:00:00Z"),
null, null);
+ DataSourcesResource dataSourcesResource =
+ new DataSourcesResource(
+ inventoryView,
+ segmentsMetadataManager,
+ databaseRuleManager,
+ null,
+ null,
+ null,
+ auditManager
+ );
+
EasyMock.expect(databaseRuleManager.getRulesWithDefault(TestDataSource.WIKI))
+ .andReturn(ImmutableList.of(loadRule))
+ .once();
+ EasyMock.expect(segmentsMetadataManager.getRecentDataSourcesSnapshot())
+
.andReturn(DataSourcesSnapshot.fromUsedSegments(ImmutableList.of()))
+ .once();
+ EasyMock.replay(databaseRuleManager, segmentsMetadataManager);
+
+ String interval = "2013-01-01T01:00:00Z/2013-01-01T02:00:00Z";
+ Response response =
dataSourcesResource.isHandOffComplete(TestDataSource.WIKI, interval, 1, "v1");
+ Assert.assertTrue((boolean) response.getEntity());
+
+ EasyMock.verify(databaseRuleManager, segmentsMetadataManager);
+ }
+
+ @Test
+ public void testIsHandOffCompleteWithPartialLoadRuleFallThrough()
+ {
+ // A FALL_THROUGH partial rule whose matcher does not resolve on the
segment (the projection it asks for is not
+ // present) should not halt the cascade. The next rule (drop) catches the
segment, so the response is true.
+ MetadataRuleManager databaseRuleManager =
EasyMock.createMock(MetadataRuleManager.class);
+ Interval ruleInterval =
Intervals.of("2013-01-01T00:00:00Z/2013-01-03T00:00:00Z");
+ Rule partialRule = new IntervalPartialLoadRule(
+ ruleInterval,
+ null,
+ null,
+ new ExactProjectionPartialLoadMatcher(ImmutableList.of("user_daily")),
+ CannotMatchBehavior.FALL_THROUGH
+ );
+ Rule dropRule = new IntervalDropRule(ruleInterval);
+ DataSourcesResource dataSourcesResource =
+ new DataSourcesResource(
+ inventoryView,
+ segmentsMetadataManager,
+ databaseRuleManager,
+ null,
+ null,
+ null,
+ auditManager
+ );
+
+ String interval = "2013-01-01T01:00:00Z/2013-01-01T02:00:00Z";
+ // Segment exposes projections [other_daily] which the partial rule's
matcher (asking for "user_daily") cannot
+ // resolve, so the partial rule falls through and the drop rule catches it.
+ DataSegment segment = buildHandoffSegment(
+ TestDataSource.WIKI,
+ Intervals.of(interval),
+ "v1",
+ 1,
+ ImmutableList.of("other_daily")
+ );
+
+
EasyMock.expect(databaseRuleManager.getRulesWithDefault(TestDataSource.WIKI))
+ .andReturn(ImmutableList.of(partialRule, dropRule))
+ .once();
+ EasyMock.expect(segmentsMetadataManager.getRecentDataSourcesSnapshot())
+
.andReturn(DataSourcesSnapshot.fromUsedSegments(ImmutableList.of(segment)))
+ .once();
+ EasyMock.replay(databaseRuleManager, segmentsMetadataManager);
+
+ Response response =
dataSourcesResource.isHandOffComplete(TestDataSource.WIKI, interval, 1, "v1");
+ Assert.assertTrue((boolean) response.getEntity());
+
+ EasyMock.verify(databaseRuleManager, segmentsMetadataManager);
+ }
+
+ @Test
+ public void testIsHandOffCompleteWithPartialLoadRuleMatcherResolves()
+ {
+ // A partial rule whose matcher does resolve on the segment applies
(loads), so the segment is "still waiting for
+ // handoff", the response is false until the timeline reflects it.
+ MetadataRuleManager databaseRuleManager =
EasyMock.createMock(MetadataRuleManager.class);
+ Interval ruleInterval =
Intervals.of("2013-01-01T00:00:00Z/2013-01-03T00:00:00Z");
+ Rule partialRule = new IntervalPartialLoadRule(
+ ruleInterval,
+ null,
+ null,
+ new ExactProjectionPartialLoadMatcher(ImmutableList.of("user_daily")),
+ CannotMatchBehavior.FALL_THROUGH
+ );
+ Rule dropRule = new IntervalDropRule(ruleInterval);
+ DataSourcesResource dataSourcesResource =
+ new DataSourcesResource(
+ inventoryView,
+ segmentsMetadataManager,
+ databaseRuleManager,
+ null,
+ null,
+ null,
+ auditManager
+ );
+
+ String interval = "2013-01-01T01:00:00Z/2013-01-01T02:00:00Z";
+ DataSegment segment = buildHandoffSegment(
+ TestDataSource.WIKI,
+ Intervals.of(interval),
+ "v1",
+ 1,
+ ImmutableList.of("user_daily")
+ );
+
+
EasyMock.expect(databaseRuleManager.getRulesWithDefault(TestDataSource.WIKI))
+ .andReturn(ImmutableList.of(partialRule, dropRule))
+ .once();
+ EasyMock.expect(segmentsMetadataManager.getRecentDataSourcesSnapshot())
+
.andReturn(DataSourcesSnapshot.fromUsedSegments(ImmutableList.of(segment)))
+ .once();
+ EasyMock.expect(inventoryView.getTimeline(new
TableDataSource(TestDataSource.WIKI)))
+ .andReturn(null)
+ .once();
+ EasyMock.replay(inventoryView, databaseRuleManager,
segmentsMetadataManager);
+
+ Response response =
dataSourcesResource.isHandOffComplete(TestDataSource.WIKI, interval, 1, "v1");
+ Assert.assertFalse((boolean) response.getEntity());
+
+ EasyMock.verify(inventoryView, databaseRuleManager,
segmentsMetadataManager);
+ }
+
+ private static DataSegment buildHandoffSegment(String dataSource, Interval
interval, String version, int partitionNumber)
+ {
+ return buildHandoffSegment(dataSource, interval, version, partitionNumber,
null);
+ }
+
+ private static DataSegment buildHandoffSegment(
+ String dataSource,
+ Interval interval,
+ String version,
+ int partitionNumber,
+ List<String> projections
+ )
+ {
+ return DataSegment.builder()
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [DataSegment.builder](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11142)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]