EventSinkImpl implements EventSink { @Override public void queueEvent(Event event) { if (eventFilter.shouldFilter(event)) { log.debug("Filtering event {}", event); return; } if (this.modeManager.getCurrentMode() != Mode.NORMAL) { throw new IllegalStateException("Candlepin is in suspend mode"); } log.debug("Queuing event: {}", event); try { if (messageSender == null) { messageSender = new EventMessageSender(this.sessionFactory); } messageSender.queueMessage(mapper.writeValueAsString(event), event.getType(), event.getTarget()); } catch (Exception e) { log.error("Error while trying to send event", e); } } @Inject  EventSinkImpl(EventFilter eventFilter, EventFactory eventFactory,
        ObjectMapper mapper, Configuration config, ActiveMQSessionFactory sessionFactory,
        CandlepinModeManager modeManager); @Override List<QueueStatus> getQueueInfo(); @Override void queueEvent(Event event); @Override void sendEvents(); @Override void rollback(); void emitConsumerCreated(Consumer newConsumer); void emitOwnerCreated(Owner newOwner); void emitOwnerMigrated(Owner owner); void emitPoolCreated(Pool newPool); void emitExportCreated(Consumer consumer); void emitImportCreated(Owner owner); void emitActivationKeyCreated(ActivationKey key); void emitSubscriptionExpired(SubscriptionDTO subscription); @Override void emitRulesModified(Rules oldRules, Rules newRules); @Override void emitRulesDeleted(Rules rules); @Override void emitCompliance(Consumer consumer, ComplianceStatus compliance); @Override void emitCompliance(Consumer consumer, SystemPurposeComplianceStatus compliance); @Override void emitOwnerContentAccessModeChanged(Owner owner); static final String EVENT_TYPE_KEY; static final String EVENT_TARGET_KEY; }
@Test public void sendEventShouldNotFailWhenObjectMapperThrowsException() throws Exception { doThrow(new JsonGenerationException("Nothing serious!")) .when(mapper).writeValueAsString(any()); Event event = mock(Event.class); eventSinkImpl.queueEvent(event); verify(mockClientProducer, never()).send(any(ClientMessage.class)); }