synchronized public void shutdown() { try { flush(); } catch (InterruptedException | TransportException e) { logger.warn("caught error while flushing", e); } this.pool.shutdown(); }
/** * Drains buffer and sends batch asynchronously via {@link Transport}. * * @param buffer the buffer to send. * @param partitions the partitions associated with the buffer. */ private void send(TransportBuffer buffer, LinkedHashMap<String, String> partitions) { if (buffer.isEmpty()) { return; } this.threadCounter.incrementAndGet(); TransportThread tt = new TransportThread(transportFactory, buffer, partitions, this.threadCounter, this.hasUnrecoverableException, getRuntimeStat().fork(), getErrorCountStat(), getSuccessCountStat(), getContext()); tt.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { logger.error(String.format("transport thread %s failed", th.getName()), ex); } }); this.pool.execute(tt); }
this.buffers.forEach((partition, buffer) -> send(buffer, partition)); this.buffers.clear(); this.getRuntimeStat().join();
doThrow(new TransportException("expected exception in test")).when(mockDummyTransporter) .sendBatch(any(DummyTransportBuffer.class)); IpcSenderService ipc = new IpcSenderService(tfactory); Stat errorStat = mock(Stat.class); ipc.setSuccessCountStat(successStat); ipc.setErrorCountStat(errorStat); ipc.add(mock(InternalEvent.class)); ipc.flush(); } catch (TransportException e) {
@Test(expected = TransportException.class) public void testExceptionEscalation() throws TransportException, InterruptedException { DummyTransporter mockDummyTransporter = mock(DummyTransporter.class); DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = mockDummyTransporter; doThrow(new TransportException("expected exception in test")).when(mockDummyTransporter) .sendBatch(any(DummyTransportBuffer.class)); IpcSenderService ipc = new IpcSenderService(tfactory); ipc.add(mock(InternalEvent.class)); /* * Expect shutdown to throw a TransportException when a child thread also throws as * TransportException */ ipc.flush(); }
List<Pattern> regexPatterns = source.getRegexPatterns(); this.getIpcService().setContext(context); this.getIpcService().add(ievent); } catch (TransportException e) { logger.warn("error adding event", e); this.getIpcService().flush(); } catch (TransportException e) { throw new HandlerException("encounted TransportException while shutting down ipcService", e);
@Test public void testIpcOnAddFailure() throws Throwable { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(2); events.add(new DummyEvent("foo", 0)); events.add(new DummyEvent("bar", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); TransportBuffer tbSpy1 = spy(new ArrayTransportBuffer()); TransportBuffer tbSpy2 = spy(new ArrayTransportBuffer()); doCallRealMethod().doCallRealMethod().when(tbSpy1).add(any()); doThrow(new IllegalStateException("expected")).when(tbSpy2).add(any()); IpcSenderService spyIpc = spy(handler.getIpcService()); TransportFactory tfSpy = spy(spyIpc.getTransportFactory()); when(tfSpy.newTransportBuffer()).thenReturn(tbSpy1, tbSpy2); spyIpc.setTransportFactory(tfSpy); handler.setIpcService(spyIpc); handler.handler(events, context); assertEquals(1, spyIpc.getSuccessCountStat().getValue()); }
setIpcService(new IpcSenderService(handlerResources.getTransportFactory())); sources = new ArrayList<Source>(handlerResources.getSources().values()); queueSize = config.getHandlerConfig().getQueueSize();
public void shutdown() { if (this.getIpcService() != null) { this.getIpcService().shutdown(); } }
return; } catch (IllegalStateException e) { send(buffer, partitions); } catch (IOException e) { throw new TransportException("Exception occurred while adding to buffer", e);
DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = new DummyTransporter(); IpcSenderService ipc = new IpcSenderService(tfactory); Stat errorStat = mock(Stat.class); ipc.setRuntimeStat(runtimeStat); ipc.setSuccessCountStat(successStat); ipc.setErrorCountStat(errorStat); ipc.add(mock(InternalEvent.class)); ipc.flush();
DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = mockDummyTransporter; IpcSenderService ipc = new IpcSenderService(tfactory); InternalEvent ie = new DummyEvent("" + i, 0, part1); sent1.add(ie); ipc.add(ie); InternalEvent ie = new DummyEvent("" + i, 0, part2); sent2.add(ie); ipc.add(ie); InternalEvent ie = new DummyEvent("" + i, 0, part3); sent1.add(ie); ipc.add(ie); ipc.flush();
List<Pattern> regexPatterns = source.getRegexPatterns(); this.getIpcService().setContext(context); this.getIpcService().add(ievent); } catch (TransportException e) { logger.warn("error adding event", e); this.getIpcService().flush(); } catch (TransportException e) { throw new HandlerException("encounted TransportException while shutting down ipcService", e);
setIpcService(new IpcSenderService(handlerResources.getTransportFactory())); sources = new ArrayList<Source>(handlerResources.getSources().values()); queueSize = config.getHandlerConfig().getQueueSize();
public void shutdown() { if (this.getIpcService() != null) { this.getIpcService().shutdown(); } }
return; } catch (IllegalStateException e) { send(buffer, partitions); } catch (IOException e) { throw new TransportException("Exception occurred while adding to buffer", e);
DummyTransporterFactory tfactory = new DummyTransporterFactory(); tfactory.transporter = mockDummyTransporter; IpcSenderService ipc = new IpcSenderService(tfactory); ie.setPartitions(new LinkedHashMap(0)); sent.add(ie); ipc.add(ie); ipc.flush();
/** * Drains buffer and sends batch asynchronously via {@link Transport}. * * @param buffer the buffer to send. * @param partitions the partitions associated with the buffer. */ private void send(TransportBuffer buffer, LinkedHashMap<String, String> partitions) { if (buffer.isEmpty()) { return; } this.threadCounter.incrementAndGet(); TransportThread tt = new TransportThread(transportFactory, buffer, partitions, this.threadCounter, this.hasUnrecoverableException, getRuntimeStat().fork(), getErrorCountStat(), getSuccessCountStat(), getContext()); tt.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { logger.error(String.format("transport thread %s failed", th.getName()), ex); } }); this.pool.execute(tt); }
synchronized public void shutdown() { try { flush(); } catch (InterruptedException | TransportException e) { logger.warn("caught error while flushing", e); } this.pool.shutdown(); }
this.buffers.forEach((partition, buffer) -> send(buffer, partition)); this.buffers.clear(); this.getRuntimeStat().join();