use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testStreamOperatorSpecWithMapWithFunctionReference.
@Test
public void testStreamOperatorSpecWithMapWithFunctionReference() {
MapFunction<KV<String, Object>, Object> mapFn = KV::getValue;
StreamOperatorSpec<KV<String, Object>, Object> streamOperatorSpec = OperatorSpecs.createMapOperatorSpec(mapFn, "op0");
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> cloneOperatorSpec = (StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(streamOperatorSpec);
assertNotEquals(streamOperatorSpec, cloneOperatorSpec);
assertTrue(streamOperatorSpec.isClone(cloneOperatorSpec));
MapFunction userFn = (MapFunction) Whitebox.getInternalState(streamOperatorSpec, "mapFn");
assertEquals(userFn, mapFn);
assertNotEquals(streamOperatorSpec.getTransformFn(), cloneOperatorSpec.getTransformFn());
MapFunction clonedUserFn = (MapFunction) Whitebox.getInternalState(cloneOperatorSpec, "mapFn");
assertTrue(cloneOperatorSpec.getTransformFn() instanceof FlatMapFunction);
assertTrue(clonedUserFn instanceof MapFunction);
assertNotEquals(userFn, clonedUserFn);
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testStreamOperatorSpecWithMapWithEnum.
@Test
public void testStreamOperatorSpecWithMapWithEnum() {
MapFunction<TestMessageEnvelope, TestOutputMessageEnvelope> mapFn = new MapWithEnum(OperatorSpecTestUtils.TestEnum.One);
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> streamOperatorSpec = OperatorSpecs.createMapOperatorSpec(mapFn, "op0");
assertTrue(streamOperatorSpec instanceof MapOperatorSpec);
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> cloneOperatorSpec = (StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(streamOperatorSpec);
assertNotEquals(streamOperatorSpec, cloneOperatorSpec);
assertTrue(streamOperatorSpec.isClone(cloneOperatorSpec));
MapFunction userFn = (MapFunction) Whitebox.getInternalState(streamOperatorSpec, "mapFn");
assertEquals(userFn, mapFn);
assertNotEquals(streamOperatorSpec.getTransformFn(), cloneOperatorSpec.getTransformFn());
MapFunction clonedUserFn = (MapFunction) Whitebox.getInternalState(cloneOperatorSpec, "mapFn");
assertTrue(cloneOperatorSpec.getTransformFn() instanceof FlatMapFunction);
assertTrue(clonedUserFn instanceof MapWithEnum);
assertNotEquals(userFn, clonedUserFn);
// originally the types should be the same
assertTrue(((MapWithEnum) userFn).getType() == ((MapWithEnum) clonedUserFn).getType());
// after changing the type of the cloned user function, the types are different now
((MapWithEnum) clonedUserFn).setType(OperatorSpecTestUtils.TestEnum.Two);
assertTrue(((MapWithEnum) userFn).getType() != ((MapWithEnum) clonedUserFn).getType());
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testStreamOperatorSpecWithMapAndListInClosure.
@Test
public void testStreamOperatorSpecWithMapAndListInClosure() {
List<Integer> integers = new ArrayList<>(1);
integers.add(0, 100);
List<String> keys = new ArrayList<>(1);
keys.add(0, "test-1");
MapFunction<TestMessageEnvelope, TestOutputMessageEnvelope> mapFn = m -> new TestOutputMessageEnvelope(keys.get(m.getKey().hashCode() % 1), integers.get(m.getMessage().hashCode() % 1));
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> streamOperatorSpec = OperatorSpecs.createMapOperatorSpec(mapFn, "op0");
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> cloneOperatorSpec = (StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(streamOperatorSpec);
assertNotEquals(streamOperatorSpec, cloneOperatorSpec);
assertTrue(streamOperatorSpec.isClone(cloneOperatorSpec));
MapFunction userFn = (MapFunction) Whitebox.getInternalState(streamOperatorSpec, "mapFn");
assertEquals(userFn, mapFn);
assertNotEquals(streamOperatorSpec.getTransformFn(), cloneOperatorSpec.getTransformFn());
MapFunction clonedUserFn = (MapFunction) Whitebox.getInternalState(cloneOperatorSpec, "mapFn");
assertTrue(cloneOperatorSpec.getTransformFn() instanceof FlatMapFunction);
assertTrue(clonedUserFn instanceof MapFunction);
assertNotEquals(userFn, clonedUserFn);
// verify changing the values in the original keys and integers list will change the result of the original map function
TestMessageEnvelope mockImsg = new TestMessageEnvelope("input-key-x", new String("value-x"));
assertEquals(((MapFunction) userFn).apply(mockImsg), new TestOutputMessageEnvelope("test-1", 100));
integers.set(0, 200);
keys.set(0, "test-2");
assertEquals(((MapFunction) userFn).apply(mockImsg), new TestOutputMessageEnvelope("test-2", 200));
// verify that the cloned map function uses a different copy of lists and still yields the same result
assertEquals(((MapFunction) clonedUserFn).apply(mockImsg), new TestOutputMessageEnvelope("test-1", 100));
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testStreamOperatorSpecWithMap.
@Test
public void testStreamOperatorSpecWithMap() {
MapFunction<TestMessageEnvelope, TestOutputMessageEnvelope> mapFn = m -> new TestOutputMessageEnvelope(m.getKey(), m.getMessage().hashCode());
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> streamOperatorSpec = OperatorSpecs.createMapOperatorSpec(mapFn, "op0");
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> cloneOperatorSpec = (StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(streamOperatorSpec);
assertNotEquals(streamOperatorSpec, cloneOperatorSpec);
assertTrue(streamOperatorSpec.isClone(cloneOperatorSpec));
MapFunction userFn = (MapFunction) Whitebox.getInternalState(streamOperatorSpec, "mapFn");
assertEquals(userFn, mapFn);
assertNotEquals(streamOperatorSpec.getTransformFn(), cloneOperatorSpec.getTransformFn());
MapFunction clonedUserFn = (MapFunction) Whitebox.getInternalState(cloneOperatorSpec, "mapFn");
assertTrue(cloneOperatorSpec.getTransformFn() instanceof FlatMapFunction);
assertTrue(clonedUserFn instanceof MapFunction);
assertNotEquals(userFn, clonedUserFn);
assertNull(streamOperatorSpec.getWatermarkFn());
assertNull(cloneOperatorSpec.getWatermarkFn());
assertNull(streamOperatorSpec.getScheduledFn());
assertNull(cloneOperatorSpec.getScheduledFn());
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testStreamOperatorSpecWithFilter.
@Test
public void testStreamOperatorSpecWithFilter() {
FilterFunction<TestMessageEnvelope> filterFn = m -> m.getKey().equals("key1");
StreamOperatorSpec<TestMessageEnvelope, TestMessageEnvelope> streamOperatorSpec = OperatorSpecs.createFilterOperatorSpec(filterFn, "op0");
StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope> cloneOperatorSpec = (StreamOperatorSpec<TestMessageEnvelope, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(streamOperatorSpec);
assertNotEquals(streamOperatorSpec, cloneOperatorSpec);
assertTrue(streamOperatorSpec.isClone(cloneOperatorSpec));
FilterFunction userFn = (FilterFunction) Whitebox.getInternalState(streamOperatorSpec, "filterFn");
assertEquals(userFn, filterFn);
assertNotEquals(streamOperatorSpec.getTransformFn(), cloneOperatorSpec.getTransformFn());
FilterFunction clonedUserFn = (FilterFunction) Whitebox.getInternalState(cloneOperatorSpec, "filterFn");
assertTrue(cloneOperatorSpec.getTransformFn() instanceof FlatMapFunction);
assertTrue(clonedUserFn instanceof FilterFunction);
assertNotEquals(userFn, clonedUserFn);
assertNull(streamOperatorSpec.getWatermarkFn());
assertNull(cloneOperatorSpec.getWatermarkFn());
assertNull(streamOperatorSpec.getScheduledFn());
assertNull(cloneOperatorSpec.getScheduledFn());
}
Aggregations