use of org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase in project bookkeeper by apache.
the class TestLocationClientImpl method testLocateStorageContainersSucceedAfterRetried.
@Test
public void testLocateStorageContainersSucceedAfterRetried() throws Exception {
serviceRegistry.removeService(locationServiceDefinition);
final AtomicInteger retries = new AtomicInteger(3);
StatusRuntimeException statusException = new StatusRuntimeException(Status.INTERNAL);
StorageContainerServiceImplBase locationServiceWithFailures = new StorageContainerServiceImplBase() {
@Override
public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
if (retries.decrementAndGet() == 0) {
locationService.getStorageContainerEndpoint(request, responseObserver);
return;
}
responseObserver.onError(statusException);
}
};
serviceRegistry.addService(locationServiceWithFailures.bindService());
testLocateStorageContainersSuccess();
assertEquals(0, retries.get());
}
use of org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase in project bookkeeper by apache.
the class TestLocationClientImpl method testLocateStorageContainersFailureAfterRetried.
@Test
public void testLocateStorageContainersFailureAfterRetried() throws Exception {
serviceRegistry.removeService(locationServiceDefinition);
final AtomicInteger retries = new AtomicInteger(3);
StatusRuntimeException statusException = new StatusRuntimeException(Status.INTERNAL);
StorageContainerServiceImplBase locationServiceWithFailures = new StorageContainerServiceImplBase() {
@Override
public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
if (retries.decrementAndGet() == 0) {
responseObserver.onError(new StatusRuntimeException(Status.INVALID_ARGUMENT));
return;
}
responseObserver.onError(statusException);
}
};
serviceRegistry.addService(locationServiceWithFailures.bindService());
CompletableFuture<List<OneStorageContainerEndpointResponse>> future = locationClient.locateStorageContainers(Lists.newArrayList(Revisioned.of(1L, IRevisioned.ANY_REVISION)));
try {
future.get();
fail("should fail with exception");
} catch (ExecutionException ee) {
assertNotNull(ee.getCause());
assertTrue(ee.getCause() instanceof StatusRuntimeException);
assertEquals(Status.INVALID_ARGUMENT, ((StatusRuntimeException) ee.getCause()).getStatus());
}
assertEquals(0, retries.get());
}
use of org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase 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();
}
Aggregations