Search in sources :

Example 1 with MockEventHubClientManagerFactory

use of org.apache.samza.system.eventhub.MockEventHubClientManagerFactory in project samza by apache.

the class TestEventHubSystemProducer method testSendingLargeMessage.

@Test
public void testSendingLargeMessage() throws Exception {
    String systemName = "eventhubs";
    String streamName = "testLMStream";
    int numEvents = 10;
    int partitionId0 = 0;
    TestMetricsRegistry testMetrics = new TestMetricsRegistry();
    Map<String, Interceptor> interceptor = new HashMap<>();
    interceptor.put(streamName, new PassThroughInterceptor());
    List<String> outgoingMessagesP0 = generateMessages(numEvents / 2);
    outgoingMessagesP0.add("1234567890123456789012345678901234567890");
    outgoingMessagesP0.addAll(generateMessages(numEvents / 2));
    // 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_SKIP_MESSAGES_LARGER_THAN, systemName), "30");
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_ENTITYPATH, streamName), EVENTHUB_ENTITY1);
    configMap.put(String.format(EventHubConfig.CONFIG_PRODUCER_PARTITION_METHOD, systemName), PartitioningMethod.PARTITION_KEY_AS_PARTITION.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())));
    // Retrieve sent data
    List<String> receivedData0 = factory.getSentData(systemName, streamName, partitionId0).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    Assert.assertEquals(outgoingMessagesP0.size(), receivedData0.size() + 1);
}
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 2 with MockEventHubClientManagerFactory

use of org.apache.samza.system.eventhub.MockEventHubClientManagerFactory in project samza by apache.

the class TestEventHubSystemProducer method testSkipLargeMessageCheck.

@Test
public void testSkipLargeMessageCheck() throws Exception {
    String systemName = "eventhubs";
    String streamName = "testLMStream";
    int numEvents = 10;
    int partitionId0 = 0;
    TestMetricsRegistry testMetrics = new TestMetricsRegistry();
    Map<String, Interceptor> interceptor = new HashMap<>();
    interceptor.put(streamName, new PassThroughInterceptor());
    List<String> outgoingMessagesP0 = generateMessages(numEvents / 2);
    outgoingMessagesP0.add("1234567890123456789012345678901234567890");
    outgoingMessagesP0.addAll(generateMessages(numEvents / 2));
    // 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_SKIP_MESSAGES_LARGER_THAN, systemName), "-1");
    configMap.put(String.format(EventHubConfig.CONFIG_STREAM_ENTITYPATH, streamName), EVENTHUB_ENTITY1);
    configMap.put(String.format(EventHubConfig.CONFIG_PRODUCER_PARTITION_METHOD, systemName), PartitioningMethod.PARTITION_KEY_AS_PARTITION.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())));
    // Retrieve sent data
    List<String> receivedData0 = factory.getSentData(systemName, streamName, partitionId0).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    Assert.assertEquals(outgoingMessagesP0.size(), receivedData0.size());
}
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 3 with MockEventHubClientManagerFactory

use of org.apache.samza.system.eventhub.MockEventHubClientManagerFactory in project samza by apache.

the class TestEventHubSystemProducer method testSendingToSpecificPartitions.

private void testSendingToSpecificPartitions(boolean perPartitionConnection) throws Exception {
    String systemName = "eventhubs";
    String streamName = "testStream";
    int numEvents = 10;
    int partitionId0 = 0;
    int partitionId1 = 1;
    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);
    configMap.put(String.format(EventHubConfig.CONFIG_PRODUCER_PARTITION_METHOD, systemName), PartitioningMethod.PARTITION_KEY_AS_PARTITION.toString());
    configMap.put(String.format(EventHubConfig.CONFIG_PER_PARTITION_CONNECTION, systemName), String.valueOf(perPartitionConnection));
    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, partitionId0).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    List<String> receivedData1 = factory.getSentData(systemName, streamName, partitionId1).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    Assert.assertTrue(outgoingMessagesP0.equals(receivedData0));
    Assert.assertTrue(outgoingMessagesP1.equals(receivedData1));
    if (perPartitionConnection) {
        Assert.assertNotEquals("perPartitionConnection=true; partitions should not share the same client", producer.perPartitionEventHubClients.get(streamName).get(0), producer.perPartitionEventHubClients.get(streamName).get(1));
    } else {
        Assert.assertEquals("perPartitionConnection=false; partitions should share the same client", producer.perPartitionEventHubClients.get(streamName).get(0), producer.perPartitionEventHubClients.get(streamName).get(1));
    }
}
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)

