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();
}
}
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);
}
Aggregations