use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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.stream.proto.storage.OneStorageContainerEndpointResponse 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.stream.proto.storage.OneStorageContainerEndpointResponse 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.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.
the class TestProtocolInternalUtils method testCreateStorageContainerEndpointResponse.
@Test
public void testCreateStorageContainerEndpointResponse() {
List<StorageContainerEndpoint> endpoints = Lists.newArrayList(StorageContainerEndpoint.newBuilder().setStorageContainerId(1L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(2L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(3L).build());
GetStorageContainerEndpointResponse response = createGetStorageContainerEndpointResponse(endpoints);
assertEquals(3, response.getResponsesCount());
int i = 0;
for (OneStorageContainerEndpointResponse oneResp : response.getResponsesList()) {
assertEquals(StatusCode.SUCCESS, oneResp.getStatusCode());
assertTrue(endpoints.get(i) == oneResp.getEndpoint());
++i;
}
}
use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.
the class TestStorageServerClientManagerImpl method testGetLocationClient.
@SuppressWarnings("unchecked")
@Test
public void testGetLocationClient() throws Exception {
LocationClient lc = serverManager.getLocationClient();
assertNotNull(lc);
assertEquals(lc, serverManager.getLocationClient());
List<OneStorageContainerEndpointResponse> responses = FutureUtils.result(lc.locateStorageContainers(Lists.newArrayList(Revisioned.of(123L, 456L))));
assertEquals(1, responses.size());
assertEquals(StatusCode.SUCCESS, responses.get(0).getStatusCode());
assertEquals(ENDPOINT, responses.get(0).getEndpoint().getRwEndpoint());
assertEquals(0, responses.get(0).getEndpoint().getRoEndpointCount());
}
Aggregations