Search in sources :

Example 1 with SegmentContainerRegistry

use of io.pravega.segmentstore.server.SegmentContainerRegistry in project pravega by pravega.

the class ZKSegmentContainerMonitorTest method testShutdownNotYetStartedContainer.

@Test
public void testShutdownNotYetStartedContainer() throws Exception {
    @Cleanup CuratorFramework zkClient = startClient();
    initializeHostContainerMapping(zkClient);
    SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
    @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
    segMonitor.initialize(Duration.ofSeconds(1));
    // Simulate a container that takes a long time to start. Should be greater than a few monitor loops.
    ContainerHandle containerHandle = mock(ContainerHandle.class);
    when(containerHandle.getContainerId()).thenReturn(2);
    CompletableFuture<ContainerHandle> startupFuture = Futures.delayedFuture(() -> CompletableFuture.completedFuture(containerHandle), 3000, executorService());
    when(containerRegistry.startContainer(eq(2), any())).thenReturn(startupFuture);
    // Use ZK to send that information to the Container Manager.
    HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
    currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));
    // Verify it's not yet started.
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
    assertEquals(0, segMonitor.getRegisteredContainers().size());
    // Now simulate shutting it down.
    when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
    currentData.clear();
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));
    verify(containerRegistry, timeout(10000).atLeastOnce()).stopContainer(any(), any());
    Thread.sleep(2000);
    assertEquals(0, segMonitor.getRegisteredContainers().size());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Set(java.util.Set) Host(io.pravega.common.cluster.Host) SegmentContainerRegistry(io.pravega.segmentstore.server.SegmentContainerRegistry) Cleanup(lombok.Cleanup) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 2 with SegmentContainerRegistry

use of io.pravega.segmentstore.server.SegmentContainerRegistry in project pravega by pravega.

the class ZKSegmentContainerMonitorTest method testRetryOnExceptions.

@Test
public void testRetryOnExceptions() throws Exception {
    @Cleanup CuratorFramework zkClient = startClient();
    initializeHostContainerMapping(zkClient);
    SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
    @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
    segMonitor.initialize(Duration.ofSeconds(1));
    // Simulate a container that throws exception on start.
    when(containerRegistry.startContainer(eq(2), any())).thenThrow(new RuntimeException());
    // Use ZK to send that information to the Container Manager.
    HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
    currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));
    // Verify that it does not start.
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
    assertEquals(0, segMonitor.getRegisteredContainers().size());
    // Now simulate success for the same container.
    ContainerHandle containerHandle = mock(ContainerHandle.class);
    when(containerHandle.getContainerId()).thenReturn(2);
    when(containerRegistry.startContainer(eq(2), any())).thenReturn(CompletableFuture.completedFuture(containerHandle));
    // Verify that it retries and starts the same container again.
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
    // Using wait here to ensure the private data structure is updated.
    // TODO: Removing dependency on sleep here and other places in this class
    // - https://github.com/pravega/pravega/issues/1079
    Thread.sleep(2000);
    assertEquals(1, segMonitor.getRegisteredContainers().size());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Set(java.util.Set) Host(io.pravega.common.cluster.Host) SegmentContainerRegistry(io.pravega.segmentstore.server.SegmentContainerRegistry) Cleanup(lombok.Cleanup) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 3 with SegmentContainerRegistry

use of io.pravega.segmentstore.server.SegmentContainerRegistry 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 4 with SegmentContainerRegistry

use of io.pravega.segmentstore.server.SegmentContainerRegistry 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 5 with SegmentContainerRegistry

use of io.pravega.segmentstore.server.SegmentContainerRegistry 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)9 SegmentContainerRegistry (io.pravega.segmentstore.server.SegmentContainerRegistry)9 Cleanup (lombok.Cleanup)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)7 Test (org.junit.Test)7 Host (io.pravega.common.cluster.Host)4 Set (java.util.Set)4 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1