use of org.apache.curator.framework.listen.Listenable in project pravega by pravega.
the class ControllerEventProcessorsTest method testIsReady.
@Test(timeout = 30000L)
public void testIsReady() throws Exception {
LocalController controller = mock(LocalController.class);
StreamMetadataStore streamStore = mock(StreamMetadataStore.class);
BucketStore bucketStore = mock(BucketStore.class);
ConnectionPool connectionPool = mock(ConnectionPool.class);
StreamMetadataTasks streamMetadataTasks = mock(StreamMetadataTasks.class);
StreamTransactionMetadataTasks streamTransactionMetadataTasks = mock(StreamTransactionMetadataTasks.class);
KVTableMetadataStore kvtStore = mock(KVTableMetadataStore.class);
TableMetadataTasks kvtTasks = mock(TableMetadataTasks.class);
ControllerEventProcessorConfig config = ControllerEventProcessorConfigImpl.withDefault();
EventProcessorSystem system = mock(EventProcessorSystem.class);
CuratorZookeeperClient curatorZKClientMock = mock(CuratorZookeeperClient.class);
CuratorFramework client = mock(CuratorFramework.class);
Listenable listen = mock(Listenable.class);
doNothing().when(listen).addListener(any(ConnectionStateListener.class));
doReturn(listen).when(client).getConnectionStateListenable();
doReturn(curatorZKClientMock).when(client).getZookeeperClient();
doReturn(true).when(curatorZKClientMock).isConnected();
ZKCheckpointStore checkpointStore = (ZKCheckpointStore) CheckpointStoreFactory.createZKStore(client);
doAnswer(x -> null).when(streamMetadataTasks).initializeStreamWriters(any(), any());
doAnswer(x -> null).when(streamTransactionMetadataTasks).initializeStreamWriters(any(EventStreamClientFactory.class), any(ControllerEventProcessorConfig.class));
CompletableFuture<Boolean> createScopeResponseFuture = new CompletableFuture<>();
CompletableFuture<Void> createScopeSignalFuture = new CompletableFuture<>();
doAnswer(x -> {
createScopeSignalFuture.complete(null);
return createScopeResponseFuture;
}).when(controller).createScope(anyString());
LinkedBlockingQueue<CompletableFuture<Boolean>> createStreamResponses = new LinkedBlockingQueue<>();
LinkedBlockingQueue<CompletableFuture<Void>> createStreamSignals = new LinkedBlockingQueue<>();
List<CompletableFuture<Boolean>> createStreamResponsesList = new LinkedList<>();
List<CompletableFuture<Void>> createStreamSignalsList = new LinkedList<>();
for (int i = 0; i < 4; i++) {
CompletableFuture<Boolean> responseFuture = new CompletableFuture<>();
CompletableFuture<Void> signalFuture = new CompletableFuture<>();
createStreamResponsesList.add(responseFuture);
createStreamResponses.add(responseFuture);
createStreamSignalsList.add(signalFuture);
createStreamSignals.add(signalFuture);
}
// return a future from latches queue
doAnswer(x -> {
createStreamSignals.take().complete(null);
return createStreamResponses.take();
}).when(controller).createInternalStream(anyString(), anyString(), any());
@Cleanup ControllerEventProcessors processors = spy(new ControllerEventProcessors("host1", config, controller, checkpointStore, streamStore, bucketStore, connectionPool, streamMetadataTasks, streamTransactionMetadataTasks, kvtStore, kvtTasks, system, executorService()));
// Check isReady() method before invoking bootstrap
Assert.assertFalse(processors.getBootstrapCompleted().get());
Assert.assertTrue(processors.isMetadataServiceConnected());
Assert.assertFalse(processors.isRunning());
Assert.assertFalse(processors.isReady());
// Call bootstrap on ControllerEventProcessors
processors.bootstrap(streamTransactionMetadataTasks, streamMetadataTasks, kvtTasks);
// Wait on create scope being called.
createScopeSignalFuture.join();
createScopeResponseFuture.complete(true);
createStreamSignalsList.get(0).join();
createStreamSignalsList.get(1).join();
createStreamSignalsList.get(2).join();
createStreamSignalsList.get(3).join();
createStreamResponsesList.get(0).complete(true);
createStreamResponsesList.get(1).complete(true);
createStreamResponsesList.get(2).complete(true);
createStreamResponsesList.get(3).complete(true);
AssertExtensions.assertEventuallyEquals(true, () -> processors.getBootstrapCompleted().get(), 10000);
Assert.assertTrue(processors.isMetadataServiceConnected());
Assert.assertFalse(processors.isRunning());
Assert.assertFalse(processors.isReady());
EventProcessorGroup mockEventProcessorGroup = mock(EventProcessorGroup.class);
doNothing().when(mockEventProcessorGroup).awaitRunning();
doReturn(mockEventProcessorGroup).when(system).createEventProcessorGroup(any(EventProcessorConfig.class), any(CheckpointStore.class), any(ScheduledExecutorService.class));
processors.startAsync();
processors.awaitRunning();
Assert.assertTrue(processors.isMetadataServiceConnected());
Assert.assertTrue(processors.isBootstrapCompleted());
Assert.assertTrue(processors.isRunning());
Assert.assertTrue(processors.isReady());
}
use of org.apache.curator.framework.listen.Listenable in project pravega by pravega.
the class SegmentContainerMonitorHealthContributorTest method setup.
@Before
public void setup() {
HostControllerStore hostStore = mock(HostControllerStore.class);
CuratorFramework client = mock(CuratorFramework.class);
ContainerBalancer balancer = mock(ContainerBalancer.class);
CuratorZookeeperClient curatorZKClientMock = mock(CuratorZookeeperClient.class);
Listenable listen = mock(Listenable.class);
doNothing().when(listen).addListener(any(ConnectionStateListener.class));
doReturn(listen).when(client).getConnectionStateListenable();
doReturn(curatorZKClientMock).when(client).getZookeeperClient();
doReturn(true).when(curatorZKClientMock).isConnected();
monitor = spy(new SegmentContainerMonitor(hostStore, client, balancer, 1));
contributor = new SegmentContainerMonitorHealthContributor("segmentcontainermonitor", monitor);
builder = Health.builder().name("monitor");
}
Aggregations