Search in sources :

Example 1 with WorkerStatusResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse in project beam by apache.

the class BeamWorkerStatusGrpcServiceTest method testGetWorkerStatusReturnError.

@Test
public void testGetWorkerStatusReturnError() throws Exception {
    StreamObserver<WorkerStatusResponse> observer = stub.workerStatus(mockObserver);
    waitAndGetStatusClient(ID);
    doAnswer((invocation) -> {
        WorkerStatusRequest request = (WorkerStatusRequest) invocation.getArguments()[0];
        observer.onNext(WorkerStatusResponse.newBuilder().setId(request.getId()).setError("error").build());
        return null;
    }).when(mockObserver).onNext(any());
    CompletableFuture<String> future = service.getWorkerStatus(ID);
    String response = future.get(5, TimeUnit.SECONDS);
    assertEquals("error", response);
}
Also used : WorkerStatusResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse) WorkerStatusRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest) Test(org.junit.Test)

Example 2 with WorkerStatusResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse in project beam by apache.

the class BeamWorkerStatusGrpcServiceTest method testGetWorkerStatusSuccess.

@Test
public void testGetWorkerStatusSuccess() throws Exception {
    StreamObserver<WorkerStatusResponse> observer = stub.workerStatus(mockObserver);
    waitAndGetStatusClient(ID);
    doAnswer((invocation) -> {
        WorkerStatusRequest request = (WorkerStatusRequest) invocation.getArguments()[0];
        observer.onNext(WorkerStatusResponse.newBuilder().setId(request.getId()).setStatusInfo("status").build());
        return null;
    }).when(mockObserver).onNext(any());
    CompletableFuture<String> future = service.getWorkerStatus(ID);
    String response = future.get(5, TimeUnit.SECONDS);
    assertEquals("status", response);
}
Also used : WorkerStatusResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse) WorkerStatusRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest) Test(org.junit.Test)

Example 3 with WorkerStatusResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse in project beam by apache.

the class BeamWorkerStatusGrpcServiceTest method testGetAllWorkerStatuses.

@Test
public void testGetAllWorkerStatuses() throws Exception {
    Set<String> ids = Sets.newHashSet("id0", "id3", "id11", "id12", "id21");
    for (String id : ids) {
        StreamObserver<WorkerStatusRequest> requestObserverMock = mock(StreamObserver.class);
        BeamFnWorkerStatusStub workerStatusStub = BeamFnWorkerStatusGrpc.newStub(channel).withInterceptors(AddHarnessIdInterceptor.create(id));
        StreamObserver<WorkerStatusResponse> observer = workerStatusStub.workerStatus(requestObserverMock);
        // wait for connection before proceeding to avoid race condition.
        waitAndGetStatusClient(id);
        doAnswer((invocation) -> {
            WorkerStatusRequest request = (WorkerStatusRequest) invocation.getArguments()[0];
            observer.onNext(WorkerStatusResponse.newBuilder().setId(request.getId()).setStatusInfo("status").build());
            return null;
        }).when(requestObserverMock).onNext(any());
    }
    Map<String, String> allWorkerStatuses = service.getAllWorkerStatuses(5, TimeUnit.SECONDS);
    assertEquals(ids, allWorkerStatuses.keySet());
    for (String id : ids) {
        assertEquals("status", allWorkerStatuses.get(id));
    }
}
Also used : WorkerStatusResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse) BeamFnWorkerStatusStub(org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusStub) WorkerStatusRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest) Test(org.junit.Test)

Example 4 with WorkerStatusResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse in project beam by apache.

the class BeamFnStatusClientTest method testWorkerStatusResponse.

@Test
public void testWorkerStatusResponse() throws Exception {
    BlockingQueue<WorkerStatusResponse> values = new LinkedBlockingQueue<>();
    BlockingQueue<StreamObserver<WorkerStatusRequest>> requestObservers = new LinkedBlockingQueue<>();
    StreamObserver<WorkerStatusResponse> inboundServerObserver = TestStreams.withOnNext(values::add).build();
    Server server = InProcessServerBuilder.forName(apiServiceDescriptor.getUrl()).addService(new BeamFnWorkerStatusImplBase() {

        @Override
        public StreamObserver<WorkerStatusResponse> workerStatus(StreamObserver<WorkerStatusRequest> responseObserver) {
            Uninterruptibles.putUninterruptibly(requestObservers, responseObserver);
            return inboundServerObserver;
        }
    }).build();
    server.start();
    try {
        BundleProcessorCache processorCache = mock(BundleProcessorCache.class);
        when(processorCache.getActiveBundleProcessors()).thenReturn(Collections.emptyMap());
        ManagedChannelFactory channelFactory = ManagedChannelFactory.createInProcess();
        new BeamFnStatusClient(apiServiceDescriptor, channelFactory::forDescriptor, processorCache, PipelineOptionsFactory.create(), Caches.noop());
        StreamObserver<WorkerStatusRequest> requestObserver = requestObservers.take();
        requestObserver.onNext(WorkerStatusRequest.newBuilder().setId("id").build());
        WorkerStatusResponse response = values.take();
        assertThat(response.getStatusInfo(), containsString("No active processing bundles."));
        assertThat(response.getId(), is("id"));
    } finally {
        server.shutdownNow();
    }
}
Also used : StreamObserver(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver) WorkerStatusResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse) Server(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server) BundleProcessorCache(org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessorCache) WorkerStatusRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ManagedChannelFactory(org.apache.beam.sdk.fn.channel.ManagedChannelFactory) BeamFnWorkerStatusImplBase(org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusImplBase) Test(org.junit.Test)

Aggregations

WorkerStatusRequest (org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest)4 WorkerStatusResponse (org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse)4 Test (org.junit.Test)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 BundleProcessorCache (org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessorCache)1 BeamFnWorkerStatusImplBase (org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusImplBase)1 BeamFnWorkerStatusStub (org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusStub)1 ManagedChannelFactory (org.apache.beam.sdk.fn.channel.ManagedChannelFactory)1 Server (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server)1 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)1