use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest 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);
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.
the class KafkaConsumerTest method assertMessagesEqual.
private void assertMessagesEqual(EntityUpdateRequest message, HookNotification consumedMessage, Referenceable entity) {
assertEquals(consumedMessage.getType(), message.getType());
assertEquals(consumedMessage.getUser(), message.getUser());
assertTrue(consumedMessage instanceof EntityUpdateRequest);
EntityUpdateRequest deserializedEntityUpdateRequest = (EntityUpdateRequest) consumedMessage;
Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
assertEquals(deserializedEntity.getId(), entity.getId());
assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
assertEquals(deserializedEntity.getTraits(), entity.getTraits());
assertEquals(deserializedEntity.getTrait(TRAIT_NAME), entity.getTrait(TRAIT_NAME));
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.
the class HookNotificationDeserializerTest method testDeserializeSplitMessage.
@Test
public void testDeserializeSplitMessage() throws Exception {
Referenceable entity = generateVeryLargeEntityWithTrait();
EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
List<String> jsonMsgList = new ArrayList<>();
AbstractNotification.createNotificationMessages(message, jsonMsgList);
assertTrue(jsonMsgList.size() > 1);
HookNotification deserializedMessage = deserialize(jsonMsgList);
assertEqualMessage(deserializedMessage, message);
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.
the class HookNotificationDeserializerTest method testDeserializeLegacyMessage.
// validate deserialization of legacy message, which doesn't use MessageVersion
@Test
public void testDeserializeLegacyMessage() throws Exception {
Referenceable entity = generateEntityWithTrait();
EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
String jsonMsg = AtlasType.toV1Json(message);
HookNotification deserializedMessage = deserialize(Collections.singletonList(jsonMsg));
assertEqualMessage(deserializedMessage, message);
}
use of org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest in project atlas by apache.
the class HookNotificationDeserializerTest method testDeserializeCompressedMessage.
@Test
public void testDeserializeCompressedMessage() throws Exception {
Referenceable entity = generateLargeEntityWithTrait();
EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
List<String> jsonMsgList = new ArrayList<>();
AbstractNotification.createNotificationMessages(message, jsonMsgList);
assertTrue(jsonMsgList.size() == 1);
String compressedMsg = jsonMsgList.get(0);
String uncompressedMsg = AtlasType.toV1Json(message);
assertTrue(compressedMsg.length() < uncompressedMsg.length(), "Compressed message (" + compressedMsg.length() + ") should be shorter than uncompressed message (" + uncompressedMsg.length() + ")");
HookNotification deserializedMessage = deserialize(jsonMsgList);
assertEqualMessage(deserializedMessage, message);
}
Aggregations