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);
}
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"));
}
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();
}
}
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());
}
Aggregations