Search in sources :

Example 1 with GetOperationRequest

use of com.google.longrunning.GetOperationRequest in project gax-java by googleapis.

the class GrpcLongRunningClientTest method get.

@Test
public void get() {
    OperationsStub operationsStub = mock(OperationsStub.class);
    when(operationsStub.getOperationCallable()).thenReturn(new UnaryCallable<GetOperationRequest, Operation>() {

        @Override
        public ApiFuture<Operation> futureCall(GetOperationRequest request, ApiCallContext context) {
            if (!request.getName().equals("poseidon")) {
                return ApiFutures.immediateFailedFuture(new IllegalStateException("Unexpected request: " + request));
            } else {
                return ApiFutures.immediateFuture(Operation.newBuilder().setName("greece").build());
            }
        }
    });
    LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub);
    Truth.assertThat(longRunningClient.getOperationCallable().call("poseidon").getName()).isEqualTo("greece");
}
Also used : ApiFuture(com.google.api.core.ApiFuture) OperationsStub(com.google.longrunning.stub.OperationsStub) GetOperationRequest(com.google.longrunning.GetOperationRequest) LongRunningClient(com.google.api.gax.rpc.LongRunningClient) Operation(com.google.longrunning.Operation) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) Test(org.junit.Test)

Example 2 with GetOperationRequest

use of com.google.longrunning.GetOperationRequest in project java-spanner by googleapis.

the class GapicSpannerRpc method getOperation.

@Override
public Operation getOperation(String name) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    final GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build();
    final GrpcCallContext context = newCallContext(null, name, request, OperationsGrpc.getGetOperationMethod());
    return runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.getOperationsStub().getOperationCallable().futureCall(request, context)));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) GetOperationRequest(com.google.longrunning.GetOperationRequest)

Example 3 with GetOperationRequest

use of com.google.longrunning.GetOperationRequest in project java-spanner by googleapis.

the class AbstractMockServerTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockInstanceAdmin = new MockInstanceAdminImpl();
    mockDatabaseAdmin = new MockDatabaseAdminImpl();
    mockOperations = new OperationsImplBase() {

        @Override
        public void getOperation(GetOperationRequest request, StreamObserver<Operation> responseObserver) {
            responseObserver.onNext(Operation.newBuilder().setDone(false).setName(request.getName()).setMetadata(Any.pack(Empty.getDefaultInstance())).build());
            responseObserver.onCompleted();
        }
    };
    address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockInstanceAdmin).addService(mockDatabaseAdmin).addService(mockOperations).build().start();
    mockSpanner.putStatementResult(StatementResult.query(SELECT_COUNT_STATEMENT, SELECT_COUNT_RESULTSET_BEFORE_INSERT));
    mockSpanner.putStatementResult(StatementResult.update(INSERT_STATEMENT, UPDATE_COUNT));
    mockSpanner.putStatementResult(StatementResult.query(SELECT_RANDOM_STATEMENT, RANDOM_RESULT_SET));
    futureParentHandlers = Logger.getLogger(AbstractFuture.class.getName()).getUseParentHandlers();
    exceptionRunnableParentHandlers = Logger.getLogger(LogExceptionRunnable.class.getName()).getUseParentHandlers();
    nettyServerParentHandlers = Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").getUseParentHandlers();
    clientStreamParentHandlers = Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").getUseParentHandlers();
    Logger.getLogger(AbstractFuture.class.getName()).setUseParentHandlers(false);
    Logger.getLogger(LogExceptionRunnable.class.getName()).setUseParentHandlers(false);
    Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").setUseParentHandlers(false);
    Logger.getLogger("io.grpc.internal.AbstractClientStream").setUseParentHandlers(false);
}
Also used : LogExceptionRunnable(io.grpc.internal.LogExceptionRunnable) GetOperationRequest(com.google.longrunning.GetOperationRequest) InetSocketAddress(java.net.InetSocketAddress) MockDatabaseAdminImpl(com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl) MockInstanceAdminImpl(com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl) Operation(com.google.longrunning.Operation) OperationsImplBase(com.google.longrunning.OperationsGrpc.OperationsImplBase) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) AbstractFuture(com.google.common.util.concurrent.AbstractFuture) BeforeClass(org.junit.BeforeClass)

Example 4 with GetOperationRequest

use of com.google.longrunning.GetOperationRequest in project bazel-buildfarm by bazelbuild.

the class BuildFarmServerTest method getOperation.

private Operation getOperation(String name) {
    GetOperationRequest getRequest = GetOperationRequest.newBuilder().setName(name).build();
    OperationsGrpc.OperationsBlockingStub operationsStub = OperationsGrpc.newBlockingStub(inProcessChannel);
    return operationsStub.getOperation(getRequest);
}
Also used : GetOperationRequest(com.google.longrunning.GetOperationRequest) OperationsGrpc(com.google.longrunning.OperationsGrpc)

Aggregations

GetOperationRequest (com.google.longrunning.GetOperationRequest)4 Operation (com.google.longrunning.Operation)2 ApiFuture (com.google.api.core.ApiFuture)1 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)1 LongRunningClient (com.google.api.gax.rpc.LongRunningClient)1 MockSpannerServiceImpl (com.google.cloud.spanner.MockSpannerServiceImpl)1 MockDatabaseAdminImpl (com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl)1 MockInstanceAdminImpl (com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl)1 AbstractFuture (com.google.common.util.concurrent.AbstractFuture)1 OperationsGrpc (com.google.longrunning.OperationsGrpc)1 OperationsImplBase (com.google.longrunning.OperationsGrpc.OperationsImplBase)1 OperationsStub (com.google.longrunning.stub.OperationsStub)1 LogExceptionRunnable (io.grpc.internal.LogExceptionRunnable)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1