Search in sources :

Example 6 with NotificationException

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");
    }
}
Also used : Producer(org.apache.kafka.clients.producer.Producer) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) NotificationException(org.apache.atlas.notification.NotificationException) Future(java.util.concurrent.Future) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 7 with NotificationException

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");
}
Also used : HookNotification(org.apache.atlas.notification.hook.HookNotification) ArrayList(java.util.ArrayList) NotificationException(org.apache.atlas.notification.NotificationException) NotificationException(org.apache.atlas.notification.NotificationException) Test(org.testng.annotations.Test)

Example 8 with NotificationException

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.
}
Also used : ArrayList(java.util.ArrayList) NotificationException(org.apache.atlas.notification.NotificationException) NotificationException(org.apache.atlas.notification.NotificationException) Test(org.testng.annotations.Test)

Aggregations

NotificationException (org.apache.atlas.notification.NotificationException)8 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)6 Future (java.util.concurrent.Future)3 HookNotification (org.apache.atlas.notification.hook.HookNotification)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3 Properties (java.util.Properties)2 Producer (org.apache.kafka.clients.producer.Producer)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 AtlasException (org.apache.atlas.AtlasException)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1