Search in sources :

Example 1 with MessageVersion

use of org.apache.atlas.model.notification.MessageVersion in project atlas by apache.

the class KafkaConsumerTest method testReceive.

@Test
public void testReceive() throws Exception {
    Referenceable entity = getEntity(TRAIT_NAME);
    EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
    String json = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), message));
    TopicPartition tp = new TopicPartition("ATLAS_HOOK", 0);
    List<ConsumerRecord<String, String>> klist = Collections.singletonList(new ConsumerRecord<>("ATLAS_HOOK", 0, 0L, "mykey", json));
    Map mp = Collections.singletonMap(tp, klist);
    ConsumerRecords records = new ConsumerRecords(mp);
    when(kafkaConsumer.poll(100)).thenReturn(records);
    kafkaConsumer.assign(Collections.singletonList(tp));
    AtlasKafkaConsumer consumer = new AtlasKafkaConsumer(NotificationType.HOOK, kafkaConsumer, false, 100L);
    List<AtlasKafkaMessage<HookNotification>> messageList = consumer.receive();
    assertTrue(messageList.size() > 0);
    HookNotification consumedMessage = messageList.get(0).getMessage();
    assertMessagesEqual(message, consumedMessage, entity);
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest) HookNotification(org.apache.atlas.model.notification.HookNotification) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) TopicPartition(org.apache.kafka.common.TopicPartition) Map(java.util.Map) Test(org.testng.annotations.Test) EntityNotificationTest(org.apache.atlas.notification.entity.EntityNotificationTest)

Example 2 with MessageVersion

use of org.apache.atlas.model.notification.MessageVersion in project 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(AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage1)));
    jsonList.add(AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage2)));
    jsonList.add(AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage3)));
    jsonList.add(AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage4)));
    NotificationConsumer<TestMessage> consumer = new TestNotificationConsumer(jsonList, logger);
    List<AtlasKafkaMessage<TestMessage>> messageList = consumer.receive();
    assertFalse(messageList.isEmpty());
    assertEquals(messageList.get(0).getMessage(), testMessage1);
    assertEquals(messageList.get(1).getMessage(), testMessage2);
    assertEquals(messageList.get(2).getMessage(), testMessage3);
    assertEquals(messageList.get(3).getMessage(), testMessage4);
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) AtlasNotificationMessage(org.apache.atlas.model.notification.AtlasNotificationMessage) 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 3 with MessageVersion

use of org.apache.atlas.model.notification.MessageVersion in project atlas by apache.

the class AbstractNotificationConsumerTest method testNextForwardVersion.

@Test
public void testNextForwardVersion() throws Exception {
    Logger logger = mock(Logger.class);
    TestMessage testMessage1 = new TestMessage("sValue1", 99);
    TestMessage testMessage2 = new TestMessage("sValue2", 98);
    List jsonList = new LinkedList<>();
    String json1 = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage1));
    String json2 = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("2.0.0"), testMessage2));
    jsonList.add(json1);
    jsonList.add(json2);
    NotificationConsumer<TestMessage> consumer = new TestNotificationConsumer(jsonList, logger);
    try {
        List<AtlasKafkaMessage<TestMessage>> messageList = consumer.receive();
        messageList.get(1).getMessage();
        fail("Expected VersionMismatchException!");
    } catch (IncompatibleVersionException e) {
    }
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) 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 4 with MessageVersion

use of org.apache.atlas.model.notification.MessageVersion in project atlas by apache.

the class AbstractNotificationConsumerTest method testNextBackVersion.

@Test
public void testNextBackVersion() 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<>();
    String json1 = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("1.0.0"), testMessage1));
    String json2 = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("0.0.5"), testMessage2));
    String json3 = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("0.5.0"), testMessage3));
    String json4 = AtlasType.toV1Json(testMessage4);
    jsonList.add(json1);
    jsonList.add(json2);
    jsonList.add(json3);
    jsonList.add(json4);
    NotificationConsumer<TestMessage> consumer = new TestNotificationConsumer(jsonList, logger);
    List<AtlasKafkaMessage<TestMessage>> messageList = consumer.receive();
    assertEquals(new TestMessage("sValue1", 99), messageList.get(0).getMessage());
    assertEquals(new TestMessage("sValue2", 98), messageList.get(1).getMessage());
    assertEquals(new TestMessage("sValue3", 97), messageList.get(2).getMessage());
    assertEquals(new TestMessage("sValue4", 96), messageList.get(3).getMessage());
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) 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 5 with MessageVersion

use of org.apache.atlas.model.notification.MessageVersion in project atlas by apache.

the class MessageVersionTest method testGetVersionParts.

@Test
public void testGetVersionParts() throws Exception {
    MessageVersion version = new MessageVersion("1.0.0");
    assertTrue(Arrays.equals(new Integer[] { 1 }, version.getVersionParts()));
    version = new MessageVersion("1.0");
    assertTrue(Arrays.equals(new Integer[] { 1 }, version.getVersionParts()));
    version = new MessageVersion("1");
    assertTrue(Arrays.equals(new Integer[] { 1 }, version.getVersionParts()));
    version = new MessageVersion("1.0.2");
    assertTrue(Arrays.equals(new Integer[] { 1, 0, 2 }, version.getVersionParts()));
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) Test(org.testng.annotations.Test)

Aggregations

MessageVersion (org.apache.atlas.model.notification.MessageVersion)12 Test (org.testng.annotations.Test)12 AtlasNotificationMessage (org.apache.atlas.model.notification.AtlasNotificationMessage)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 AtlasKafkaMessage (org.apache.atlas.kafka.AtlasKafkaMessage)3 Logger (org.slf4j.Logger)3 Map (java.util.Map)2 HookNotification (org.apache.atlas.model.notification.HookNotification)2 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)2 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)2 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 IncompatibleVersionException (org.apache.atlas.notification.IncompatibleVersionException)1