use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.
the class TestStorageContainerChannel method testGetRootRangeServiceFailureWhenClosingChannelManager.
@Test
public void testGetRootRangeServiceFailureWhenClosingChannelManager() 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());
// closing the channel manager
channelManager.close();
// 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));
// verify the result
try {
rsChannelFuture.get();
fail("Should fail get root range service if channel manager is shutting down.");
} catch (ExecutionException ee) {
assertNotNull(ee.getCause());
assertTrue(ee.getCause() instanceof ObjectClosedException);
}
// 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
assertNull(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 testGetRootRangeServiceUnexpectedException.
@Test
public void testGetRootRangeServiceUnexpectedException() 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 with wrong responses
locateResponses1.complete(Lists.newArrayList(oneResp, oneResp));
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 GrpcClientTestBase method setUp.
@Before
public void setUp() throws Exception {
fakeServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
scheduler = OrderedScheduler.newSchedulerBuilder().name("scheduler-" + getClass()).numThreads(Runtime.getRuntime().availableProcessors()).build();
settings = StorageClientSettings.newBuilder().managedChannelBuilder(InProcessChannelBuilder.forName(serverName).directExecutor()).usePlaintext(true).build();
serverManager = new StorageServerClientManagerImpl(settings, resources.scheduler(), endpoint -> new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty()));
StorageContainerServiceImplBase scService = new StorageContainerServiceImplBase() {
@Override
public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
GetStorageContainerEndpointResponse.Builder respBuilder = GetStorageContainerEndpointResponse.newBuilder();
respBuilder.setStatusCode(StatusCode.SUCCESS);
for (OneStorageContainerEndpointRequest oneReq : request.getRequestsList()) {
OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(oneReq.getStorageContainer()).setRevision(oneReq.getRevision() + 1).setRwEndpoint(ENDPOINT)).build();
respBuilder.addResponses(oneResp);
}
responseObserver.onNext(respBuilder.build());
responseObserver.onCompleted();
}
};
serviceRegistry.addService(scService.bindService());
doSetup();
}
use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.
the class StorageContainerChannel method handleFetchStorageContainerInfoSuccess.
private void handleFetchStorageContainerInfoSuccess(List<OneStorageContainerEndpointResponse> storageContainerEndpoints) {
if (storageContainerEndpoints.size() != 1) {
handleFetchStorageContainerInfoFailure(new Exception("Expected only one storage container endpoint. But found " + storageContainerEndpoints.size() + " storage container endpoints."));
return;
}
OneStorageContainerEndpointResponse response = storageContainerEndpoints.get(0);
if (StatusCode.SUCCESS != response.getStatusCode()) {
handleFetchStorageContainerInfoFailure(new StorageContainerException(response.getStatusCode(), "fail to fetch location for storage container (" + scId + ")"));
return;
}
StorageContainerEndpoint endpoint = response.getEndpoint();
if (null != scInfo && scInfo.getRevision() >= endpoint.getRevision()) {
handleFetchStorageContainerInfoFailure(new StorageContainerException(StatusCode.STALE_GROUP_INFO, "Fetched a stale storage container info : current = " + scInfo.getRevision() + ", fetched = " + endpoint.getRevision() + ""));
return;
}
// we got the updated location
List<Endpoint> readEndpoints = Lists.newArrayListWithExpectedSize(1 + endpoint.getRoEndpointCount());
readEndpoints.add(endpoint.getRwEndpoint());
readEndpoints.addAll(endpoint.getRoEndpointList());
scInfo = StorageContainerInfo.of(scId, endpoint.getRevision(), endpoint.getRwEndpoint(), readEndpoints);
// get the channel from channel manager (if it doesn't exist create one)
StorageServerChannel serverChannel = channelManager.getOrCreateChannel(endpoint.getRwEndpoint());
if (null == serverChannel) {
log.info("No channel found/created for range server {}. The channel manager must be shutting down." + " Stop the process of fetching storage container ({}).", endpoint.getRwEndpoint(), scId);
synchronized (this) {
rsChannelFuture.completeExceptionally(new ObjectClosedException("StorageServerChannelManager is closed"));
}
return;
}
// update the future
synchronized (this) {
rsChannelFuture.complete(serverChannel);
}
}
use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.
the class LocationClientTest method testLocateStorageContainers.
@Test
public void testLocateStorageContainers() throws Exception {
List<OneStorageContainerEndpointResponse> responses = client.locateStorageContainers(Lists.newArrayList(Revisioned.of(ROOT_STORAGE_CONTAINER_ID, -1L))).get();
assertEquals(1, responses.size());
OneStorageContainerEndpointResponse oneResponse = responses.get(0);
assertEquals(StatusCode.SUCCESS, oneResponse.getStatusCode());
Endpoint endpoint = oneResponse.getEndpoint().getRwEndpoint();
log.info("Current cluster endpoints = {}", cluster.getRpcEndpoints());
log.info("Response : rw endpoint = {}", endpoint);
assertTrue(cluster.getRpcEndpoints().contains(endpoint));
assertEquals(1, oneResponse.getEndpoint().getRoEndpointCount());
endpoint = oneResponse.getEndpoint().getRoEndpoint(0);
log.info("Response : ro endpoint = {}", endpoint);
assertTrue(cluster.getRpcEndpoints().contains(endpoint));
}
Aggregations