use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class ApplicationRepository method getEventTypes.
public List<EventType> getEventTypes(UUID appId) {
String query = "FROM EventType WHERE application.id = :appId";
Application app = entityManager.find(Application.class, appId);
if (app == null) {
throw new NotFoundException();
} else {
List<EventType> eventTypes = entityManager.createQuery(query, EventType.class).setParameter("appId", appId).getResultList();
for (EventType eventType : eventTypes) {
eventType.filterOutApplication();
}
return eventTypes;
}
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testValidPayloadWithMessageId.
@Test
void testValidPayloadWithMessageId() {
EventType eventType = mockGetEventTypeAndCreateEvent();
Action action = buildValidAction();
String payload = serializeAction(action);
UUID messageId = UUID.randomUUID();
Message<String> message = buildMessageWithId(messageId.toString().getBytes(UTF_8), payload);
inMemoryConnector.source(INGRESS_CHANNEL).send(message);
micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_VALID_COUNTER_NAME, 1);
assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, DUPLICATE_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME, MESSAGE_ID_MISSING_COUNTER_NAME);
verifyExactlyOneProcessing(eventType, payload, action);
verify(kafkaMessageDeduplicator, times(1)).registerMessageId(messageId);
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testNullMessageId.
@Test
void testNullMessageId() {
EventType eventType = mockGetEventTypeAndCreateEvent();
Action action = buildValidAction();
String payload = serializeAction(action);
Message<String> message = buildMessageWithId(null, payload);
inMemoryConnector.source(INGRESS_CHANNEL).send(message);
micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_INVALID_COUNTER_NAME, 1);
assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, DUPLICATE_COUNTER_NAME, MESSAGE_ID_VALID_COUNTER_NAME, MESSAGE_ID_MISSING_COUNTER_NAME);
verifyExactlyOneProcessing(eventType, payload, action);
verify(kafkaMessageDeduplicator, times(1)).registerMessageId(null);
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testValidPayloadWithoutMessageId.
@Test
void testValidPayloadWithoutMessageId() {
EventType eventType = mockGetEventTypeAndCreateEvent();
Action action = buildValidAction();
String payload = serializeAction(action);
inMemoryConnector.source(INGRESS_CHANNEL).send(payload);
micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_MISSING_COUNTER_NAME, 1);
assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, DUPLICATE_COUNTER_NAME, MESSAGE_ID_VALID_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME);
verifyExactlyOneProcessing(eventType, payload, action);
verify(kafkaMessageDeduplicator, times(1)).registerMessageId(null);
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testDuplicatePayload.
@Test
void testDuplicatePayload() {
EventType eventType = mockGetEventTypeAndCreateEvent();
Action action = buildValidAction();
String payload = serializeAction(action);
UUID messageId = UUID.randomUUID();
Message<String> message = buildMessageWithId(messageId.toString().getBytes(UTF_8), payload);
inMemoryConnector.source(INGRESS_CHANNEL).send(message);
inMemoryConnector.source(INGRESS_CHANNEL).send(message);
micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 2);
assertEquals(2L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_VALID_COUNTER_NAME, 2);
micrometerAssertionHelper.assertCounterIncrement(DUPLICATE_COUNTER_NAME, 1);
assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME, MESSAGE_ID_MISSING_COUNTER_NAME);
verifyExactlyOneProcessing(eventType, payload, action);
verify(kafkaMessageDeduplicator, times(1)).registerMessageId(messageId);
}
Aggregations