kw2542 commented on a change in pull request #15421:
URL: https://github.com/apache/beam/pull/15421#discussion_r701312783



##########
File path: 
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/SamzaTestStreamTranslator.java
##########
@@ -90,11 +95,53 @@ public void translate(
     ctx.registerInputMessageStream(output, inputDescriptor);
   }
 
+  @SuppressWarnings("unchecked")
   @Override
   public void translatePortable(
       PipelineNode.PTransformNode transform,
       QueryablePipeline pipeline,
       PortableTranslationContext ctx) {
-    throw new SamzaException("TestStream is not supported in portable by Samza 
runner");
+    final String outputId = ctx.getOutputId(transform);
+    final String escapedOutputId = 
SamzaPipelineTranslatorUtils.escape(outputId);
+    final GenericSystemDescriptor systemDescriptor =
+        new GenericSystemDescriptor(escapedOutputId, 
SamzaTestStreamSystemFactory.class.getName());
+    final ByteString bytes = transform.getTransform().getSpec().getPayload();
+    final RunnerApi.TestStreamPayload payload;
+    final Coder<T> coder;
+
+    try {
+      payload = RunnerApi.TestStreamPayload.parseFrom(bytes);
+      coder =
+          (Coder<T>)
+              RehydratedComponents.forComponents(pipeline.getComponents())
+                  .getCoder(payload.getCoderId());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+
+    // the decoder for encodedTestStream
+    SerializableFunction<String, TestStream<?>> testStreamDecoder =
+        string -> {
+          try {
+            return TestStreamTranslation.testStreamFromProtoPayload(payload, 
coder);
+          } catch (IOException e) {
+            throw new SamzaException("Could not decode TestStream.", e);
+          }
+        };
+
+    final Map<String, String> systemConfig =
+        ImmutableMap.of(
+            "encodedTestStream",
+            Base64Serializer.serializeUnchecked(bytes),

Review comment:
       Updated the decoder function not to encode the input anymore.




-- 
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]


Reply via email to