use of org.apache.samza.operators.impl.store.TestInMemoryStore in project samza by apache.
the class TestJoinOperator method createStreamOperatorTask.
private StreamOperatorTask createStreamOperatorTask(Clock clock, StreamApplicationDescriptorImpl graphSpec) throws Exception {
Map<String, String> mapConfig = new HashMap<>();
mapConfig.put("job.name", "jobName");
mapConfig.put("job.id", "jobId");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream", "insystem", "instream");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream2", "insystem", "instream2");
Context context = new MockContext(new MapConfig(mapConfig));
TaskModel taskModel = mock(TaskModel.class);
when(taskModel.getSystemStreamPartitions()).thenReturn(ImmutableSet.of(new SystemStreamPartition("insystem", "instream", new Partition(0)), new SystemStreamPartition("insystem", "instream2", new Partition(0))));
when(context.getTaskContext().getTaskModel()).thenReturn(taskModel);
when(context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap());
// need to return different stores for left and right side
IntegerSerde integerSerde = new IntegerSerde();
TimestampedValueSerde timestampedValueSerde = new TimestampedValueSerde(new KVSerde(integerSerde, integerSerde));
when(context.getTaskContext().getStore(eq("jobName-jobId-join-j1-L"))).thenReturn(new TestInMemoryStore(integerSerde, timestampedValueSerde));
when(context.getTaskContext().getStore(eq("jobName-jobId-join-j1-R"))).thenReturn(new TestInMemoryStore(integerSerde, timestampedValueSerde));
StreamOperatorTask sot = new StreamOperatorTask(graphSpec.getOperatorSpecGraph(), clock);
sot.init(context);
return sot;
}
use of org.apache.samza.operators.impl.store.TestInMemoryStore in project samza by apache.
the class TestWindowOperator method testTumblingAggregatingWindowsDiscardingMode.
@Test
public void testTumblingAggregatingWindowsDiscardingMode() throws Exception {
when(this.context.getTaskContext().getStore("jobName-jobId-window-w1")).thenReturn(new TestInMemoryStore<>(new TimeSeriesKeySerde(new IntegerSerde()), new IntegerSerde()));
OperatorSpecGraph sgb = this.getAggregateTumblingWindowStreamGraph(AccumulationMode.DISCARDING, Duration.ofSeconds(1), Triggers.repeat(Triggers.count(2))).getOperatorSpecGraph();
List<WindowPane<Integer, Integer>> windowPanes = new ArrayList<>();
TestClock testClock = new TestClock();
StreamOperatorTask task = new StreamOperatorTask(sgb, testClock);
task.init(this.context);
MessageCollector messageCollector = envelope -> windowPanes.add((WindowPane<Integer, Integer>) envelope.getMessage());
integers.forEach(n -> task.processAsync(new IntegerEnvelope(n), messageCollector, taskCoordinator, taskCallback));
testClock.advanceTime(Duration.ofSeconds(1));
task.window(messageCollector, taskCoordinator);
Assert.assertEquals(windowPanes.size(), 5);
Assert.assertEquals(windowPanes.get(0).getMessage(), new Integer(2));
Assert.assertEquals(windowPanes.get(1).getMessage(), new Integer(2));
Assert.assertEquals(windowPanes.get(2).getMessage(), new Integer(2));
Assert.assertEquals(windowPanes.get(3).getMessage(), new Integer(2));
Assert.assertEquals(windowPanes.get(4).getMessage(), new Integer(1));
}
Aggregations