Search in sources :

Example 6 with EntityUpdateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.

the class HookNotificationDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    Referenceable entity = generateEntityWithTrait();
    EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
    List<String> jsonMsgList = new ArrayList<>();
    AbstractNotification.createNotificationMessages(message, jsonMsgList);
    HookNotification deserializedMessage = deserialize(jsonMsgList);
    assertEqualMessage(deserializedMessage, message);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ArrayList(java.util.ArrayList) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest) Test(org.testng.annotations.Test) EntityNotificationTest(org.apache.atlas.notification.entity.EntityNotificationTest)

Example 7 with EntityUpdateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.

the class NotificationHookConsumerIT method testUpdateEntityFullUpdate.

@Test
public void testUpdateEntityFullUpdate() throws Exception {
    final Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
    final String dbName = "db" + randomString();
    entity.set(NAME, dbName);
    entity.set(DESCRIPTION, randomString());
    entity.set(QUALIFIED_NAME, dbName);
    entity.set(CLUSTER_NAME, randomString());
    atlasClientV1.createEntity(entity);
    final Referenceable newEntity = new Referenceable(DATABASE_TYPE_BUILTIN);
    newEntity.set(NAME, randomString());
    newEntity.set(DESCRIPTION, randomString());
    newEntity.set("owner", randomString());
    newEntity.set(QUALIFIED_NAME, dbName);
    newEntity.set(CLUSTER_NAME, randomString());
    // updating unique attribute
    sendHookMessage(new EntityUpdateRequest(TEST_USER, newEntity));
    waitFor(MAX_WAIT_TIME, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
            return results.size() == 1;
        }
    });
    Referenceable actualEntity = atlasClientV1.getEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName);
    assertEquals(actualEntity.get(DESCRIPTION), newEntity.get(DESCRIPTION));
    assertEquals(actualEntity.get("owner"), newEntity.get("owner"));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest) Test(org.testng.annotations.Test)

Example 8 with EntityUpdateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest 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 9 with EntityUpdateRequest

use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.

the class HookNotificationDeserializerTest method assertEqualMessage.

private void assertEqualMessage(HookNotification deserializedMessage, EntityUpdateRequest message) throws Exception {
    assertNotNull(deserializedMessage);
    assertEquals(deserializedMessage.getType(), message.getType());
    assertEquals(deserializedMessage.getUser(), message.getUser());
    assertTrue(deserializedMessage instanceof EntityUpdateRequest);
    EntityUpdateRequest deserializedEntityUpdateRequest = (EntityUpdateRequest) deserializedMessage;
    Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
    Referenceable entity = message.getEntities().get(0);
    String traitName = entity.getTraitNames().get(0);
    assertEquals(deserializedEntity.getId(), entity.getId());
    assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
    assertEquals(deserializedEntity.getTraits(), entity.getTraits());
    assertEquals(deserializedEntity.getTrait(traitName).hashCode(), entity.getTrait(traitName).hashCode());
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityUpdateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 Test (org.testng.annotations.Test)7 HookNotification (org.apache.atlas.model.notification.HookNotification)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)6 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 MessageVersion (org.apache.atlas.model.notification.MessageVersion)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IncompatibleVersionException (org.apache.atlas.notification.IncompatibleVersionException)1