use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class TestStorageContainerInfo method testBasic.
@Test
public void testBasic() {
long groupId = 1234L;
long revision = 4468L;
Endpoint endpoint = Endpoint.newBuilder().setHostname("123.46.78.96").setPort(3181).build();
StorageContainerInfo sc = StorageContainerInfo.of(groupId, revision, endpoint, Lists.newArrayList(endpoint));
assertEquals(groupId, sc.getGroupId());
assertEquals(revision, sc.getRevision());
assertEquals(endpoint, sc.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint), sc.getReadEndpoints());
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class NetUtils method parseEndpoint.
/**
* Parse an endpoint from an endpoint string.
*
* @param endpointStr an endpoint string.
* @return endpoint.
*/
public static Endpoint parseEndpoint(String endpointStr) {
String[] endpointParts = StringUtils.split(endpointStr, ':');
checkArgument(2 == endpointParts.length, "Invalid endpoint string %s - It should be 'host:port'.", endpointStr);
String host = endpointParts[0];
int port;
try {
port = Integer.parseInt(endpointParts[1]);
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("Invalid port found in the endpoint string " + endpointStr, nfe);
}
return createEndpoint(host, port);
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.
the class TestRangeStoreImpl method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
storageResources = StorageResources.create();
Endpoint endpoint = createEndpoint("127.0.0.1", 0);
// create the client manager
MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
MVCCAsyncStore<byte[], byte[]> store = mock(MVCCAsyncStore.class);
when(storeFactory.openStore(anyLong(), anyLong(), anyLong())).thenReturn(FutureUtils.value(store));
when(storeFactory.closeStores(anyLong())).thenReturn(FutureUtils.Void());
rangeStore = (RangeStoreImpl) RangeStoreBuilder.newBuilder().withStorageConfiguration(storageConf).withStorageResources(storageResources).withStorageContainerManagerFactory((numScs, storeConf, rgRegistry) -> new LocalStorageContainerManager(endpoint, storeConf, rgRegistry, 2)).withRangeStoreFactory(storeFactory).withDefaultBackendUri(URI.create("distributedlog://127.0.0.1/stream/storage")).build();
rangeStore.start();
}
use of org.apache.bookkeeper.stream.proto.common.Endpoint 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.proto.common.Endpoint in project bookkeeper by apache.
the class TestNetUtils method testToInetSocketAddress.
@Test
public void testToInetSocketAddress() {
String hostname = "127.0.0.1";
int port = 8080;
Endpoint endpoint = createEndpoint(hostname, port);
InetSocketAddress socketAddress = new InetSocketAddress(hostname, port);
assertEquals(socketAddress, NetUtils.of(endpoint));
}
Aggregations