use of org.apache.atlas.notification.NotificationException in project incubator-atlas by apache.
the class KafkaNotificationMockTest method shouldThrowExceptionIfProducerFails.
@Test
@SuppressWarnings("unchecked")
public void shouldThrowExceptionIfProducerFails() throws NotificationException, ExecutionException, InterruptedException {
Properties configProperties = mock(Properties.class);
KafkaNotification kafkaNotification = new KafkaNotification(configProperties);
Producer producer = mock(Producer.class);
String topicName = kafkaNotification.getTopicName(NotificationInterface.NotificationType.HOOK);
String message = "This is a test message";
Future returnValue = mock(Future.class);
when(returnValue.get()).thenThrow(new RuntimeException("Simulating exception"));
ProducerRecord expectedRecord = new ProducerRecord(topicName, message);
when(producer.send(expectedRecord)).thenReturn(returnValue);
try {
kafkaNotification.sendInternalToProducer(producer, NotificationInterface.NotificationType.HOOK, new String[] { message });
fail("Should have thrown NotificationException");
} catch (NotificationException e) {
assertEquals(e.getFailedMessages().size(), 1);
assertEquals(e.getFailedMessages().get(0), "This is a test message");
}
}
use of org.apache.atlas.notification.NotificationException in project incubator-atlas by apache.
the class AtlasHookTest method testAllFailedMessagesAreLogged.
@Test
public void testAllFailedMessagesAreLogged() throws NotificationException {
List<HookNotification.HookNotificationMessage> hookNotificationMessages = new ArrayList<HookNotification.HookNotificationMessage>() {
{
add(new HookNotification.EntityCreateRequest("user"));
}
};
doThrow(new NotificationException(new Exception(), Arrays.asList("test message1", "test message2"))).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotificationMessages);
AtlasHook.notifyEntitiesInternal(hookNotificationMessages, 2, notificationInterface, true, failedMessagesLogger);
verify(failedMessagesLogger, times(1)).log("test message1");
verify(failedMessagesLogger, times(1)).log("test message2");
}
use of org.apache.atlas.notification.NotificationException in project incubator-atlas by apache.
the class AtlasHookTest method testNotifyEntitiesDoesNotHangOnException.
@Test(timeOut = 10000)
public void testNotifyEntitiesDoesNotHangOnException() throws Exception {
List<HookNotification.HookNotificationMessage> hookNotificationMessages = new ArrayList<>();
doThrow(new NotificationException(new Exception())).when(notificationInterface).send(NotificationInterface.NotificationType.HOOK, hookNotificationMessages);
AtlasHook.notifyEntitiesInternal(hookNotificationMessages, 0, notificationInterface, false, failedMessagesLogger);
// if we've reached here, the method finished OK.
}
Aggregations