Search in sources :

Example 1 with StorageContainerRegistryImpl

use of org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl in project bookkeeper by apache.

the class TestHelixStorageContainerManager method testStorageContainerManager.

@Ignore
@Test
public void testStorageContainerManager() throws Exception {
    String clusterName = runtime.getMethodName();
    int numStorageContainers = 12;
    int numHosts = 3;
    controller.createCluster(clusterName, numStorageContainers, 3);
    StorageConfiguration conf = new StorageConfiguration(new CompositeConfiguration());
    Endpoint[] endpoints = new Endpoint[numHosts];
    StorageContainerRegistryImpl[] registries = new StorageContainerRegistryImpl[numHosts];
    HelixStorageContainerManager[] managers = new HelixStorageContainerManager[numHosts];
    int basePort = 80;
    for (int i = 0; i < numHosts; i++) {
        endpoints[i] = createEndpoint("127.0.0.1", basePort + i);
        registries[i] = createRegistry();
        managers[i] = createManager(clusterName, conf, registries[i], endpoints[i]);
    }
    managers[0].start();
    while (registries[0].getNumStorageContainers() < numStorageContainers) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers, registries[0].getNumStorageContainers());
    assertEquals(0, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the second node
    managers[1].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() < numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers / 2, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 2, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the third node
    managers[2].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[2].getNumStorageContainers() < numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    int totalStorageContainers = registries[0].getNumStorageContainers() + registries[1].getNumStorageContainers() + registries[2].getNumStorageContainers();
    assertEquals("Expected " + numStorageContainers + "But " + totalStorageContainers + " found", numStorageContainers, totalStorageContainers);
    assertEquals(numStorageContainers / 3, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[1].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[2].getNumStorageContainers());
    for (int i = 0; i < 10; i++) {
        int nid = ThreadLocalRandom.current().nextInt(numHosts);
        long scId = ThreadLocalRandom.current().nextLong(numStorageContainers);
        Endpoint endpoint = managers[nid].getStorageContainer(scId);
        if (null != endpoint) {
            assertTrue(endpoint.equals(endpoints[0]) || endpoint.equals(endpoints[1]) || endpoint.equals(endpoints[2]));
        }
    }
    for (HelixStorageContainerManager manager : managers) {
        manager.close();
    }
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with StorageContainerRegistryImpl

use of org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl in project bookkeeper by apache.

the class TestHelixStorageContainerManager method createRegistry.

private StorageContainerRegistryImpl createRegistry() {
    return new StorageContainerRegistryImpl((scId) -> {
        StorageContainer sc = mock(StorageContainer.class);
        when(sc.getId()).thenReturn(scId);
        when(sc.start()).thenReturn(FutureUtils.value(null));
        when(sc.stop()).thenReturn(FutureUtils.value(null));
        return sc;
    }, scheduler);
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)

Aggregations

StorageContainerRegistryImpl (org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1 StorageConfiguration (org.apache.bookkeeper.stream.storage.conf.StorageConfiguration)1 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1