use of org.apache.samza.operators.impl.store.TimeSeriesKeySerde in project samza by apache.
the class WindowOperatorSpec method getStoreDescriptors.
@Override
public Collection<StoreDescriptor> getStoreDescriptors() {
String storeName = getOpId();
String storeFactory = "org.apache.samza.storage.kv.RocksDbKeyValueStorageEngineFactory";
Serde storeKeySerde = new TimeSeriesKeySerde<>(window.getKeySerde());
Serde storeValSerde = window.getFoldLeftFunction() == null ? window.getMsgSerde() : window.getWindowValSerde();
StoreDescriptor descriptor = new StoreDescriptor(storeName, storeFactory, storeKeySerde, storeValSerde, storeName, Collections.emptyMap());
return Collections.singletonList(descriptor);
}
use of org.apache.samza.operators.impl.store.TimeSeriesKeySerde in project samza by apache.
the class TestWindowOperator method setup.
@Before
public void setup() {
Map<String, String> configMap = new HashMap<>();
configMap.put("job.default.system", "kafka");
configMap.put("job.name", "jobName");
configMap.put("job.id", "jobId");
this.config = new MapConfig(configMap);
this.context = new MockContext();
when(this.context.getJobContext().getConfig()).thenReturn(this.config);
Serde storeKeySerde = new TimeSeriesKeySerde(new IntegerSerde());
Serde storeValSerde = KVSerde.of(new IntegerSerde(), new IntegerSerde());
SystemStreamPartition ssp = new SystemStreamPartition("kafka", "integers", new Partition(0));
TaskModel taskModel = mock(TaskModel.class);
when(taskModel.getSystemStreamPartitions()).thenReturn(ImmutableSet.of(ssp));
when(taskModel.getTaskName()).thenReturn(new TaskName("task 1"));
when(this.context.getTaskContext().getTaskModel()).thenReturn(taskModel);
when(((TaskContextImpl) this.context.getTaskContext()).getSspsExcludingSideInputs()).thenReturn(ImmutableSet.of(ssp));
when(this.context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(this.context.getTaskContext().getStore("jobName-jobId-window-w1")).thenReturn(new TestInMemoryStore<>(storeKeySerde, storeValSerde));
}
use of org.apache.samza.operators.impl.store.TimeSeriesKeySerde 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