MetadataTotalsInterceptor extends MetadataMetricsInterceptorImpl { private int getValue(String key, AdaptrisMessage msg) { if (!msg.headersContainsKey(key)) { return 0; } return Integer.parseInt(msg.getMetadataValue(key)); } MetadataTotalsInterceptor();  MetadataTotalsInterceptor(List<String> keys); @Override synchronized void workflowStart(AdaptrisMessage inputMsg); @Override synchronized void workflowEnd(AdaptrisMessage inputMsg, final AdaptrisMessage outputMsg); List<String> getMetadataKeys(); void setMetadataKeys(List<String> l);  }
@Test public void testInterceptor() throws Exception { LifecycleHelper.init(metricsInterceptor); LifecycleHelper.start(metricsInterceptor); AdaptrisMessage message = createMessage(); assertEquals(0, metricsInterceptor.getStats().size()); submitMessage(message); assertEquals(1, metricsInterceptor.getStats().size()); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1)); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2)); assertEquals(0, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(this.getClass().getSimpleName())); assertEquals(0, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue("blah")); }
@Test public void testCreatesNewTimeSliceAfterTimeDelay() throws Exception { LifecycleHelper.init(metricsInterceptor); LifecycleHelper.start(metricsInterceptor); metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS)); AdaptrisMessage message = createMessage(); assertEquals(0, metricsInterceptor.getStats().size()); submitMessage(message); assertEquals(1, metricsInterceptor.getStats().size()); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1)); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2)); metricsInterceptor.setTimesliceDuration(new TimeInterval(1L, TimeUnit.SECONDS)); submitMessage(message); submitMessage(message); assertEquals(2, metricsInterceptor.getStats().size()); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1)); assertEquals(10, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2)); assertEquals(20, ((MetadataStatistic) metricsInterceptor.getStats().get(1)).getValue(COUNTER_1)); assertEquals(20, ((MetadataStatistic) metricsInterceptor.getStats().get(1)).getValue(COUNTER_2)); }
@Test public void testMultiThreadedSingleMetricsInterceptorInstance() throws Exception { LifecycleHelper.init(metricsInterceptor); LifecycleHelper.start(metricsInterceptor); new MetricsInserterThread(20).run(); new MetricsInserterThread(20).run(); new MetricsInserterThread(20).run(); new MetricsInserterThread(20).run(); new MetricsInserterThread(20).run(); Thread.sleep(200); assertEquals(1000, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1)); assertEquals(1000, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2)); }