@Override public void emit(Event event) { for (Emitter e : emitters) { e.emit(event); } }
@Override @LifecycleStart public void start() { emitter.start(); }
@Override @LifecycleStop public void close() throws IOException { emitter.close(); }
@Override public void flush() throws IOException { emitter.flush(); }
@Override public void flush() throws IOException { boolean fail = false; log.info("Flushing Composing Emitter."); for (Emitter e : emitters) { try { log.info("Flushing emitter %s.", e.getClass().getName()); e.flush(); } catch (IOException ex) { log.error(ex, "Failed to flush emitter [%s]", e.getClass().getName()); fail = true; } } if (fail) { throw new IOException("failed to flush one or more emitters"); } }
@Test public void failEmitMalformedEvent() throws Exception { Emitter emitter = parametrizedEmmiter("http://example.com/{keyNotSetInEvents}"); Event event = new UnitEvent("test", 1); httpClient.setGoHandler(GoHandlers.failingHandler()); try { emitter.emit(event); emitter.flush(); } catch (IllegalArgumentException e) { Assert.assertEquals( e.getMessage(), StringUtils.format( "ParametrizedUriExtractor with pattern http://example.com/{keyNotSetInEvents} requires keyNotSetInEvents to be set in event, but found %s", event.toMap()) ); } } }
@Override public void emit(Event event) { emitter.emit(event); }
@Override @LifecycleStart public void start() { log.info("Starting Composing Emitter."); for (Emitter e : emitters) { log.info("Starting emitter %s.", e.getClass().getName()); e.start(); } }
private void closeNoFlush(Emitter emitter) throws IOException { emitter.close(); }
@Test public void testFlush() throws IOException { for (Emitter emitter : childEmitters) { emitter.flush(); EasyMock.replay(emitter); } composingEmitter.flush(); }
emitter.emit(event);
@Before public void setup() { emitter = EasyMock.createMock(Emitter.class); emitter.start(); EasyMock.replay(emitter); }
@Override @LifecycleStop public void close() throws IOException { boolean fail = false; log.info("Closing Composing Emitter."); for (Emitter e : emitters) { try { log.info("Closing emitter %s.", e.getClass().getName()); e.close(); } catch (IOException ex) { log.error(ex, "Failed to close emitter [%s]", e.getClass().getName()); fail = true; } } if (fail) { throw new IOException("failed to close one or more emitters"); } }
@Override public void flush() throws IOException { emitter.flush(); }
@Test public void testEmit() { Event e = EasyMock.createMock(Event.class); for (Emitter emitter : childEmitters) { emitter.emit(e); EasyMock.replay(emitter); } composingEmitter.emit(e); }
@Test public void testGetEmitter() { ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class); EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes(); Injector injector = EasyMock.createMock(Injector.class); EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter); EasyMock.replay(config, injector); Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector); composingEmitter.start(); EasyMock.verify(config, emitter, injector); }
@Test public void testClose() throws IOException { for (Emitter emitter : childEmitters) { emitter.close(); EasyMock.replay(emitter); } composingEmitter.close(); }