use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project jetcd by coreos.
the class LeaseUnitTest method testKeepAliveAfterFirstKeepAliveTimeout.
@Test
public void testKeepAliveAfterFirstKeepAliveTimeout() throws InterruptedException {
final StreamObserver<io.etcd.jetcd.lease.LeaseKeepAliveResponse> observer = Observers.observer(response -> {
});
try (CloseableClient listener = this.leaseCli.keepAlive(LEASE_ID_1, observer)) {
// expect at least some KeepAlive requests are sent within
// firstKeepAliveTimeout(5000 ms) + some quiet time (1000 ms).
verify(this.requestStreamObserverMock, after(6000).atLeastOnce()).onNext(argThat(hasLeaseID(LEASE_ID_1)));
// reset mock to a empty state.
Mockito.<StreamObserver>reset(this.requestStreamObserverMock);
// verify no keepAlive requests are sent within one second after firstKeepAliveTimeout.
verify(this.requestStreamObserverMock, after(1000).times(0)).onNext(argThat(hasLeaseID(LEASE_ID_1)));
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project alluxio by Alluxio.
the class BlockWorkerRegisterStreamIntegrationTest method getResponseObserver.
// The field is private so we have to use reflection to bypass the permission control
private StreamObserver<RegisterWorkerPResponse> getResponseObserver(RegisterStreamer stream) throws Exception {
Field privateField = RegisterStreamer.class.getDeclaredField("mMasterResponseObserver");
privateField.setAccessible(true);
return (StreamObserver<RegisterWorkerPResponse>) privateField.get(stream);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project pravega by pravega.
the class ControllerServiceImpl method checkScopeExists.
@Override
public void checkScopeExists(ScopeInfo request, StreamObserver<Controller.ExistsResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), CHECK_SCOPE_EXISTS, request.getScope());
String scope = request.getScope();
log.info(requestTag.getRequestId(), "checkScopeExists called for scope {}.", request);
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScope(scope), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<Controller.ExistsResponse>> scopeFn = delegationToken -> controllerService.getScope(scope, requestTag.getRequestId()).handle((response, e) -> {
boolean exists;
if (e != null) {
if (Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException) {
exists = false;
} else {
throw new CompletionException(e);
}
} else {
exists = true;
}
return Controller.ExistsResponse.newBuilder().setExists(exists).build();
});
authenticateExecuteAndProcessResults(stringSupplier, scopeFn, responseObserver, requestTag);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project pravega by pravega.
the class ControllerServiceImpl method listStreamsInScopeForTag.
@Override
public void listStreamsInScopeForTag(Controller.StreamsInScopeWithTagRequest request, StreamObserver<Controller.StreamsInScopeResponse> responseObserver) {
String scopeName = request.getScope().getScope();
String tag = request.getTag();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_STREAMS_IN_SCOPE_FOR_TAG, scopeName);
log.info(requestTag.getRequestId(), "{} called for scope {} and tags {}", LIST_STREAMS_IN_SCOPE_FOR_TAG, scopeName, tag);
final AuthContext ctx = this.grpcAuthHelper.isAuthEnabled() ? AuthContext.current() : null;
Function<String, CompletableFuture<Controller.StreamsInScopeResponse>> streamsFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listStreamsForTag(scopeName, tag, x, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofStreamInScope(scopeName, x), AuthHandler.Permissions.READ, ctx), x -> StreamInfo.newBuilder().setScope(scopeName).setStream(x).build(), requestTag.getRequestId()).handle((response, ex) -> {
if (ex != null) {
if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
return Controller.StreamsInScopeResponse.newBuilder().setStatus(Controller.StreamsInScopeResponse.Status.SCOPE_NOT_FOUND).build();
} else {
throw new CompletionException(ex);
}
} else {
return Controller.StreamsInScopeResponse.newBuilder().addAllStreams(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).setStatus(Controller.StreamsInScopeResponse.Status.SUCCESS).build();
}
});
authenticateExecuteAndProcessResults(() -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScope(scopeName), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScope(scopeName), result);
return result;
}, streamsFn, responseObserver, requestTag);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project pravega by pravega.
the class ControllerServiceImpl method listScopes.
@Override
public void listScopes(Controller.ScopesRequest request, StreamObserver<Controller.ScopesResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_SCOPES);
log.info(requestTag.getRequestId(), "listScope called.");
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScopes(), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<Controller.ScopesResponse>> scopesFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listScopes(x, y, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofScope(x), AuthHandler.Permissions.READ, ctx), x -> x, requestTag.getRequestId()).thenApply(response -> Controller.ScopesResponse.newBuilder().addAllScopes(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).build());
authenticateExecuteAndProcessResults(stringSupplier, scopesFn, responseObserver, requestTag);
}
Aggregations