@Override public void init(Context context) { super.init(context); Preconditions.checkNotNull(this.context, "Must specify context for local tables."); kvStore = this.context.getTaskContext().getStore(tableId); Preconditions.checkNotNull(kvStore, String.format( "Backing store for table %s was not injected by SamzaContainer", tableId)); logger.info("Initialized backing store for table " + tableId); }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }
@Override public void init(Context context) { super.init(context); Preconditions.checkNotNull(this.context, "Must specify context for local tables."); kvStore = (KeyValueStore) this.context.getTaskContext().getStore(tableSpec.getId()); if (kvStore == null) { throw new SamzaException(String.format( "Backing store for table %s was not injected by SamzaContainer", tableSpec.getId())); } logger.info("Initialized backing store for table " + tableSpec.getId()); }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }
@Override public void init(Context context) { super.init(context); Preconditions.checkNotNull(this.context, "Must specify context for local tables."); kvStore = (KeyValueStore) this.context.getTaskContext().getStore(tableSpec.getId()); if (kvStore == null) { throw new SamzaException(String.format( "Backing store for table %s was not injected by SamzaContainer", tableSpec.getId())); } logger.info("Initialized backing store for table " + tableSpec.getId()); }
@Test public void testInit() { Context context = mock(Context.class); JobContext jobContext = mock(JobContext.class); when(context.getJobContext()).thenReturn(jobContext); when(jobContext.getConfig()).thenReturn(new MapConfig()); ContainerContext containerContext = mock(ContainerContext.class); when(context.getContainerContext()).thenReturn(containerContext); when(containerContext.getContainerMetricsRegistry()).thenReturn(new NoOpMetricsRegistry()); TaskContext taskContext = mock(TaskContext.class); when(context.getTaskContext()).thenReturn(taskContext); when(taskContext.getStore(any())).thenReturn(mock(KeyValueStore.class)); TableProvider tableProvider = createTableProvider("t1"); tableProvider.init(context); Assert.assertNotNull(tableProvider.getTable()); }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
@Override protected void handleInit(Context context) { KeyValueStore<TimeSeriesKey<K>, Object> store = (KeyValueStore<TimeSeriesKey<K>, Object>) context.getTaskContext().getStore(windowOpSpec.getOpId()); if (initializer != null) { initializer.init(context); } if (keyFn != null) { keyFn.init(context); } // For aggregating windows, we use the store in over-write mode since we only retain the aggregated // value. Else, we use the store in append-mode. if (foldLeftFn != null) { foldLeftFn.init(context); timeSeriesStore = new TimeSeriesStoreImpl(store, false); } else { timeSeriesStore = new TimeSeriesStoreImpl(store, true); } }
@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()); TaskModel taskModel = mock(TaskModel.class); when(taskModel.getSystemStreamPartitions()).thenReturn(ImmutableSet .of(new SystemStreamPartition("kafka", "integTestExecutionPlannerers", new Partition(0)))); when(taskModel.getTaskName()).thenReturn(new TaskName("task 1")); when(this.context.getTaskContext().getTaskModel()).thenReturn(taskModel); 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)); }
@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.process(new IntegerEnvelope(n), messageCollector, taskCoordinator)); 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)); }