public IpcSenderService(TransportFactory factory) { super(factory.getChildClass()); this.transportFactory = factory; this.pool = Executors.newFixedThreadPool(factory.getMaxThreads()); this.buffers = new HashMap<LinkedHashMap<String, String>, TransportBuffer>(); }
this.buffers.put(partitions, this.transportFactory.newTransportBuffer()); buffer = this.transportFactory.newTransportBuffer(); partitions = new LinkedHashMap<String, String>(partitions); this.buffers.put(partitions, buffer);
transport = tf.newInstance(); } catch (TransportFactoryInitException e) { hasUnrecoverableException.set(true);
transportFactory.close();
this.buffers.put(partitions, this.transportFactory.newTransportBuffer()); buffer = this.transportFactory.newTransportBuffer(); partitions = new LinkedHashMap<String, String>(partitions); this.buffers.put(partitions, buffer);
transport = tf.newInstance(); } catch (TransportFactoryInitException e) { hasUnrecoverableException.set(true);
transportFactory.close();
public IpcSenderService(TransportFactory factory) { super(factory.getChildClass()); this.transportFactory = factory; this.pool = Executors.newFixedThreadPool(factory.getMaxThreads()); this.buffers = new HashMap<LinkedHashMap<String, String>, TransportBuffer>(); }
@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()); }
@Test(expected = TransportException.class) public void testTransportOnSendFailure() throws Throwable { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; 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); IpcSenderService spyIpc = spy(handler.getIpcService()); TransportFactory tf = spy(handler.getIpcService().getTransportFactory()); BufferedTransporter mockTransport = mock(BufferedTransporter.class); doThrow(new TransportException("expected")).when(mockTransport).sendBatch(any()); when(tf.newInstance()).thenReturn(mockTransport); spyIpc.setTransportFactory(tf); handler.setIpcService(spyIpc); try { handler.handler(events, context); } catch (Exception e) { throw e.getCause().getCause(); } }