use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class TestStorageContainerChannel method testGetRootRangeServiceFailureOnStaleGroupInfo.
@Test
public void testGetRootRangeServiceFailureOnStaleGroupInfo() throws Exception {
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses3 = FutureUtils.createFuture();
when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses3);
// the future is not set before #getRootRangeService
assertNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
// call #getRootRangeService
CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
// the future is set and the locationClient#locateStorageContainers is called
assertNotNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
// if the request is outstanding, a second call will not call locationClient#locateStorageContainers
CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
assertTrue(rsChannelFuture == rsChannelFuture1);
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
//
// Complete the first response
//
// prepare the result and complete the request
OneStorageContainerEndpointResponse oneResp1 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
locateResponses1.complete(Lists.newArrayList(oneResp1));
// get the service
StorageServerChannel rsChannel = rsChannelFuture.get();
assertTrue(rsChannel == mockChannel);
// verify storage container info
StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
assertEquals(1000L, scInfo.getRevision());
assertEquals(endpoint, scInfo.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
// verify channel
assertEquals(mockChannel, channelManager.getChannel(endpoint));
//
// Reset and complete the second response
//
scClient.resetStorageServerChannelFuture();
rsChannelFuture = scClient.getStorageContainerChannelFuture();
OneStorageContainerEndpointResponse oneResp2 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(999L).setRwEndpoint(endpoint2).addRoEndpoint(endpoint2).build()).build();
locateResponses2.complete(Lists.newArrayList(oneResp2));
ensureCallbackExecuted();
// verify storage container info : group info will not be updated
scInfo = scClient.getStorageContainerInfo();
assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
assertEquals(1000L, scInfo.getRevision());
assertEquals(endpoint, scInfo.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
// the future will not be completed
assertFalse(rsChannelFuture.isDone());
//
// complete the third response
//
scClient.resetStorageServerChannelFuture();
rsChannelFuture = scClient.getStorageContainerChannelFuture();
OneStorageContainerEndpointResponse oneResp3 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1001L).setRwEndpoint(endpoint3).addRoEndpoint(endpoint3).build()).build();
locateResponses3.complete(Lists.newArrayList(oneResp3));
ensureCallbackExecuted();
StorageServerChannel rsChannel3 = rsChannelFuture.get();
assertTrue(rsChannel3 == mockChannel3);
// verify storage container info : group info will not be updated
scInfo = scClient.getStorageContainerInfo();
assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
assertEquals(1001L, scInfo.getRevision());
assertEquals(endpoint3, scInfo.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint3, endpoint3), scInfo.getReadEndpoints());
verify(locationClient, times(3)).locateStorageContainers(anyList());
}
use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class TestStorageContainerChannel method testGetRootRangeServiceSuccess.
@Test
public void testGetRootRangeServiceSuccess() throws Exception {
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses = FutureUtils.createFuture();
when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses);
// the future is not set before #getRootRangeService
assertNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
// call #getRootRangeService
CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
// the future is set and the locationClient#locateStorageContainers is called
assertNotNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
// if the request is outstanding, a second call will not call locationClient#locateStorageContainers
CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
assertTrue(rsChannelFuture == rsChannelFuture1);
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
// prepare the result and complete the request
OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
locateResponses.complete(Lists.newArrayList(oneResp));
// get the service
StorageServerChannel rsChannel = rsChannelFuture.get();
assertTrue(rsChannel == mockChannel);
// verify storage container info
StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
assertEquals(1000L, scInfo.getRevision());
assertEquals(endpoint, scInfo.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
// verify channel
assertEquals(mockChannel, channelManager.getChannel(endpoint));
verify(locationClient, times(1)).locateStorageContainers(anyList());
}
use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class TestStorageContainerChannel method testGetRootRangeServiceExceptionally.
@Test
public void testGetRootRangeServiceExceptionally() throws Exception {
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses2);
// the future is not set before #getRootRangeService
assertNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
// call #getRootRangeService
CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
// the future is set and the locationClient#locateStorageContainers is called
assertNotNull(scClient.getStorageServerChannelFuture());
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
// if the request is outstanding, a second call will not call locationClient#locateStorageContainers
CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
assertTrue(rsChannelFuture == rsChannelFuture1);
assertNull(scClient.getStorageContainerInfo());
verify(locationClient, times(1)).locateStorageContainers(anyList());
// prepare the result and complete the request
OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
// complete exceptionally
locateResponses1.completeExceptionally(new ClientException("test-exception"));
ensureCallbackExecuted();
// verify channel
assertNull(channelManager.getChannel(endpoint));
// verify storage container info
assertNull(scClient.getStorageContainerInfo());
// complete with right responses
locateResponses2.complete(Lists.newArrayList(oneResp));
// get the service
StorageServerChannel rsChannel = rsChannelFuture.get();
assertTrue(rsChannel == mockChannel);
// verify storage container info
StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
assertEquals(1000L, scInfo.getRevision());
assertEquals(endpoint, scInfo.getWriteEndpoint());
assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
// verify channel
assertEquals(mockChannel, channelManager.getChannel(endpoint));
verify(locationClient, times(2)).locateStorageContainers(anyList());
}
use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class RootRangeClientImplTestBase method testRequestFailure.
@Test
public void testRequestFailure() throws Exception {
CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
RootRangeServiceImplBase rootRangeService = createRootRangeServiceForRequestFailure();
serviceRegistry.addService(rootRangeService.bindService());
StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
serviceFuture.complete(rsChannel);
verifyRequestFailure(rootRangeClient);
}
use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class RootRangeClientImplTestBase method testRequestSuccess.
@Test
public void testRequestSuccess() throws Exception {
CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
RootRangeServiceImplBase rootRangeService = createRootRangeServiceForSuccess();
serviceRegistry.addService(rootRangeService.bindService());
StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
serviceFuture.complete(rsChannel);
verifySuccess(rootRangeClient);
}
Aggregations