Search in sources :

Example 1 with BeamFnWorkerStatusStub

use of org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusStub 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)

Aggregations

WorkerStatusRequest (org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusRequest)1 WorkerStatusResponse (org.apache.beam.model.fnexecution.v1.BeamFnApi.WorkerStatusResponse)1 BeamFnWorkerStatusStub (org.apache.beam.model.fnexecution.v1.BeamFnWorkerStatusGrpc.BeamFnWorkerStatusStub)1 Test (org.junit.Test)1