Search in sources :

Example 6 with ContainerHandle

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Cleanup(lombok.Cleanup) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) IntentionalException(io.pravega.test.common.IntentionalException) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 7 with ContainerHandle

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Cleanup(lombok.Cleanup) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 8 with ContainerHandle

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();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) SegmentContainerRegistry(io.pravega.segmentstore.server.SegmentContainerRegistry) Cleanup(lombok.Cleanup) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 9 with ContainerHandle

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());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) SegmentContainerRegistry(io.pravega.segmentstore.server.SegmentContainerRegistry) Cleanup(lombok.Cleanup) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 10 with ContainerHandle

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;
}
Also used : SegmentContainerRegistry(io.pravega.segmentstore.server.SegmentContainerRegistry) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle)

Aggregations

ContainerHandle (io.pravega.segmentstore.server.ContainerHandle)15 SegmentContainerRegistry (io.pravega.segmentstore.server.SegmentContainerRegistry)10 Cleanup (lombok.Cleanup)10 Test (org.junit.Test)10 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 CompletableFuture (java.util.concurrent.CompletableFuture)6 Host (io.pravega.common.cluster.Host)5 Set (java.util.Set)5 ContainerNotFoundException (io.pravega.segmentstore.contracts.ContainerNotFoundException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Exceptions (io.pravega.common.Exceptions)1 LoggerHelpers (io.pravega.common.LoggerHelpers)1 Futures (io.pravega.common.concurrent.Futures)1 CollectionHelpers (io.pravega.common.util.CollectionHelpers)1 SegmentContainer (io.pravega.segmentstore.server.SegmentContainer)1 IntentionalException (io.pravega.test.common.IntentionalException)1 IOException (java.io.IOException)1