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));
}
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);
}
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());
});
}
}
Aggregations