Search in sources :

Example 11 with HookNotification

use of org.apache.atlas.model.notification.HookNotification 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 12 with HookNotification

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

the class HookNotificationTest method testEntityPartialUpdateV2SerDe.

@Test
public void testEntityPartialUpdateV2SerDe() throws Exception {
    AtlasEntity entity1 = new AtlasEntity("sometype");
    AtlasEntity entity2 = new AtlasEntity("newtype");
    AtlasEntity entity3 = new AtlasEntity("othertype");
    setAttributes(entity1);
    entity1.setAttribute("complex", new AtlasObjectId(entity3.getGuid(), entity3.getTypeName()));
    AtlasEntityWithExtInfo entity = new AtlasEntityWithExtInfo(entity1);
    entity.addReferredEntity(entity2);
    entity.addReferredEntity(entity3);
    String user = "user";
    EntityPartialUpdateRequestV2 request = new EntityPartialUpdateRequestV2(user, AtlasTypeUtil.getAtlasObjectId(entity1), entity);
    String notificationJson = AtlasJson.toJson(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_PARTIAL_UPDATE_V2);
    assertEquals(actualNotification.getUser(), user);
    EntityPartialUpdateRequestV2 updateRequest = (EntityPartialUpdateRequestV2) actualNotification;
    assertEquals(updateRequest.getEntity().getReferredEntities().size(), 2);
    AtlasEntity actualEntity1 = updateRequest.getEntity().getEntity();
    AtlasEntity actualEntity2 = updateRequest.getEntity().getReferredEntity(entity2.getGuid());
    AtlasEntity actualEntity3 = updateRequest.getEntity().getReferredEntity(entity3.getGuid());
    Map actualComplexAttr = (Map) actualEntity1.getAttribute("complex");
    assertEquals(actualEntity1.getGuid(), entity1.getGuid());
    assertEquals(actualEntity1.getTypeName(), entity1.getTypeName());
    assertAttributes(actualEntity1);
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_GUID), entity3.getGuid());
    assertEquals(actualComplexAttr.get(AtlasObjectId.KEY_TYPENAME), entity3.getTypeName());
    assertEquals(actualEntity2.getGuid(), entity2.getGuid());
    assertEquals(actualEntity2.getTypeName(), entity2.getTypeName());
    assertEquals(actualEntity3.getGuid(), entity3.getGuid());
    assertEquals(actualEntity3.getTypeName(), entity3.getTypeName());
}
Also used : EntityPartialUpdateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2) HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 13 with HookNotification

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

the class HookNotificationTest method testNewMessageSerDe.

@Test
public void testNewMessageSerDe() throws Exception {
    Referenceable entity1 = new Referenceable("sometype");
    Referenceable entity2 = new Referenceable("newtype");
    entity1.set("attr", "value");
    entity1.set("complex", new Referenceable("othertype"));
    String user = "user";
    EntityCreateRequest request = new EntityCreateRequest(user, entity1, entity2);
    String notificationJson = AtlasType.toV1Json(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_CREATE);
    assertEquals(actualNotification.getUser(), user);
    assertTrue(actualNotification instanceof EntityCreateRequest);
    EntityCreateRequest createRequest = (EntityCreateRequest) actualNotification;
    assertEquals(createRequest.getEntities().size(), 2);
    Referenceable actualEntity1 = createRequest.getEntities().get(0);
    assertEquals(actualEntity1.getTypeName(), "sometype");
    assertEquals(((Referenceable) actualEntity1.get("complex")).getTypeName(), "othertype");
    assertEquals(createRequest.getEntities().get(1).getTypeName(), "newtype");
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest) Test(org.testng.annotations.Test)

Example 14 with HookNotification

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

the class HookNotificationTest method testEntityDeleteV2SerDe.

@Test
public void testEntityDeleteV2SerDe() throws Exception {
    AtlasEntity entity1 = new AtlasEntity("sometype");
    AtlasEntity entity2 = new AtlasEntity("newtype");
    AtlasEntity entity3 = new AtlasEntity("othertype");
    List<AtlasObjectId> objectsToDelete = new ArrayList<>();
    objectsToDelete.add(new AtlasObjectId(entity1.getGuid(), entity1.getTypeName()));
    objectsToDelete.add(new AtlasObjectId(entity2.getGuid(), entity2.getTypeName()));
    objectsToDelete.add(new AtlasObjectId(entity3.getGuid(), entity3.getTypeName()));
    String user = "user";
    EntityDeleteRequestV2 request = new EntityDeleteRequestV2(user, objectsToDelete);
    String notificationJson = AtlasJson.toJson(request);
    HookNotification actualNotification = deserializer.deserialize(notificationJson);
    assertEquals(actualNotification.getType(), HookNotificationType.ENTITY_DELETE_V2);
    assertEquals(actualNotification.getUser(), user);
    EntityDeleteRequestV2 deleteRequest = (EntityDeleteRequestV2) actualNotification;
    assertEquals(deleteRequest.getEntities().size(), objectsToDelete.size());
    assertEquals(deleteRequest.getEntities(), objectsToDelete);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityDeleteRequestV2(org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2) Test(org.testng.annotations.Test)

Example 15 with HookNotification

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

the class AtlasHookTest method testNotifyEntitiesDoesNotHangOnException.

@Test(timeOut = 10000)
public void testNotifyEntitiesDoesNotHangOnException() throws Exception {
    List<HookNotification> hookNotifications = new ArrayList<>();
    doThrow(new NotificationException(new Exception())).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotifications);
    AtlasHook.notifyEntitiesInternal(hookNotifications, 0, notificationInterface, false, failedMessagesLogger);
// if we've reached here, the method finished OK.
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) NotificationException(org.apache.atlas.notification.NotificationException) NotificationException(org.apache.atlas.notification.NotificationException) Test(org.testng.annotations.Test)

Aggregations

HookNotification (org.apache.atlas.model.notification.HookNotification)31 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)13 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)9 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)9 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)8 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)6 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)6 Map (java.util.Map)5 EntityCreateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)5 NotificationException (org.apache.atlas.notification.NotificationException)5 EntityUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2)4 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)3 EntityDeleteRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2)3 EntityPartialUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2)3 MessageVersion (org.apache.atlas.model.notification.MessageVersion)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2