Search in sources :

Example 6 with AtlasKafkaMessage

use of org.apache.atlas.kafka.AtlasKafkaMessage in project incubator-atlas by apache.

the class AbstractNotificationConsumerTest method testReceive.

@Test
public void testReceive() throws Exception {
    Logger logger = mock(Logger.class);
    TestMessage testMessage1 = new TestMessage("sValue1", 99);
    TestMessage testMessage2 = new TestMessage("sValue2", 98);
    TestMessage testMessage3 = new TestMessage("sValue3", 97);
    TestMessage testMessage4 = new TestMessage("sValue4", 96);
    List jsonList = new LinkedList<>();
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage1)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage2)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage3)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage4)));
    Type versionedMessageType = new TypeToken<VersionedMessage<TestMessage>>() {
    }.getType();
    NotificationConsumer<TestMessage> consumer = new TestNotificationConsumer<>(versionedMessageType, jsonList, logger);
    List<AtlasKafkaMessage<TestMessage>> messageList = consumer.receive();
    assertFalse(messageList.isEmpty());
    assertEquals(testMessage1, messageList.get(0).getMessage());
    assertEquals(testMessage2, messageList.get(1).getMessage());
    assertEquals(testMessage3, messageList.get(2).getMessage());
    assertEquals(testMessage4, messageList.get(3).getMessage());
}
Also used : Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) Logger(org.slf4j.Logger) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 7 with AtlasKafkaMessage

use of org.apache.atlas.kafka.AtlasKafkaMessage in project incubator-atlas by apache.

the class NotificationHookConsumerTest method testCommitIsCalledWhenMessageIsProcessed.

@Test
public void testCommitIsCalledWhenMessageIsProcessed() throws AtlasServiceException, AtlasException {
    NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
    NotificationConsumer consumer = mock(NotificationConsumer.class);
    NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
    HookNotification.EntityCreateRequest message = mock(HookNotification.EntityCreateRequest.class);
    when(message.getUser()).thenReturn("user");
    when(message.getType()).thenReturn(HookNotification.HookNotificationType.ENTITY_CREATE);
    Referenceable mock = mock(Referenceable.class);
    when(message.getEntities()).thenReturn(Arrays.asList(mock));
    hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
    verify(consumer).commit(any(TopicPartition.class), anyInt());
}
Also used : HookNotification(org.apache.atlas.notification.hook.HookNotification) Referenceable(org.apache.atlas.typesystem.Referenceable) TopicPartition(org.apache.kafka.common.TopicPartition) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) Test(org.testng.annotations.Test)

Example 8 with AtlasKafkaMessage

use of org.apache.atlas.kafka.AtlasKafkaMessage in project atlas by apache.

the class NotificationHookConsumerTest method testCommitIsCalledWhenMessageIsProcessed.

@Test
public void testCommitIsCalledWhenMessageIsProcessed() throws AtlasServiceException, AtlasException {
    NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
    NotificationConsumer consumer = mock(NotificationConsumer.class);
    NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
    EntityCreateRequest message = mock(EntityCreateRequest.class);
    Referenceable mock = mock(Referenceable.class);
    when(message.getUser()).thenReturn("user");
    when(message.getType()).thenReturn(HookNotificationType.ENTITY_CREATE);
    when(message.getEntities()).thenReturn(Arrays.asList(mock));
    hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
    verify(consumer).commit(any(TopicPartition.class), anyInt());
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) TopicPartition(org.apache.kafka.common.TopicPartition) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 9 with AtlasKafkaMessage

use of org.apache.atlas.kafka.AtlasKafkaMessage in project atlas by apache.

the class NotificationHookConsumerTest method testCommitIsNotCalledEvenWhenMessageProcessingFails.

@Test
public void testCommitIsNotCalledEvenWhenMessageProcessingFails() throws AtlasServiceException, AtlasException, AtlasBaseException {
    NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
    NotificationConsumer consumer = mock(NotificationConsumer.class);
    NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
    EntityCreateRequest message = new EntityCreateRequest("user", Collections.singletonList(mock(Referenceable.class)));
    when(atlasEntityStore.createOrUpdate(any(EntityStream.class), anyBoolean())).thenThrow(new RuntimeException("Simulating exception in processing message"));
    hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
    verifyZeroInteractions(consumer);
}
Also used : EntityStream(org.apache.atlas.repository.store.graph.v1.EntityStream) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 10 with AtlasKafkaMessage

use of org.apache.atlas.kafka.AtlasKafkaMessage in project incubator-atlas by apache.

the class NotificationHookConsumerTest method testCommitIsNotCalledEvenWhenMessageProcessingFails.

@Test
public void testCommitIsNotCalledEvenWhenMessageProcessingFails() throws AtlasServiceException, AtlasException, AtlasBaseException {
    NotificationHookConsumer notificationHookConsumer = new NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, instanceConverter, typeRegistry);
    NotificationConsumer consumer = mock(NotificationConsumer.class);
    NotificationHookConsumer.HookConsumer hookConsumer = notificationHookConsumer.new HookConsumer(consumer);
    HookNotification.EntityCreateRequest message = new HookNotification.EntityCreateRequest("user", new ArrayList<Referenceable>() {

        {
            add(mock(Referenceable.class));
        }
    });
    when(atlasEntityStore.createOrUpdate(any(EntityStream.class), anyBoolean())).thenThrow(new RuntimeException("Simulating exception in processing message"));
    hookConsumer.handleMessage(new AtlasKafkaMessage(message, -1, -1));
    verifyZeroInteractions(consumer);
}
Also used : EntityStream(org.apache.atlas.repository.store.graph.v1.EntityStream) HookNotification(org.apache.atlas.notification.hook.HookNotification) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasKafkaMessage(org.apache.atlas.kafka.AtlasKafkaMessage) Test(org.testng.annotations.Test)

Aggregations

AtlasKafkaMessage (org.apache.atlas.kafka.AtlasKafkaMessage)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Logger (org.slf4j.Logger)6 Type (java.lang.reflect.Type)3 MessageVersion (org.apache.atlas.model.notification.MessageVersion)3 HookNotification (org.apache.atlas.notification.hook.HookNotification)2 EntityStream (org.apache.atlas.repository.store.graph.v1.EntityStream)2 Referenceable (org.apache.atlas.typesystem.Referenceable)2 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 AtlasNotificationMessage (org.apache.atlas.model.notification.AtlasNotificationMessage)1 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)1