use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel 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.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.
the class TestMetaRangeClientImpl method testGetActiveStreamRanges.
@Test
public void testGetActiveStreamRanges() throws Exception {
CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
// create response
GetActiveRangesResponse getActiveRangesResponse = GetActiveRangesResponse.newBuilder().addRanges(buildRelatedRange(Long.MIN_VALUE, 0L, 123L, 1L, Lists.newArrayList(113L))).addRanges(buildRelatedRange(0L, Long.MAX_VALUE, 124L, 2L, Lists.newArrayList(114L))).build();
StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(getActiveRangesResponse).build();
MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {
@Override
public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
serviceRegistry.addService(metaRangeService.bindService());
StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
serviceFuture.complete(rsChannel);
HashStreamRanges expectedStream = createActiveRanges(response.getGetActiveRangesResp());
CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
assertEquals(expectedStream, getFuture.get());
}
use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel 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.clients.impl.channel.StorageServerChannel 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);
}
}
Aggregations