use of io.pravega.segmentstore.server.ContainerHandle in project pravega by pravega.
the class StreamSegmentContainerRegistryTests method testContainerFailureWhileRunning.
/**
* Tests the ability to detect a container failure and unregister the container in case the container fails while running.
*/
@Test
public void testContainerFailureWhileRunning() throws Exception {
final int containerId = 123;
TestContainerFactory factory = new TestContainerFactory();
@Cleanup StreamSegmentContainerRegistry registry = new StreamSegmentContainerRegistry(factory, executorService());
ContainerHandle handle = registry.startContainer(containerId, TIMEOUT).join();
// Register a Listener for the Container.Stop event. Make this a Future since these callbacks are invoked async
// so they may finish executing after stop() finished.
CompletableFuture<Integer> stopListenerCallback = new CompletableFuture<>();
handle.setContainerStoppedListener(stopListenerCallback::complete);
TestContainer container = (TestContainer) registry.getContainer(handle.getContainerId());
// Fail the container and wait for it to properly terminate.
container.fail(new IntentionalException());
ServiceListeners.awaitShutdown(container, false);
Assert.assertEquals("Unexpected value passed to Handle.stopListenerCallback or callback was not invoked.", containerId, (int) stopListenerCallback.join());
AssertExtensions.assertThrows("Container is still registered after failure.", () -> registry.getContainer(containerId), ex -> ex instanceof ContainerNotFoundException);
}
use of io.pravega.segmentstore.server.ContainerHandle in project pravega by pravega.
the class StreamSegmentContainerRegistryTests method testStopContainer.
/**
* Tests the ability to stop the container via the stopContainer() method.
*/
@Test
public void testStopContainer() throws Exception {
final int containerId = 123;
TestContainerFactory factory = new TestContainerFactory();
@Cleanup StreamSegmentContainerRegistry registry = new StreamSegmentContainerRegistry(factory, executorService());
ContainerHandle handle = registry.startContainer(containerId, TIMEOUT).join();
// Register a Listener for the Container.Stop event. Make this a Future since these callbacks are invoked async
// so they may finish executing after stop() finished.
CompletableFuture<Integer> stopListenerCallback = new CompletableFuture<>();
handle.setContainerStoppedListener(stopListenerCallback::complete);
TestContainer container = (TestContainer) registry.getContainer(handle.getContainerId());
Assert.assertFalse("Container is closed before being shut down.", container.isClosed());
registry.stopContainer(handle, TIMEOUT).join();
Assert.assertEquals("Unexpected value passed to Handle.stopListenerCallback or callback was not invoked.", containerId, (int) stopListenerCallback.join());
Assert.assertTrue("Container is not closed after being shut down.", container.isClosed());
AssertExtensions.assertThrows("Container is still registered after being shut down.", () -> registry.getContainer(handle.getContainerId()), ex -> ex instanceof ContainerNotFoundException);
}
use of io.pravega.segmentstore.server.ContainerHandle in project pravega by pravega.
the class ZKSegmentContainerManagerTest method testClose.
@Test
public void testClose() throws Exception {
@Cleanup CuratorFramework zkClient = startClient();
SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class);
ContainerHandle containerHandle1 = mock(ContainerHandle.class);
when(containerHandle1.getContainerId()).thenReturn(1);
when(containerRegistry.startContainer(eq(1), any())).thenReturn(CompletableFuture.completedFuture(containerHandle1));
when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
ZKSegmentContainerManager segManager = createContainerManager(containerRegistry, zkClient);
segManager.initialize();
segManager.close();
}
use of io.pravega.segmentstore.server.ContainerHandle in project pravega by pravega.
the class ZKSegmentContainerManagerTest method testContainerStart.
@Test
public void testContainerStart() throws Exception {
@Cleanup CuratorFramework zkClient = startClient();
initializeHostContainerMapping(zkClient);
SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class);
ContainerHandle containerHandle1 = mock(ContainerHandle.class);
when(containerHandle1.getContainerId()).thenReturn(1);
when(containerRegistry.startContainer(eq(1), any())).thenReturn(CompletableFuture.completedFuture(containerHandle1));
@Cleanup ZKSegmentContainerManager segManager = createContainerManager(containerRegistry, zkClient);
segManager.initialize();
verify(containerRegistry, timeout(30000).atLeastOnce()).startContainer(eq(1), any());
}
use of io.pravega.segmentstore.server.ContainerHandle in project pravega by pravega.
the class ZKSegmentContainerManagerTest method createMockContainerRegistry.
private SegmentContainerRegistry createMockContainerRegistry() {
SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class);
ContainerHandle containerHandle1 = mock(ContainerHandle.class);
when(containerHandle1.getContainerId()).thenReturn(1);
when(containerRegistry.startContainer(anyInt(), any())).thenReturn(CompletableFuture.completedFuture(containerHandle1));
when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
return containerRegistry;
}
Aggregations