[
https://issues.apache.org/jira/browse/BEAM-3676?focusedWorklogId=81458&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-81458
]
ASF GitHub Bot logged work on BEAM-3676:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Mar/18 00:42
Start Date: 17/Mar/18 00:42
Worklog Time Spent: 10m
Work Description: lukecwik commented on a change in pull request #4884:
[BEAM-3676] Add Portable State Service
URL: https://github.com/apache/beam/pull/4884#discussion_r175241253
##########
File path:
runners/java-fn-execution/src/test/java/org/apache/beam/runners/fnexecution/state/GrpcStateServiceTest.java
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.fnexecution.state;
+
+import com.google.protobuf.ByteString;
+import io.grpc.stub.StreamObserver;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.CompletableFuture;
+import org.apache.beam.model.fnexecution.v1.BeamFnApi;
+import org.apache.beam.sdk.fn.test.TestStreams;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+/** Tests for {@link
org.apache.beam.runners.fnexecution.state.GrpcStateService} */
+@RunWith(JUnit4.class)
+public class GrpcStateServiceTest {
+ private static long TIMEOUT = 30 * 1000;
+
+ private GrpcStateService stateService;
+
+ @Mock
+ private StreamObserver<BeamFnApi.StateResponse> responseObserver;
+
+ @Mock
+ private StateRequestHandler handler;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stateService = new GrpcStateService();
+ }
+
+ /**
+ * After a handler has been registered with
+ * {@link GrpcStateService#registerForProcessBundleInstructionId(String,
StateRequestHandler)},
+ * the {@link GrpcStateService} should delegate requests through
+ * {@link GrpcStateService#state(StreamObserver)} to the registered handler.
+ */
+ @Test
+ public void testStateRequestsHandledByRegisteredHandlers() throws Exception {
+ // register handler
+ String bundleInstructionId = "bundle_instruction";
+ stateService.registerForProcessBundleInstructionId(bundleInstructionId,
handler);
+
+ // open state stream
+ StreamObserver requestObserver = stateService.state(responseObserver);
+
+ // send state request
+ BeamFnApi.StateRequest request =
+
BeamFnApi.StateRequest.newBuilder().setInstructionReference(bundleInstructionId).build();
+ requestObserver.onNext(request);
+
+ // assert behavior
+ verify(handler).accept(eq(request), any());
+ }
+
+ @Test
+ public void testHandlerResponseSentToStateStream() throws Exception {
+ // define handler behavior
+ ByteString expectedResponseData =
+ ByteString.copyFrom("EXPECTED_RESPONSE_DATA", StandardCharsets.UTF_8);
+ String bundleInstructionId = "EXPECTED_BUNDLE_INSTRUCTION_ID";
+ BeamFnApi.StateResponse.Builder expectedBuilder =
+ BeamFnApi.StateResponse
+ .newBuilder()
+
.setGet(BeamFnApi.StateGetResponse.newBuilder().setData(expectedResponseData));
+ StateRequestHandler dummyHandler =
+ (request, result) ->
result.toCompletableFuture().complete(expectedBuilder);
+
+ // define observer behavior
+ CompletableFuture<Void> onNextCalled = new CompletableFuture<>();
+ StreamObserver<BeamFnApi.StateResponse> recordingResponseObserver =
+ TestStreams
+ .<BeamFnApi.StateResponse>withOnNext(next -> {
+ synchronized (onNextCalled) {
Review comment:
Follow the pattern here:
https://github.com/apache/beam/blob/cb13361a6d4452e7f5e31af5974e8b90316a654a/sdks/java/harness/src/test/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClientTest.java#L100
Use a concurrent linked queue.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 81458)
> FlinkRunner: Portable state service
> -----------------------------------
>
> Key: BEAM-3676
> URL: https://issues.apache.org/jira/browse/BEAM-3676
> Project: Beam
> Issue Type: Sub-task
> Components: runner-flink
> Reporter: Ben Sidhom
> Assignee: Axel Magnuson
> Priority: Major
> Time Spent: 1h
> Remaining Estimate: 0h
>
> The State API is an implementation of BeamFnState that exposes pipeline state
> to SDK harnesses. Because it is used for side inputs, this service will also
> need to be tied into side inputs/outputs during the translation phase.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)