Search in sources :

Example 1 with EventHubSystemFactory

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

the class TestEventHubSystemAdmin method testOffsetComparison.

@Test
public void testOffsetComparison() {
    EventHubSystemFactory eventHubSystemFactory = new EventHubSystemFactory();
    EventHubSystemAdmin eventHubSystemAdmin = (EventHubSystemAdmin) eventHubSystemFactory.getAdmin(SYSTEM_NAME, MockEventHubConfigFactory.getEventHubConfig(EventHubSystemProducer.PartitioningMethod.EVENT_HUB_HASHING));
    Assert.assertEquals(-1, eventHubSystemAdmin.offsetComparator("100", "200").intValue());
    Assert.assertEquals(0, eventHubSystemAdmin.offsetComparator("150", "150").intValue());
    Assert.assertEquals(1, eventHubSystemAdmin.offsetComparator("200", "100").intValue());
    Assert.assertNull(eventHubSystemAdmin.offsetComparator("1", "a"));
    Assert.assertNull(eventHubSystemAdmin.offsetComparator("100", EventHubSystemConsumer.END_OF_STREAM));
    Assert.assertNull(eventHubSystemAdmin.offsetComparator(EventHubSystemConsumer.END_OF_STREAM, EventHubSystemConsumer.END_OF_STREAM));
}
Also used : EventHubSystemFactory(org.apache.samza.system.eventhub.EventHubSystemFactory) Test(org.junit.Test)

Example 2 with EventHubSystemFactory

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

the class ITestEventHubSystemConsumer method testSinglePartitionConsumptionHappyPath.

@Test
public void testSinglePartitionConsumptionHappyPath() throws Exception {
    int partitionId = 0;
    TestMetricsRegistry testMetrics = new TestMetricsRegistry();
    SystemStreamPartition ssp = new SystemStreamPartition(SYSTEM_NAME, STREAM_NAME1, new Partition(partitionId));
    Config eventHubConfig = createEventHubConfig();
    EventHubSystemFactory factory = new EventHubSystemFactory();
    SystemConsumer consumer = factory.getConsumer(SYSTEM_NAME, eventHubConfig, testMetrics);
    consumer.register(ssp, EventHubSystemConsumer.START_OF_STREAM);
    consumer.start();
    int numEvents = 0;
    int numRetries = 20;
    while (numRetries-- > 0) {
        List<IncomingMessageEnvelope> result = consumer.poll(Collections.singleton(ssp), 2000).get(ssp);
        numEvents = result == null ? 0 : result.size();
        if (numEvents > 0) {
            EventHubIncomingMessageEnvelope eventData = (EventHubIncomingMessageEnvelope) result.get(0);
            System.out.println("System properties: " + eventData.getEventData().getSystemProperties());
            System.out.println("Key: " + new String((byte[]) eventData.getKey()));
            System.out.println("Message: " + new String((byte[]) eventData.getMessage()));
        }
        System.out.println("Retries left: " + numRetries);
    }
    Assert.assertTrue(numEvents > 0);
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) EventHubSystemFactory(org.apache.samza.system.eventhub.EventHubSystemFactory) SystemConsumer(org.apache.samza.system.SystemConsumer) Config(org.apache.samza.config.Config) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) TestMetricsRegistry(org.apache.samza.system.eventhub.TestMetricsRegistry) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 3 with EventHubSystemFactory

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

the class TestEventHubSystemAdmin method testGetStreamMetadata.

@Ignore("Integration Test")
@Test
public void testGetStreamMetadata() {
    EventHubSystemFactory eventHubSystemFactory = new EventHubSystemFactory();
    SystemAdmin eventHubSystemAdmin = eventHubSystemFactory.getAdmin(SYSTEM_NAME, MockEventHubConfigFactory.getEventHubConfig(EventHubSystemProducer.PartitioningMethod.EVENT_HUB_HASHING));
    Set<String> streams = new HashSet<>();
    streams.add(STREAM_NAME1);
    streams.add(STREAM_NAME2);
    Map<String, SystemStreamMetadata> metadataMap = eventHubSystemAdmin.getSystemStreamMetadata(streams);
    for (String stream : streams) {
        Assert.assertTrue(metadataMap.containsKey(stream));
        Assert.assertEquals(stream, metadataMap.get(stream).getStreamName());
        Assert.assertNotNull(metadataMap.get(stream).getSystemStreamPartitionMetadata());
        Map<Partition, SystemStreamMetadata.SystemStreamPartitionMetadata> partitionMetadataMap = metadataMap.get(stream).getSystemStreamPartitionMetadata();
        Assert.assertTrue(partitionMetadataMap.size() >= MIN_EVENTHUB_ENTITY_PARTITION);
        Assert.assertTrue(partitionMetadataMap.size() <= MAX_EVENTHUB_ENTITY_PARTITION);
        partitionMetadataMap.forEach((partition, metadata) -> {
            Assert.assertEquals(EventHubSystemConsumer.START_OF_STREAM, metadata.getOldestOffset());
            Assert.assertNotSame(EventHubSystemConsumer.END_OF_STREAM, metadata.getNewestOffset());
            String expectedUpcomingOffset = String.valueOf(Long.parseLong(metadata.getNewestOffset()) + 1);
            Assert.assertEquals(expectedUpcomingOffset, metadata.getUpcomingOffset());
        });
    }
}
Also used : EventHubSystemFactory(org.apache.samza.system.eventhub.EventHubSystemFactory) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) SystemAdmin(org.apache.samza.system.SystemAdmin) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

EventHubSystemFactory (org.apache.samza.system.eventhub.EventHubSystemFactory)3 Test (org.junit.Test)3 Partition (org.apache.samza.Partition)2 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)2 HashSet (java.util.HashSet)1 Config (org.apache.samza.config.Config)1 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)1 SystemAdmin (org.apache.samza.system.SystemAdmin)1 SystemConsumer (org.apache.samza.system.SystemConsumer)1 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)1 TestMetricsRegistry (org.apache.samza.system.eventhub.TestMetricsRegistry)1 Ignore (org.junit.Ignore)1