Search in sources :

Example 96 with SystemStream

use of org.apache.samza.system.SystemStream in project samza by apache.

the class TestEventHubSystemProducer method testSendingToEventHubHashing.

@Test
public void testSendingToEventHubHashing() throws Exception {
    String systemName = "eventhubs";
    String streamName = "testStream";
    int numEvents = 10;
    String partitionId0 = "124";
    String partitionId1 = "235";
    TestMetricsRegistry testMetrics = new TestMetricsRegistry();
    Map<String, Interceptor> interceptor = new HashMap<>();
    interceptor.put(streamName, new PassThroughInterceptor());
    List<String> outgoingMessagesP0 = generateMessages(numEvents);
    List<String> outgoingMessagesP1 = generateMessages(numEvents);
    // Set configs
    Map<String, String> configMap = new HashMap<>();
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_LIST, systemName), streamName);
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_NAMESPACE, streamName), EVENTHUB_NAMESPACE);
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_SAS_KEY_NAME, streamName), EVENTHUB_KEY_NAME);
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_SAS_TOKEN, streamName), EVENTHUB_KEY);
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_ENTITYPATH, streamName), EVENTHUB_ENTITY1);
    // mod 2 on the partitionid to simulate consistent hashing
    configMap.put(String.format(EventHubConfig.CONFIG_PRODUCER_PARTITION_METHOD, systemName), PartitioningMethod.EVENT_HUB_HASHING.toString());
    MapConfig config = new MapConfig(configMap);
    MockEventHubClientManagerFactory factory = new MockEventHubClientManagerFactory();
    EventHubSystemProducer producer = new EventHubSystemProducer(new EventHubConfig(config), systemName, factory, interceptor, testMetrics);
    SystemStream systemStream = new SystemStream(systemName, streamName);
    producer.register(SOURCE);
    producer.start();
    outgoingMessagesP0.forEach(message -> producer.send(SOURCE, new OutgoingMessageEnvelope(systemStream, partitionId0, null, message.getBytes())));
    outgoingMessagesP1.forEach(message -> producer.send(SOURCE, new OutgoingMessageEnvelope(systemStream, partitionId1, null, message.getBytes())));
    // Retrieve sent data
    List<String> receivedData0 = factory.getSentData(systemName, streamName, 0).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    List<String> receivedData1 = factory.getSentData(systemName, streamName, 1).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    Assert.assertTrue(outgoingMessagesP0.equals(receivedData0));
    Assert.assertTrue(outgoingMessagesP1.equals(receivedData1));
}
Also used : PartitionSender(com.microsoft.azure.eventhubs.PartitionSender) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) EventHubRuntimeInformation(com.microsoft.azure.eventhubs.EventHubRuntimeInformation) SystemStream(org.apache.samza.system.SystemStream) PartitionRuntimeInformation(com.microsoft.azure.eventhubs.PartitionRuntimeInformation) Map(java.util.Map) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PartitioningMethod(org.apache.samza.system.eventhub.producer.EventHubSystemProducer.PartitioningMethod) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) MapConfig(org.apache.samza.config.MapConfig) MockEventHubConfigFactory(org.apache.samza.system.eventhub.MockEventHubConfigFactory) PassThroughInterceptor(org.apache.samza.system.eventhub.admin.PassThroughInterceptor) PartitionReceiver(com.microsoft.azure.eventhubs.PartitionReceiver) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockEventHubClientManagerFactory(org.apache.samza.system.eventhub.MockEventHubClientManagerFactory) List(java.util.List) EventHubClient(com.microsoft.azure.eventhubs.EventHubClient) TestMetricsRegistry(org.apache.samza.system.eventhub.TestMetricsRegistry) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Interceptor(org.apache.samza.system.eventhub.Interceptor) Assert(org.junit.Assert) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream) TestMetricsRegistry(org.apache.samza.system.eventhub.TestMetricsRegistry) MockEventHubClientManagerFactory(org.apache.samza.system.eventhub.MockEventHubClientManagerFactory) MapConfig(org.apache.samza.config.MapConfig) PassThroughInterceptor(org.apache.samza.system.eventhub.admin.PassThroughInterceptor) PassThroughInterceptor(org.apache.samza.system.eventhub.admin.PassThroughInterceptor) Interceptor(org.apache.samza.system.eventhub.Interceptor) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with SystemStream

use of org.apache.samza.system.SystemStream in project samza by apache.

the class TestAzureBlobSystemProducer method createOME.

