Search in sources :

Example 41 with MetricsRegistryMap

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>()));
}
Also used : TaskInstance(org.apache.samza.container.TaskInstance) SamzaContainerContext(org.apache.samza.container.SamzaContainerContext) Config(org.apache.samza.config.Config) TaskInstanceMetrics(org.apache.samza.container.TaskInstanceMetrics) TaskInstanceExceptionHandler(org.apache.samza.container.TaskInstanceExceptionHandler) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) HashSet(java.util.HashSet)

Example 42 with MetricsRegistryMap

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);
}
Also used : StreamOperatorSpec(org.apache.samza.operators.spec.StreamOperatorSpec) Assert.assertNotSame(org.junit.Assert.assertNotSame) ArrayList(java.util.ArrayList) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) PartialJoinOperatorSpec(org.apache.samza.operators.spec.PartialJoinOperatorSpec) SinkOperatorSpec(org.apache.samza.operators.spec.SinkOperatorSpec) MessageStreamImpl(org.apache.samza.operators.MessageStreamImpl) Duration(java.time.Duration) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) Method(java.lang.reflect.Method) Before(org.junit.Before) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) WindowType(org.apache.samza.operators.windows.internal.WindowType) TaskContext(org.apache.samza.task.TaskContext) Windows(org.apache.samza.operators.windows.Windows) Iterator(java.util.Iterator) WindowOperatorSpec(org.apache.samza.operators.spec.WindowOperatorSpec) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JoinFunction(org.apache.samza.operators.functions.JoinFunction) Field(java.lang.reflect.Field) FlatMapFunction(org.apache.samza.operators.functions.FlatMapFunction) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) InvocationTargetException(java.lang.reflect.InvocationTargetException) SinkFunction(org.apache.samza.operators.functions.SinkFunction) Config(org.apache.samza.config.Config) TestMessageStreamImplUtil(org.apache.samza.operators.TestMessageStreamImplUtil) WindowInternal(org.apache.samza.operators.windows.internal.WindowInternal) Assert.assertEquals(org.junit.Assert.assertEquals) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Mockito.mock(org.mockito.Mockito.mock) TaskContext(org.apache.samza.task.TaskContext) Set(java.util.Set) Config(org.apache.samza.config.Config) ArrayList(java.util.ArrayList) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 43 with MetricsRegistryMap

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);
}
Also used : TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) TaskContext(org.apache.samza.task.TaskContext) Config(org.apache.samza.config.Config) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 44 with MetricsRegistryMap

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);
}
Also used : StreamOperatorSpec(org.apache.samza.operators.spec.StreamOperatorSpec) Assert.assertNotSame(org.junit.Assert.assertNotSame) ArrayList(java.util.ArrayList) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) PartialJoinOperatorSpec(org.apache.samza.operators.spec.PartialJoinOperatorSpec) SinkOperatorSpec(org.apache.samza.operators.spec.SinkOperatorSpec) MessageStreamImpl(org.apache.samza.operators.MessageStreamImpl) Duration(java.time.Duration) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) Method(java.lang.reflect.Method) Before(org.junit.Before) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) WindowType(org.apache.samza.operators.windows.internal.WindowType) TaskContext(org.apache.samza.task.TaskContext) Windows(org.apache.samza.operators.windows.Windows) Iterator(java.util.Iterator) WindowOperatorSpec(org.apache.samza.operators.spec.WindowOperatorSpec) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JoinFunction(org.apache.samza.operators.functions.JoinFunction) Field(java.lang.reflect.Field) FlatMapFunction(org.apache.samza.operators.functions.FlatMapFunction) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) InvocationTargetException(java.lang.reflect.InvocationTargetException) SinkFunction(org.apache.samza.operators.functions.SinkFunction) Config(org.apache.samza.config.Config) TestMessageStreamImplUtil(org.apache.samza.operators.TestMessageStreamImplUtil) WindowInternal(org.apache.samza.operators.windows.internal.WindowInternal) Assert.assertEquals(org.junit.Assert.assertEquals) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Mockito.mock(org.mockito.Mockito.mock) TaskContext(org.apache.samza.task.TaskContext) Set(java.util.Set) Config(org.apache.samza.config.Config) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 45 with MetricsRegistryMap

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);
}
Also used : TaskContext(org.apache.samza.task.TaskContext) Config(org.apache.samza.config.Config) Matchers.anyObject(org.mockito.Matchers.anyObject) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Aggregations

MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)69 Test (org.junit.Test)27 MapConfig (org.apache.samza.config.MapConfig)24 Config (org.apache.samza.config.Config)23 HashMap (java.util.HashMap)17 JobConfig (org.apache.samza.config.JobConfig)12 Before (org.junit.Before)12 File (java.io.File)10 StorageConfig (org.apache.samza.config.StorageConfig)10 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)9 SamzaException (org.apache.samza.SamzaException)8 TaskName (org.apache.samza.container.TaskName)8 TaskModel (org.apache.samza.job.model.TaskModel)8 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)7 LocalityManager (org.apache.samza.container.LocalityManager)7 TaskContext (org.apache.samza.task.TaskContext)7 Partition (org.apache.samza.Partition)6 SystemStream (org.apache.samza.system.SystemStream)6 Map (java.util.Map)5 MetricsConfig (org.apache.samza.config.MetricsConfig)5