use of io.druid.client.coordinator.CoordinatorClient in project druid by druid-io.
the class CoordinatorBasedSegmentHandoffNotifierTest method testHandoffCallbackCalled.
@Test
public void testHandoffCallbackCalled() throws IOException, InterruptedException {
Interval interval = new Interval("2011-04-01/2011-04-02");
SegmentDescriptor descriptor = new SegmentDescriptor(interval, "v1", 2);
DataSegment segment = new DataSegment("test_ds", interval, "v1", null, null, null, new NumberedShardSpec(2, 3), 0, 0);
final AtomicBoolean callbackCalled = new AtomicBoolean(false);
CoordinatorClient coordinatorClient = EasyMock.createMock(CoordinatorClient.class);
EasyMock.expect(coordinatorClient.fetchServerView("test_ds", interval, true)).andReturn(Lists.newArrayList(new ImmutableSegmentLoadInfo(segment, Sets.newHashSet(createHistoricalServerMetadata("a1"))))).anyTimes();
EasyMock.replay(coordinatorClient);
CoordinatorBasedSegmentHandoffNotifier notifier = new CoordinatorBasedSegmentHandoffNotifier("test_ds", coordinatorClient, notifierConfig);
notifier.registerSegmentHandoffCallback(descriptor, MoreExecutors.sameThreadExecutor(), new Runnable() {
@Override
public void run() {
callbackCalled.set(true);
}
});
Assert.assertEquals(1, notifier.getHandOffCallbacks().size());
Assert.assertTrue(notifier.getHandOffCallbacks().containsKey(descriptor));
notifier.checkForSegmentHandoffs();
// callback should have been removed
Assert.assertTrue(notifier.getHandOffCallbacks().isEmpty());
Assert.assertTrue(callbackCalled.get());
EasyMock.verify(coordinatorClient);
}
use of io.druid.client.coordinator.CoordinatorClient in project druid by druid-io.
the class CoordinatorBasedSegmentHandoffNotifierTest method testHandoffCallbackNotCalled.
@Test
public void testHandoffCallbackNotCalled() throws IOException, InterruptedException {
Interval interval = new Interval("2011-04-01/2011-04-02");
SegmentDescriptor descriptor = new SegmentDescriptor(interval, "v1", 2);
DataSegment segment = new DataSegment("test_ds", interval, "v1", null, null, null, new NumberedShardSpec(2, 3), 0, 0);
CoordinatorClient coordinatorClient = EasyMock.createMock(CoordinatorClient.class);
EasyMock.expect(coordinatorClient.fetchServerView("test_ds", interval, true)).andReturn(Lists.newArrayList(new ImmutableSegmentLoadInfo(segment, Sets.newHashSet(createRealtimeServerMetadata("a1"))))).anyTimes();
EasyMock.replay(coordinatorClient);
CoordinatorBasedSegmentHandoffNotifier notifier = new CoordinatorBasedSegmentHandoffNotifier("test_ds", coordinatorClient, notifierConfig);
final AtomicBoolean callbackCalled = new AtomicBoolean(false);
notifier.registerSegmentHandoffCallback(descriptor, MoreExecutors.sameThreadExecutor(), new Runnable() {
@Override
public void run() {
callbackCalled.set(true);
}
});
notifier.checkForSegmentHandoffs();
// callback should have registered
Assert.assertEquals(1, notifier.getHandOffCallbacks().size());
Assert.assertTrue(notifier.getHandOffCallbacks().containsKey(descriptor));
Assert.assertFalse(callbackCalled.get());
EasyMock.verify(coordinatorClient);
}
Aggregations