arunpandianp commented on code in PR #40302:
URL: https://github.com/apache/beam/pull/40302#discussion_r4142150629
##########
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/state/BeamFnStateGrpcClientCacheTest.java:
##########
@@ -166,6 +169,13 @@ public void testRequestResponses() throws Exception {
} catch (ExecutionException e) {
assertThat(e.toString(), containsString(TEST_ERROR));
}
+ try {
+ cancelledResponse.get();
+ fail("Expected cancelled response");
+ } catch (ExecutionException e) {
+ assertThat(e.toString(), containsString(TEST_ERROR));
+
org.junit.Assert.assertTrue(WorkCancelledException.isWorkCancelledException(e));
Review Comment:
static import assertTrue
##########
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/data/PCollectionConsumerRegistryTest.java:
##########
@@ -703,6 +703,90 @@ public StreamObserver<BeamFnApi.LogEntry.List> logging(
}
}
+ @Test
+ public void doesNotLogWorkCancelledException() throws Exception {
+ final String pTransformId = "pTransformId";
+ final String message = "Work item cancelled";
+ final String instructionId = "instruction";
+ final Exception thrownException =
+ new RuntimeException(new
org.apache.beam.fn.harness.state.WorkCancelledException(message));
+
+ AtomicBoolean clientClosedStream = new AtomicBoolean();
+ Collection<BeamFnApi.LogEntry> values = new ConcurrentLinkedQueue<>();
+ AtomicReference<StreamObserver<BeamFnApi.LogControl>>
outboundServerObserver =
+ new AtomicReference<>();
+ CallStreamObserver<BeamFnApi.LogEntry.List> inboundServerObserver =
+ TestStreams.withOnNext(
+ (BeamFnApi.LogEntry.List logEntries) ->
+ values.addAll(logEntries.getLogEntriesList()))
+ .withOnCompleted(
+ () -> {
+ clientClosedStream.set(true);
+ outboundServerObserver.get().onCompleted();
+ })
+ .build();
+
+ Endpoints.ApiServiceDescriptor apiServiceDescriptor =
+ Endpoints.ApiServiceDescriptor.newBuilder()
+ .setUrl(this.getClass().getName() + "-" +
UUID.randomUUID().toString())
+ .build();
+ Server server =
+ InProcessServerBuilder.forName(apiServiceDescriptor.getUrl())
+ .addService(
+ new BeamFnLoggingGrpc.BeamFnLoggingImplBase() {
+ @Override
+ public StreamObserver<BeamFnApi.LogEntry.List> logging(
+ StreamObserver<BeamFnApi.LogControl> outboundObserver) {
+ outboundServerObserver.set(outboundObserver);
+ return inboundServerObserver;
+ }
+ })
+ .build();
+ server.start();
+ ManagedChannel channel =
InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl()).build();
+
+ ExecutionStateSampler sampler =
+ new ExecutionStateSampler(PipelineOptionsFactory.create(),
System::currentTimeMillis, null);
+ ExecutionStateSampler.ExecutionStateTracker stateTracker =
sampler.create();
+ stateTracker.start("process-bundle");
+ ExecutionStateSampler.ExecutionState state =
+ stateTracker.create("shortId", pTransformId, pTransformId, "process");
+ state.activate();
+
+ BeamFnLoggingMDC.setInstructionId(instructionId);
+ BeamFnLoggingMDC.setStateTracker(stateTracker);
+
+ try (LoggingClient ignored =
+ LoggingClientFactory.createAndStart(
+ PipelineOptionsFactory.create(),
+ apiServiceDescriptor,
+ (Endpoints.ApiServiceDescriptor descriptor) -> channel)) {
+
+ ShortIdMap shortIds = new ShortIdMap();
+ BundleProgressReporter.InMemory reporterAndRegistrar = new
BundleProgressReporter.InMemory();
+ PCollectionConsumerRegistry consumers =
+ new PCollectionConsumerRegistry(
+ stateTracker, shortIds, reporterAndRegistrar, TEST_DESCRIPTOR);
+ FnDataReceiver<WindowedValue<String>> consumer =
mock(FnDataReceiver.class);
+
+ consumers.register(P_COLLECTION_A, pTransformId, pTransformId + "Name",
consumer);
+
+ FnDataReceiver<WindowedValue<String>> wrapperConsumer =
+ (FnDataReceiver<WindowedValue<String>>)
+ (FnDataReceiver)
consumers.getMultiplexingConsumer(P_COLLECTION_A);
+
+ doThrow(thrownException).when(consumer).accept(any());
+ expectedException.expectMessage(message);
+ expectedException.expect(Exception.class);
Review Comment:
should we expect thrownException?
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/WorkCancelledException.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.fn.harness.state;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * Indicates that the work item is no longer valid on the runner and should be
cancelled without
+ * logging an error.
+ */
+public class WorkCancelledException extends IllegalStateException {
Review Comment:
extend RuntimeException instead of IllegalStateException
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]