Sanil15 commented on code in PR #26437:
URL: https://github.com/apache/beam/pull/26437#discussion_r1188046950
##########
runners/samza/src/test/java/org/apache/beam/runners/samza/translation/TranslationContextTest.java:
##########
@@ -43,45 +53,104 @@
import org.apache.samza.serializers.Serde;
import org.apache.samza.system.descriptors.GenericInputDescriptor;
import org.apache.samza.system.descriptors.GenericSystemDescriptor;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({OpAdapter.class, PTransformTranslation.class})
@SuppressWarnings({"rawtypes"})
public class TranslationContextTest {
- private final GenericInputDescriptor testInputDescriptor =
- new GenericSystemDescriptor("mockSystem", "mockFactoryClassName")
- .getInputDescriptor("test-input-1", mock(Serde.class));
- MapFunction<Object, String> keyFn = m -> m.toString();
- MapFunction<Object, Object> valueFn = m -> m;
- private final String streamName = "testStream";
- KVSerde<Object, Object> serde = KVSerde.of(new NoOpSerde<>(), new
NoOpSerde<>());
- StreamApplicationDescriptor streamApplicationDescriptor =
- new StreamApplicationDescriptorImpl(
- appDesc -> {
- MessageStream inputStream =
appDesc.getInputStream(testInputDescriptor);
- inputStream.partitionBy(keyFn, valueFn, serde, streamName);
- },
- getConfig());
- Map<PValue, String> idMap = new HashMap<>();
- Set<String> nonUniqueStateIds = new HashSet<>();
- TranslationContext translationContext =
- new TranslationContext(
- streamApplicationDescriptor, idMap, nonUniqueStateIds,
mock(SamzaPipelineOptions.class));
+ TranslationContext translationContext;
+ AppliedPTransform pTransform;
+ PCollection output;
+ List inputDescriptors;
+ StreamApplicationDescriptor streamApplicationDescriptor;
+ SamzaPipelineOptions pipelineOptions;
+ TransformHierarchy.Node node;
- @Test
- public void testRegisterInputMessageStreams() {
- final PCollection output = mock(PCollection.class);
+ @Before
+ public void before() {
+ final GenericInputDescriptor testInputDescriptor =
+ new GenericSystemDescriptor("mockSystem", "mockFactoryClassName")
+ .getInputDescriptor("test-input-1", mock(Serde.class));
+ final MapFunction<Object, String> keyFn = m -> m.toString();
+ final MapFunction<Object, Object> valueFn = m -> m;
+ final String streamName = "testStream";
+ KVSerde<Object, Object> serde = KVSerde.of(new NoOpSerde<>(), new
NoOpSerde<>());
+ pipelineOptions = mock(SamzaPipelineOptions.class);
+ when(pipelineOptions.getEnableTransformMetrics()).thenReturn(false);
+ // Create a stream application descriptor with a partitionBy
+ streamApplicationDescriptor =
+ new StreamApplicationDescriptorImpl(
+ appDesc -> {
+ MessageStream inputStream =
appDesc.getInputStream(testInputDescriptor);
+ inputStream.partitionBy(keyFn, valueFn, serde, streamName);
+ },
+ getConfig());
+ Map<PValue, String> idMap = new HashMap<>();
+ Set<String> nonUniqueStateIds = new HashSet<>();
+ translationContext =
+ new TranslationContext(
+ streamApplicationDescriptor, idMap, nonUniqueStateIds,
pipelineOptions);
+
+ // Register the input message stream
+ output = mock(PCollection.class);
+ pTransform = mock(AppliedPTransform.class);
+ node = mock(TransformHierarchy.Node.class);
+ when(pTransform.getFullName()).thenReturn("mock-ptransform");
List<String> topics = Arrays.asList("stream1", "stream2");
- List inputDescriptors =
+ inputDescriptors =
topics.stream()
.map(topicName -> createSamzaInputDescriptor(topicName, topicName))
.collect(Collectors.toList());
+ }
+ @Test
+ public void testRegisterInputMessageStreams() {
+ translationContext.setCurrentTransform(pTransform);
translationContext.registerInputMessageStreams(output, inputDescriptors);
-
assertNotNull(translationContext.getMessageStream(output));
}
- public GenericInputDescriptor<KV<String, OpMessage<?>>>
createSamzaInputDescriptor(
+ @Test
+ public void testMetricOpNotAttachedForIOTransform() {
Review Comment:
done
##########
runners/samza/src/test/java/org/apache/beam/runners/samza/metrics/TestSamzaRunnerWithTransformMetrics.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.samza.metrics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+import org.apache.beam.runners.samza.SamzaPipelineOptions;
+import org.apache.beam.runners.samza.TestSamzaRunner;
+import org.apache.beam.runners.samza.util.InMemoryMetricsReporter;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.Values;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.apache.samza.metrics.Counter;
+import org.apache.samza.metrics.Gauge;
+import org.apache.samza.metrics.Metric;
+import org.junit.Test;
+
+public class TestSamzaRunnerWithTransformMetrics {
Review Comment:
added
--
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]