Search in sources :

Example 1 with EventHubSamzaOffsetResolver

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")));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) EventHubSamzaOffsetResolver(org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) StartpointSpecific(org.apache.samza.startpoint.StartpointSpecific) Test(org.junit.Test)

Example 2 with EventHubSamzaOffsetResolver

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);
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) PartitionReceiver(com.microsoft.azure.eventhubs.PartitionReceiver) EventHubClient(com.microsoft.azure.eventhubs.EventHubClient) EventHubClientManager(org.apache.samza.system.eventhub.EventHubClientManager) StartpointTimestamp(org.apache.samza.startpoint.StartpointTimestamp) EventHubSamzaOffsetResolver(org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver) EventData(com.microsoft.azure.eventhubs.EventData) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 3 with EventHubSamzaOffsetResolver

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()));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) StartpointUpcoming(org.apache.samza.startpoint.StartpointUpcoming) EventHubSamzaOffsetResolver(org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 4 with EventHubSamzaOffsetResolver

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()));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) EventHubConfig(org.apache.samza.system.eventhub.EventHubConfig) EventHubSamzaOffsetResolver(org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver) StartpointOldest(org.apache.samza.startpoint.StartpointOldest) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Aggregations

Partition (org.apache.samza.Partition)4 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)4 EventHubConfig (org.apache.samza.system.eventhub.EventHubConfig)4 EventHubSamzaOffsetResolver (org.apache.samza.system.eventhub.admin.EventHubSystemAdmin.EventHubSamzaOffsetResolver)4 Test (org.junit.Test)4 EventData (com.microsoft.azure.eventhubs.EventData)1 EventHubClient (com.microsoft.azure.eventhubs.EventHubClient)1 PartitionReceiver (com.microsoft.azure.eventhubs.PartitionReceiver)1 StartpointOldest (org.apache.samza.startpoint.StartpointOldest)1 StartpointSpecific (org.apache.samza.startpoint.StartpointSpecific)1 StartpointTimestamp (org.apache.samza.startpoint.StartpointTimestamp)1 StartpointUpcoming (org.apache.samza.startpoint.StartpointUpcoming)1 EventHubClientManager (org.apache.samza.system.eventhub.EventHubClientManager)1