public StreamOperatorTask(OperatorSpecGraph specGraph) { this(specGraph, SystemClock.instance()); }
/** * create one TaskStorageManager for each task. Add all of them to the * List<TaskStorageManager> */ @SuppressWarnings({"unchecked", "rawtypes"}) private void getContainerStorageManagers() { Clock clock = SystemClock.instance(); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock); // don't worry about prefetching for this; looks like the tool doesn't flush to offset files anyways Map<String, SystemFactory> systemFactories = new JavaSystemConfig(jobConfig).getSystemFactories(); for (ContainerModel containerModel : containers.values()) { ContainerContext containerContext = new ContainerContextImpl(containerModel, new MetricsRegistryMap()); ContainerStorageManager containerStorageManager = new ContainerStorageManager(containerModel, streamMetadataCache, systemAdmins, changeLogSystemStreams, storageEngineFactories, systemFactories, this.getSerdes(), jobConfig, new HashMap<>(), new SamzaContainerMetrics(containerModel.getId(), new MetricsRegistryMap()), JobContextImpl.fromConfigWithDefaults(jobConfig), containerContext, new HashMap<>(), storeBaseDir, storeBaseDir, maxPartitionNumber, new SystemClock()); this.containerStorageManagers.put(containerModel.getId(), containerStorageManager); } } }
@Test public void joinReverse() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to second stream numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to first stream with same keys numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, outputSum); }
Clock clock = SystemClock.instance(); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock); systemAdmins, new StorageConfig(jobConfig).getChangeLogDeleteRetentionsInMs(), new SystemClock());
@Test public void joinRetainsMatchedMessagesReverse() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to first stream numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to second stream with same key numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, outputSum); output.clear(); // push messages to second stream with same keys once again. numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); int newOutputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, newOutputSum); // should produce the same output as before }
public StreamOperatorTask(OperatorSpecGraph specGraph) { this(specGraph, SystemClock.instance()); }
Clock clock = SystemClock.instance(); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock); systemAdmins, new StorageConfig(jobConfig).getChangeLogDeleteRetentionsInMs(), new SystemClock());
@Test public void join() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to first stream numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to second stream with same keys numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, outputSum); }
public StreamOperatorTask(OperatorSpecGraph specGraph) { this(specGraph, SystemClock.instance()); }
Clock clock = SystemClock.instance(); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock); systemAdmins, new StorageConfig(jobConfig).getChangeLogDeleteRetentionsInMs(), new SystemClock());
@Test public void joinNoMatch() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to first stream numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to second stream with different keys numbers.forEach(n -> sot.process(new SecondStreamIME(n + 100, n), messageCollector, taskCoordinator)); assertTrue(output.isEmpty()); }
public StreamOperatorTask(OperatorSpecGraph specGraph) { this(specGraph, SystemClock.instance()); }
Clock clock = SystemClock.instance(); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock); systemAdmins, new StorageConfig(jobConfig).getChangeLogDeleteRetentionsInMs(), new SystemClock());
@Test public void joinNoMatchReverse() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to second stream numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to first stream with different keys numbers.forEach(n -> sot.process(new FirstStreamIME(n + 100, n), messageCollector, taskCoordinator)); assertTrue(output.isEmpty()); }
public StreamOperatorTask(OperatorSpecGraph specGraph) { this(specGraph, SystemClock.instance()); }
@Test public void joinRetainsMatchedMessages() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to first stream numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to second stream with same key numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, outputSum); output.clear(); // push messages to first stream with same keys once again. numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); int newOutputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(110, newOutputSum); // should produce the same output as before }
@Override public JobModel getJobModel() { SystemAdmins systemAdmins = new SystemAdmins(config); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, SystemClock.instance()); systemAdmins.start(); try { String containerId = Integer.toString(config.getInt(JobConfig.PROCESSOR_ID())); GrouperMetadata grouperMetadata = new GrouperMetadataImpl(ImmutableMap.of(String.valueOf(containerId), locationId), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); return JobModelManager.readJobModel(this.config, Collections.emptyMap(), streamMetadataCache, grouperMetadata); } finally { systemAdmins.stop(); } }
@Test public void joinRetainsLatestMessageForKeyReverse() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to second stream numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to second stream again with same keys but different values numbers.forEach(n -> sot.process(new SecondStreamIME(n, 2 * n), messageCollector, taskCoordinator)); // push messages to first stream with same key numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(165, outputSum); // should use latest messages in the second stream }
@Override public JobModel getJobModel() { SystemAdmins systemAdmins = new SystemAdmins(config); StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, SystemClock.instance()); systemAdmins.start(); String containerId = Integer.toString(config.getInt(JobConfig.PROCESSOR_ID())); /** TODO: Locality Manager seems to be required in JC for reading locality info and grouping tasks intelligently and also, in SamzaContainer for writing locality info to the coordinator stream. This closely couples together TaskNameGrouper with the LocalityManager! Hence, groupers should be a property of the jobcoordinator (job.coordinator.task.grouper, instead of task.systemstreampartition.grouper) */ JobModel jobModel = JobModelManager.readJobModel(this.config, Collections.emptyMap(), null, streamMetadataCache, Collections.singletonList(containerId)); systemAdmins.stop(); return jobModel; }
@Test public void joinRetainsLatestMessageForKey() throws Exception { StreamApplicationDescriptorImpl streamAppDesc = this.getTestJoinStreamGraph(new TestJoinFunction()); StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), streamAppDesc); List<Integer> output = new ArrayList<>(); MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage()); // push messages to first stream numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator)); // push messages to first stream again with same keys but different values numbers.forEach(n -> sot.process(new FirstStreamIME(n, 2 * n), messageCollector, taskCoordinator)); // push messages to second stream with same key numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator)); int outputSum = output.stream().reduce(0, (s, m) -> s + m); assertEquals(165, outputSum); // should use latest messages in the first stream }