@Test public void testSerializationException() throws HandlerException, SerializationException { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); Serializer serSpy = spy(handler.ser.getSerializer()); doThrow(new DeserializationException("")).when(serSpy).serialize(any()); handler.ser.setSerializer(serSpy); handler.handler(events, context); assertEquals(1, handler.ser.getErrorCountStat().getValue()); }
public String serialize(Object obj) throws SerializationException { this.getRuntimeStat().start(); String serialized; try { serialized = this.serializer.serialize(obj); } catch (Exception e) { this.getErrorCountStat().increment(); throw new SerializationException(e); } finally { this.getRuntimeStat().stop(); } this.getSuccessCountStat().increment(); return serialized; }
public String serialize(Object obj) throws SerializationException { this.getRuntimeStat().start(); String serialized; try { serialized = this.serializer.serialize(obj); } catch (Exception e) { this.getErrorCountStat().increment(); throw new SerializationException(e); } finally { this.getRuntimeStat().stop(); } this.getSuccessCountStat().increment(); return serialized; }