cecemei commented on code in PR #17774:
URL: https://github.com/apache/druid/pull/17774#discussion_r2019008847


##########
server/src/test/java/org/apache/druid/server/coordination/ServerManagerTest.java:
##########
@@ -123,103 +118,77 @@
 
 public class ServerManagerTest
 {
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
+  private static ImmutableSet<DataSegment> DATA_SEGMENTS = new 
ImmutableSet.Builder<DataSegment>()
+      .add(TestSegmentUtils.makeSegment("test", "1", 
Intervals.of("P1d/2011-04-01")))
+      .add(TestSegmentUtils.makeSegment("test", "1", 
Intervals.of("P1d/2011-04-02")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("P1d/2011-04-02")))
+      .add(TestSegmentUtils.makeSegment("test", "1", 
Intervals.of("P1d/2011-04-03")))
+      .add(TestSegmentUtils.makeSegment("test", "1", 
Intervals.of("P1d/2011-04-04")))
+      .add(TestSegmentUtils.makeSegment("test", "1", 
Intervals.of("P1d/2011-04-05")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("PT1h/2011-04-04T01")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("PT1h/2011-04-04T02")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("PT1h/2011-04-04T03")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("PT1h/2011-04-04T05")))
+      .add(TestSegmentUtils.makeSegment("test", "2", 
Intervals.of("PT1h/2011-04-04T06")))
+      .add(TestSegmentUtils.makeSegment("test2", "1", 
Intervals.of("P1d/2011-04-01")))
+      .add(TestSegmentUtils.makeSegment("test2", "1", 
Intervals.of("P1d/2011-04-02")))
+      .build();
+
+  @Bind
+  private QueryRunnerFactoryConglomerate conglomerate;
+  @Bind
+  private SegmentManager segmentManager;
+  @Bind
+  private AuthConfig authConfig;
+  @Bind
+  private ServerConfig serverConfig;
+  @Bind
+  private ServiceEmitter serviceEmitter;
+  @Bind
+  private QueryProcessingPool queryProcessingPool;
+  @Bind
+  private CachePopulator cachePopulator;
+  @Bind
+  @Smile
+  private ObjectMapper objectMapper;
+  @Bind
+  private Cache cache;
+  @Bind
+  private CacheConfig cacheConfig;
 
-  private ServerManager serverManager;
   private MyQueryRunnerFactory factory;
-  private CountDownLatch queryWaitLatch;
-  private CountDownLatch queryWaitYieldLatch;
-  private CountDownLatch queryNotifyLatch;
   private ExecutorService serverManagerExec;
-  private SegmentManager segmentManager;
 
-  @Rule
-  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+  @Inject
+  private ServerManager serverManager;
 
   @Before
   public void setUp()
   {
-    final SegmentLoaderConfig loaderConfig = new SegmentLoaderConfig()
-    {
-      @Override
-      public File getInfoDir()
-      {
-        return temporaryFolder.getRoot();
-      }
-
-      @Override
-      public List<StorageLocationConfig> getLocations()
-      {
-        return Collections.singletonList(
-            new StorageLocationConfig(temporaryFolder.getRoot(), null, null)
-        );
-      }
-    };
-
-    final List<StorageLocation> storageLocations = 
loaderConfig.toStorageLocations();
-    final SegmentLocalCacheManager localCacheManager = new 
SegmentLocalCacheManager(
-        storageLocations,
-        loaderConfig,
-        new LeastBytesUsedStorageLocationSelectorStrategy(storageLocations),
-        TestIndex.INDEX_IO,
-        TestHelper.makeJsonMapper()
-    )
-    {
-      @Override
-      public ReferenceCountingSegment getSegment(final DataSegment dataSegment)
-      {
-        if (dataSegment.isTombstone()) {
-          return ReferenceCountingSegment
-              
.wrapSegment(TombstoneSegmentizerFactory.segmentForTombstone(dataSegment), 
dataSegment.getShardSpec());
-        } else {
-          return ReferenceCountingSegment.wrapSegment(new 
TestSegmentUtils.SegmentForTesting(
-              dataSegment.getDataSource(),
-              (Interval) dataSegment.getLoadSpec().get("interval"),
-              MapUtils.getString(dataSegment.getLoadSpec(), "version")
-          ), dataSegment.getShardSpec());
-        }
-      }
-    };
+    serviceEmitter = new NoopServiceEmitter();
+    EmittingLogger.registerEmitter(new NoopServiceEmitter());
+    segmentManager = new SegmentManager(new 
TestSegmentCacheManager(DATA_SEGMENTS));
+    for (DataSegment segment : DATA_SEGMENTS) {
+      loadQueryable(segment.getDataSource(), segment.getVersion(), 
segment.getInterval());
+    }
 
-    segmentManager = new SegmentManager(localCacheManager);
+    factory = new MyQueryRunnerFactory(new CountDownLatch(1), new 
CountDownLatch(1), new CountDownLatch(1));
+    // Only SearchQuery is supported in this test.
+    conglomerate = 
DefaultQueryRunnerFactoryConglomerate.buildFromQueryRunnerFactories(ImmutableMap.of(
+        SearchQuery.class,
+        factory
+    ));
 
-    EmittingLogger.registerEmitter(new NoopServiceEmitter());
-    queryWaitLatch = new CountDownLatch(1);
-    queryWaitYieldLatch = new CountDownLatch(1);
-    queryNotifyLatch = new CountDownLatch(1);
-    factory = new MyQueryRunnerFactory(queryWaitLatch, queryWaitYieldLatch, 
queryNotifyLatch);
     serverManagerExec = Execs.multiThreaded(2, "ServerManagerTest-%d");
-    QueryRunnerFactoryConglomerate conglomerate = 
DefaultQueryRunnerFactoryConglomerate.buildFromQueryRunnerFactories(ImmutableMap
-        .<Class<? extends Query>, QueryRunnerFactory>builder()
-        .put(SearchQuery.class, factory)
-        .build());
-    serverManager = new ServerManager(
-        conglomerate,
-        new NoopServiceEmitter(),
-        new ForwardingQueryProcessingPool(serverManagerExec),
-        new ForegroundCachePopulator(new DefaultObjectMapper(), new 
CachePopulatorStats(), -1),
-        new DefaultObjectMapper(),
-        new LocalCacheProvider().get(),
-        new CacheConfig(),
-        segmentManager,
-        new ServerConfig()
-    );
-
-    loadQueryable("test", "1", Intervals.of("P1d/2011-04-01"));
-    loadQueryable("test", "1", Intervals.of("P1d/2011-04-02"));
-    loadQueryable("test", "2", Intervals.of("P1d/2011-04-02"));
-    loadQueryable("test", "1", Intervals.of("P1d/2011-04-03"));
-    loadQueryable("test", "1", Intervals.of("P1d/2011-04-04"));
-    loadQueryable("test", "1", Intervals.of("P1d/2011-04-05"));
-    loadQueryable("test", "2", Intervals.of("PT1h/2011-04-04T01"));
-    loadQueryable("test", "2", Intervals.of("PT1h/2011-04-04T02"));
-    loadQueryable("test", "2", Intervals.of("PT1h/2011-04-04T03"));
-    loadQueryable("test", "2", Intervals.of("PT1h/2011-04-04T05"));
-    loadQueryable("test", "2", Intervals.of("PT1h/2011-04-04T06"));
-    loadQueryable("test2", "1", Intervals.of("P1d/2011-04-01"));
-    loadQueryable("test2", "1", Intervals.of("P1d/2011-04-02"));
-    loadQueryable("testTombstone", "1", Intervals.of("P1d/2011-04-02"));
+    queryProcessingPool = new ForwardingQueryProcessingPool(serverManagerExec);
+    cachePopulator = new ForegroundCachePopulator(new DefaultObjectMapper(), 
new CachePopulatorStats(), -1);
+    objectMapper = new DefaultObjectMapper();
+    cache = new LocalCacheProvider().get();
+    cacheConfig = new CacheConfig();
+    serverConfig = new ServerConfig();
+    authConfig = new AuthConfig();
+
+    Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);

Review Comment:
   `BoundFieldModule` just creates a module from all the Bind annotation in the 
current class, the same thing if we do `binder -> binder.bind().toInstance()`. 
It does introduce another dependency guice:test-lib. Do you have any concerns 
on this type of injecting? 



-- 
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]

Reply via email to