Example 4 with MockEventHubClientManagerFactory

use of org.apache.samza.system.eventhub.MockEventHubClientManagerFactory in project samza by apache.

the class TestEventHubSystemProducer method testSendingToSpecificPartitionsWithInterceptor.

@Test
public void testSendingToSpecificPartitionsWithInterceptor() throws Exception {
    String systemName = "eventhubs";
    String streamName = "testStream";
    int numEvents = 10;
    int partitionId0 = 0;
    int partitionId1 = 1;
    Interceptor interceptor = new SwapFirstLastByteInterceptor();
    TestMetricsRegistry testMetrics = new TestMetricsRegistry();
    Map<String, Interceptor> interceptors = new HashMap<>();
    interceptors.put(streamName, interceptor);
    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);
    configMap.put(String.format(EventHubConfig.CONFIG_PRODUCER_PARTITION_METHOD, systemName), PartitioningMethod.PARTITION_KEY_AS_PARTITION.toString());
    MapConfig config = new MapConfig(configMap);
    MockEventHubClientManagerFactory factory = new MockEventHubClientManagerFactory();
    EventHubSystemProducer producer = new EventHubSystemProducer(new EventHubConfig(config), systemName, factory, interceptors, 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, partitionId0).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    List<String> receivedData1 = factory.getSentData(systemName, streamName, partitionId1).stream().map(eventData -> new String(eventData.getBytes())).collect(Collectors.toList());
    List<String> expectedP0 = outgoingMessagesP0.stream().map(message -> new String(interceptor.intercept(message.getBytes()))).collect(Collectors.toList());
    List<String> expectedP1 = outgoingMessagesP1.stream().map(message -> new String(interceptor.intercept(message.getBytes()))).collect(Collectors.toList());
    Assert.assertTrue(expectedP0.equals(receivedData0));
    Assert.assertTrue(expectedP1.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) 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 5 with MockEventHubClientManagerFactory

use of org.apache.samza.system.eventhub.MockEventHubClientManagerFactory 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)

Aggregations

EventHubClient (com.microsoft.azure.eventhubs.EventHubClient)5 EventHubRuntimeInformation (com.microsoft.azure.eventhubs.EventHubRuntimeInformation)5 PartitionReceiver (com.microsoft.azure.eventhubs.PartitionReceiver)5 PartitionRuntimeInformation (com.microsoft.azure.eventhubs.PartitionRuntimeInformation)5 PartitionSender (com.microsoft.azure.eventhubs.PartitionSender)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 Random (java.util.Random)5 Collectors (java.util.stream.Collectors)5 MapConfig (org.apache.samza.config.MapConfig)5 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)5 SystemStream (org.apache.samza.system.SystemStream)5 EventHubConfig (org.apache.samza.system.eventhub.EventHubConfig)5 Interceptor (org.apache.samza.system.eventhub.Interceptor)5 MockEventHubClientManagerFactory (org.apache.samza.system.eventhub.MockEventHubClientManagerFactory)5 MockEventHubConfigFactory (org.apache.samza.system.eventhub.MockEventHubConfigFactory)5 TestMetricsRegistry (org.apache.samza.system.eventhub.TestMetricsRegistry)5 PassThroughInterceptor (org.apache.samza.system.eventhub.admin.PassThroughInterceptor)5