use of org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver in project samza by apache.
the class TestEventHubSystemAdmin method testStartpointResolverShouldResolveTheStartpointSpecificToCorrectOffset.
@Test
public void testStartpointResolverShouldResolveTheStartpointSpecificToCorrectOffset() {
EventHubSystemAdmin mockEventHubSystemAdmin = Mockito.mock(EventHubSystemAdmin.class);
EventHubConfig eventHubConfig = Mockito.mock(EventHubConfig.class);
SystemStreamPartition systemStreamPartition = new SystemStreamPartition("test-system", "test-stream", new Partition(0));
EventHubSamzaOffsetResolver resolver = new EventHubSamzaOffsetResolver(mockEventHubSystemAdmin, eventHubConfig);
Assert.assertEquals("100", resolver.visit(systemStreamPartition, new StartpointSpecific("100")));
}
use of org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver in project samza by apache.
the class TestEventHubSystemAdmin method testStartpointResolverShouldResolveTheStartpointTimestampToCorrectOffset.
@Test
public void testStartpointResolverShouldResolveTheStartpointTimestampToCorrectOffset() throws EventHubException {
// Initialize variables required for testing.
EventHubSystemAdmin mockEventHubSystemAdmin = Mockito.mock(EventHubSystemAdmin.class);
EventHubConfig eventHubConfig = Mockito.mock(EventHubConfig.class);
SystemStreamPartition systemStreamPartition = new SystemStreamPartition("test-system", "test-stream", new Partition(0));
String mockedOffsetToReturn = "100";
// Setup the mock variables.
EventHubClientManager mockEventHubClientManager = Mockito.mock(EventHubClientManager.class);
EventHubClient mockEventHubClient = Mockito.mock(EventHubClient.class);
PartitionReceiver mockPartitionReceiver = Mockito.mock(PartitionReceiver.class);
EventData mockEventData = Mockito.mock(EventData.class);
EventData.SystemProperties mockSystemProperties = Mockito.mock(EventData.SystemProperties.class);
// Configure the mock variables to return the appropriate values.
Mockito.when(mockEventHubSystemAdmin.getOrCreateStreamEventHubClient("test-stream")).thenReturn(mockEventHubClientManager);
Mockito.when(mockEventHubClientManager.getEventHubClient()).thenReturn(mockEventHubClient);
Mockito.when(mockEventHubClient.createReceiverSync(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(mockPartitionReceiver);
Mockito.when(mockPartitionReceiver.receiveSync(1)).thenReturn(Arrays.asList(mockEventData));
Mockito.when(mockEventData.getSystemProperties()).thenReturn(mockSystemProperties);
Mockito.when(mockSystemProperties.getOffset()).thenReturn(mockedOffsetToReturn);
// Test the Offset resolver.
EventHubSamzaOffsetResolver resolver = new EventHubSamzaOffsetResolver(mockEventHubSystemAdmin, eventHubConfig);
String resolvedOffset = resolver.visit(systemStreamPartition, new StartpointTimestamp(100L));
Assert.assertEquals(mockedOffsetToReturn, resolvedOffset);
}
use of org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver in project samza by apache.
the class TestEventHubSystemAdmin method testStartpointResolverShouldResolveTheStartpointUpcomingToCorrectOffset.
@Test
public void testStartpointResolverShouldResolveTheStartpointUpcomingToCorrectOffset() {
EventHubSystemAdmin mockEventHubSystemAdmin = Mockito.mock(EventHubSystemAdmin.class);
EventHubConfig eventHubConfig = Mockito.mock(EventHubConfig.class);
SystemStreamPartition systemStreamPartition = new SystemStreamPartition("test-system", "test-stream", new Partition(0));
EventHubSamzaOffsetResolver resolver = new EventHubSamzaOffsetResolver(mockEventHubSystemAdmin, eventHubConfig);
Assert.assertEquals(EventHubSystemConsumer.END_OF_STREAM, resolver.visit(systemStreamPartition, new StartpointUpcoming()));
}
use of org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver in project samza by apache.
the class TestEventHubSystemAdmin method testStartpointResolverShouldResolveTheStartpointOldestToCorrectOffset.
@Test
public void testStartpointResolverShouldResolveTheStartpointOldestToCorrectOffset() {
EventHubSystemAdmin mockEventHubSystemAdmin = Mockito.mock(EventHubSystemAdmin.class);
EventHubConfig eventHubConfig = Mockito.mock(EventHubConfig.class);
SystemStreamPartition systemStreamPartition = new SystemStreamPartition("test-system", "test-stream", new Partition(0));
EventHubSamzaOffsetResolver resolver = new EventHubSamzaOffsetResolver(mockEventHubSystemAdmin, eventHubConfig);
Assert.assertEquals(EventHubSystemConsumer.START_OF_STREAM, resolver.visit(systemStreamPartition, new StartpointOldest()));
}
Aggregations