use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestAsyncRunLoop method createTaskInstance.
TaskInstance createTaskInstance(AsyncStreamTask task, TaskName taskName, SystemStreamPartition ssp, OffsetManager manager, SystemConsumers consumers) {
TaskInstanceMetrics taskInstanceMetrics = new TaskInstanceMetrics("task", new MetricsRegistryMap());
scala.collection.immutable.Set<SystemStreamPartition> sspSet = JavaConverters.asScalaSetConverter(Collections.singleton(ssp)).asScala().toSet();
return new TaskInstance(task, taskName, mock(Config.class), taskInstanceMetrics, null, consumers, mock(TaskInstanceCollector.class), mock(SamzaContainerContext.class), manager, null, null, sspSet, new TaskInstanceExceptionHandler(taskInstanceMetrics, new scala.collection.immutable.HashSet<String>()));
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpls method testBroadcastChain.
@Test
public void testBroadcastChain() throws IllegalAccessException, InvocationTargetException {
// test creation of broadcast chain
StreamGraphImpl mockGraph = mock(StreamGraphImpl.class);
MessageStreamImpl<TestMessageEnvelope> testInput = TestMessageStreamImplUtil.getMessageStreamImpl(mockGraph);
TaskContext mockContext = mock(TaskContext.class);
when(mockContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
Config mockConfig = mock(Config.class);
testInput.filter(m -> m.getMessage().getEventTime() > 123456L).flatMap(m -> new ArrayList() {
{
this.add(m);
this.add(m);
}
});
testInput.filter(m -> m.getMessage().getEventTime() < 123456L).map(m -> m);
OperatorImplGraph opGraph = new OperatorImplGraph();
RootOperatorImpl operatorChain = (RootOperatorImpl) createOpsMethod.invoke(opGraph, testInput, mockConfig, mockContext);
Set<OperatorImpl> subsSet = (Set<OperatorImpl>) nextOperatorsField.get(operatorChain);
assertEquals(subsSet.size(), 2);
Iterator<OperatorImpl> iter = subsSet.iterator();
// check the first branch w/ flatMap
OperatorImpl<TestMessageEnvelope, TestMessageEnvelope> opImpl = iter.next();
Set<OperatorImpl> subsOps = (Set<OperatorImpl>) nextOperatorsField.get(opImpl);
assertEquals(subsOps.size(), 1);
OperatorImpl flatMapImpl = subsOps.iterator().next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(flatMapImpl);
assertEquals(subsOps.size(), 0);
// check the second branch w/ map
opImpl = iter.next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(opImpl);
assertEquals(subsOps.size(), 1);
OperatorImpl mapImpl = subsOps.iterator().next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(mapImpl);
assertEquals(subsOps.size(), 0);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpls method testEmptyChain.
@Test
public void testEmptyChain() throws InvocationTargetException, IllegalAccessException {
// test creation of empty chain
MessageStreamImpl<TestMessageEnvelope> testStream = mock(MessageStreamImpl.class);
TaskContext mockContext = mock(TaskContext.class);
when(mockContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
Config mockConfig = mock(Config.class);
OperatorImplGraph opGraph = new OperatorImplGraph();
RootOperatorImpl operatorChain = (RootOperatorImpl) createOpsMethod.invoke(opGraph, testStream, mockConfig, mockContext);
assertTrue(operatorChain != null);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpls method testLinearChain.
@Test
public void testLinearChain() throws IllegalAccessException, InvocationTargetException {
// test creation of linear chain
StreamGraphImpl mockGraph = mock(StreamGraphImpl.class);
MessageStreamImpl<TestMessageEnvelope> testInput = TestMessageStreamImplUtil.getMessageStreamImpl(mockGraph);
TaskContext mockContext = mock(TaskContext.class);
when(mockContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
Config mockConfig = mock(Config.class);
testInput.map(m -> m).window(Windows.keyedSessionWindow(TestMessageEnvelope::getKey, Duration.ofMinutes(10)));
OperatorImplGraph opGraph = new OperatorImplGraph();
RootOperatorImpl operatorChain = (RootOperatorImpl) createOpsMethod.invoke(opGraph, testInput, mockConfig, mockContext);
Set<OperatorImpl> subsSet = (Set<OperatorImpl>) nextOperatorsField.get(operatorChain);
assertEquals(subsSet.size(), 1);
OperatorImpl<TestMessageEnvelope, TestMessageEnvelope> firstOpImpl = subsSet.iterator().next();
Set<OperatorImpl> subsOps = (Set<OperatorImpl>) nextOperatorsField.get(firstOpImpl);
assertEquals(subsOps.size(), 1);
OperatorImpl wndOpImpl = subsOps.iterator().next();
subsOps = (Set<OperatorImpl>) nextOperatorsField.get(wndOpImpl);
assertEquals(subsOps.size(), 0);
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpl method testMultipleInitShouldThrow.
@Test(expected = IllegalStateException.class)
public void testMultipleInitShouldThrow() {
OperatorImpl<Object, Object> opImpl = new TestOpImpl(mock(Object.class));
TaskContext mockTaskContext = mock(TaskContext.class);
when(mockTaskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
opImpl.init(mock(Config.class), mockTaskContext);
opImpl.init(mock(Config.class), mockTaskContext);
}
Aggregations