/** * 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); }
/** * 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); }
@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()); }