use of org.apache.samza.system.eventhub.producer.SwapFirstLastByteInterceptor in project samza by apache.
the class TestEventHubSystemConsumer method testSinglePartitionConsumptionInterceptor.
@Test
public void testSinglePartitionConsumptionInterceptor() throws Exception {
String systemName = "eventhubs";
String streamName = "testStream";
// needs to be less than BLOCKING_QUEUE_SIZE
int numEvents = 10;
int partitionId = 0;
Interceptor interceptor = new SwapFirstLastByteInterceptor();
TestMetricsRegistry testMetrics = new TestMetricsRegistry();
Map<SystemStreamPartition, List<EventData>> eventData = new HashMap<>();
SystemStreamPartition ssp = new SystemStreamPartition(systemName, streamName, new Partition(partitionId));
Map<String, Interceptor> interceptors = new HashMap<>();
interceptors.put(streamName, interceptor);
// create EventData
List<EventData> singlePartitionEventData = MockEventData.generateEventData(numEvents);
eventData.put(ssp, singlePartitionEventData);
// 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), MOCK_ENTITY_1);
MapConfig config = new MapConfig(configMap);
MockEventHubClientManagerFactory eventHubClientWrapperFactory = new MockEventHubClientManagerFactory(eventData);
EventHubSystemConsumer consumer = new EventHubSystemConsumer(new EventHubConfig(config), systemName, eventHubClientWrapperFactory, interceptors, testMetrics);
consumer.register(ssp, EventHubSystemConsumer.END_OF_STREAM);
consumer.start();
// Mock received data from EventHub
eventHubClientWrapperFactory.sendToHandlers(consumer.streamPartitionHandlers);
List<IncomingMessageEnvelope> result = consumer.poll(Collections.singleton(ssp), 1000).get(ssp);
verifyEvents(result, singlePartitionEventData, interceptor);
Assert.assertEquals(testMetrics.getCounters(streamName).size(), 3);
Assert.assertEquals(testMetrics.getGauges(streamName).size(), 2);
Map<String, Counter> counters = testMetrics.getCounters(streamName).stream().collect(Collectors.toMap(Counter::getName, Function.identity()));
Assert.assertEquals(counters.get(EventHubSystemConsumer.EVENT_READ_RATE).getCount(), numEvents);
Assert.assertEquals(counters.get(EventHubSystemConsumer.READ_ERRORS).getCount(), 0);
}
Aggregations