private OutgoingMessageEnvelope createOME(String streamName) {
    SystemStream systemStream = new SystemStream(SYSTEM_NAME, streamName);
    DummyPageViewEvent record = new DummyPageViewEvent();
    return new OutgoingMessageEnvelope(systemStream, record);
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Example 98 with SystemStream

use of org.apache.samza.system.SystemStream in project samza by apache.

the class TestStreamOperatorTask method testExceptionIfInputOperatorMissing.

/**
 * Tests if the appropriate SamzaException is propagated to the TaskCallback if there is no InputOperator for a given
 * SystemStream in the OperatorGraph.
 */
@Test
public void testExceptionIfInputOperatorMissing() throws NoSuchFieldException, IllegalAccessException {
    IncomingMessageEnvelope mockIme = mock(IncomingMessageEnvelope.class, RETURNS_DEEP_STUBS);
    SystemStream testSystemStream = new SystemStream("foo", "bar");
    when(mockIme.getSystemStreamPartition().getSystemStream()).thenReturn(testSystemStream);
    OperatorImplGraph mockOperatorImplGraph = mock(OperatorImplGraph.class);
    when(mockOperatorImplGraph.getInputOperator(anyObject())).thenReturn(null);
    StreamOperatorTask operatorTask = new StreamOperatorTask(mock(OperatorSpecGraph.class));
    operatorTask.setOperatorImplGraph(mockOperatorImplGraph);
    TaskCallback mockTaskCallback = mock(TaskCallback.class);
    operatorTask.processAsync(mockIme, mock(MessageCollector.class), mock(TaskCoordinator.class), mockTaskCallback);
    ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
    verify(mockTaskCallback, only()).failure(throwableCaptor.capture());
    assertEquals(throwableCaptor.getValue().getClass(), SamzaException.class);
    String expectedErrMessage = String.format("InputOperator not found in OperatorGraph for %s. The available input" + " operators are: %s. Please check SystemStream configuration for the `SystemConsumer` and/or task.inputs" + " task configuration.", testSystemStream, mockOperatorImplGraph.getAllInputOperators());
    assertEquals(throwableCaptor.getValue().getMessage(), expectedErrMessage);
}
Also used : OperatorImplGraph(org.apache.samza.operators.impl.OperatorImplGraph) OperatorSpecGraph(org.apache.samza.operators.OperatorSpecGraph) SystemStream(org.apache.samza.system.SystemStream) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) Test(org.junit.Test)

Example 99 with SystemStream

use of org.apache.samza.system.SystemStream in project samza by apache.

the class IdentityStreamTask method process.

@Override
public void process(IncomingMessageEnvelope incomingMessageEnvelope, MessageCollector messageCollector, TaskCoordinator taskCoordinator) throws Exception {
    messageCollector.send(new OutgoingMessageEnvelope(new SystemStream(outputSystem, outputTopic), incomingMessageEnvelope.getMessage()));
    processedMessageCount++;
    if (processedMessageCount == expectedMessageCount) {
        taskCoordinator.shutdown(TaskCoordinator.RequestScope.ALL_TASKS_IN_CONTAINER);
    }
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Example 100 with SystemStream

use of org.apache.samza.system.SystemStream in project samza by apache.

the class IdentityStreamTask method process.

@Override
public void process(IncomingMessageEnvelope incomingMessageEnvelope, MessageCollector messageCollector, TaskCoordinator taskCoordinator) throws Exception {
    messageCollector.send(new OutgoingMessageEnvelope(new SystemStream(outputSystem, outputTopic), incomingMessageEnvelope.getMessage()));
    processedMessageCount++;
    if (processedMessageCount == expectedMessageCount) {
        taskCoordinator.shutdown(TaskCoordinator.RequestScope.ALL_TASKS_IN_CONTAINER);
    }
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Aggregations

SystemStream (org.apache.samza.system.SystemStream)143 HashMap (java.util.HashMap)75 Test (org.junit.Test)74 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)72 Partition (org.apache.samza.Partition)58 Map (java.util.Map)55 TaskName (org.apache.samza.container.TaskName)52 MapConfig (org.apache.samza.config.MapConfig)49 Config (org.apache.samza.config.Config)46 SystemAdmin (org.apache.samza.system.SystemAdmin)42 SystemAdmins (org.apache.samza.system.SystemAdmins)40 TaskModel (org.apache.samza.job.model.TaskModel)39 Collections (java.util.Collections)37 Set (java.util.Set)37 TaskConfig (org.apache.samza.config.TaskConfig)37 Clock (org.apache.samza.util.Clock)36 File (java.io.File)35 ImmutableMap (com.google.common.collect.ImmutableMap)34 SystemStreamPartitionMetadata (org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata)33 TaskMode (org.apache.samza.job.model.TaskMode)32