Search in sources :

Example 6 with MessageVersion

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

the class AtlasNotificationMessageTest method testCompareVersion.

@Test
public void testCompareVersion() throws Exception {
    MessageVersion version1 = new MessageVersion("1.0.0");
    MessageVersion version2 = new MessageVersion("2.0.0");
    MessageVersion version3 = new MessageVersion("0.5.0");
    AtlasNotificationMessage<String> atlasNotificationMessage = new AtlasNotificationMessage<>(version1, "a");
    assertTrue(atlasNotificationMessage.compareVersion(version1) == 0);
    assertTrue(atlasNotificationMessage.compareVersion(version2) < 0);
    assertTrue(atlasNotificationMessage.compareVersion(version3) > 0);
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) AtlasNotificationMessage(org.apache.atlas.model.notification.AtlasNotificationMessage) Test(org.testng.annotations.Test)

Example 7 with MessageVersion

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

the class KafkaConsumerTest method testNextVersionMismatch.

@Test
public void testNextVersionMismatch() throws Exception {
    Referenceable entity = getEntity(TRAIT_NAME);
    EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
    String json = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("2.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);
    kafkaConsumer.assign(Collections.singletonList(tp));
    when(kafkaConsumer.poll(100L)).thenReturn(records);
    AtlasKafkaConsumer consumer = new AtlasKafkaConsumer(NotificationType.HOOK, kafkaConsumer, false, 100L);
    try {
        List<AtlasKafkaMessage<HookNotification>> messageList = consumer.receive();
        assertTrue(messageList.size() > 0);
        HookNotification consumedMessage = messageList.get(0).getMessage();
        fail("Expected VersionMismatchException!");
    } catch (IncompatibleVersionException e) {
        e.printStackTrace();
    }
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) IncompatibleVersionException(org.apache.atlas.notification.IncompatibleVersionException) 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 8 with MessageVersion

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

the class MessageVersionTest method testHashCode.

@Test
public void testHashCode() throws Exception {
    MessageVersion version1 = new MessageVersion("1.0.0");
    MessageVersion version2 = new MessageVersion("1.0.0");
    MessageVersion version3 = new MessageVersion("1");
    assertEquals(version1.hashCode(), version2.hashCode());
    assertEquals(version1.hashCode(), version3.hashCode());
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) Test(org.testng.annotations.Test)

Example 9 with MessageVersion

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

the class MessageVersionTest method testEquals.

@Test
public void testEquals() throws Exception {
    MessageVersion version1 = new MessageVersion("1.0.0");
    MessageVersion version2 = new MessageVersion("1.0.0");
    MessageVersion version3 = new MessageVersion("2.0.0");
    MessageVersion version4 = new MessageVersion("1");
    MessageVersion version5 = new MessageVersion("1.5");
    MessageVersion version6 = new MessageVersion("1.0.5");
    assertTrue(version1.equals(version2));
    assertTrue(version2.equals(version1));
    assertFalse(version1.equals(version3));
    assertFalse(version3.equals(version1));
    assertTrue(version1.equals(version4));
    assertTrue(version4.equals(version1));
    assertFalse(version1.equals(version5));
    assertFalse(version5.equals(version1));
    assertFalse(version1.equals(version6));
    assertFalse(version6.equals(version1));
}
Also used : MessageVersion(org.apache.atlas.model.notification.MessageVersion) Test(org.testng.annotations.Test)

Example 10 with MessageVersion

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

the class MessageVersionTest method testCompareTo.

@Test
public void testCompareTo() throws Exception {
    MessageVersion version1 = new MessageVersion("1.0.0");
    MessageVersion version2 = new MessageVersion("1.0.0");
    MessageVersion version3 = new MessageVersion("2.0.0");
    MessageVersion version4 = new MessageVersion("1");
    MessageVersion version5 = new MessageVersion("1.5");
    MessageVersion version6 = new MessageVersion("1.0.5");
    assertTrue(version1.compareTo(version2) == 0);
    assertTrue(version2.compareTo(version1) == 0);
    assertTrue(version1.compareTo(version3) < 0);
    assertTrue(version3.compareTo(version1) > 0);
    assertTrue(version1.compareTo(version4) == 0);
    assertTrue(version4.compareTo(version1) == 0);
    assertTrue(version1.compareTo(version5) < 0);
    assertTrue(version5.compareTo(version1) > 0);
    assertTrue(version1.compareTo(version6) < 0);
    assertTrue(version6.compareTo(version1) > 0);
}
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