MessageMetricsInterceptorByMetadata extends MessageMetricsInterceptorImpl { public void init() throws CoreException { try { Args.notNull(getMetadataElement(), "metadataElement"); super.init(); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } } MessageMetricsInterceptorByMetadata();  MessageMetricsInterceptorByMetadata(MetadataElement element); void init(); KeyValuePair getMetadataElement(); void setMetadataElement(KeyValuePair m); @Override synchronized void workflowStart(AdaptrisMessage inputMsg); @Override synchronized void workflowEnd(AdaptrisMessage inputMsg, AdaptrisMessage outputMsg);  }
@Test public void testInterceptor() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); AdaptrisMessage message = createMessage(true); assertEquals(0, interceptor.getStats().size()); submitMessage(message); assertEquals(1, interceptor.getStats().size()); assertEquals(1, ((MessageStatistic) interceptor.getStats().get(0)).getTotalMessageCount()); }
@Test public void testInterceptor_NoMatch() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); AdaptrisMessage message = createMessage(false); assertEquals(0, interceptor.getStats().size()); submitMessage(message); assertEquals(0, interceptor.getStats().size()); }
@Test public void testInterceptor_WithException() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); AdaptrisMessage message = createMessage(true); message.getObjectHeaders().put(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception()); assertEquals(0, interceptor.getStats().size()); submitMessage(message); assertEquals(1, interceptor.getStats().size()); assertEquals(1, ((MessageStatistic) interceptor.getStats().get(0)).getTotalMessageCount()); assertEquals(1, ((MessageStatistic) interceptor.getStats().get(0)).getTotalMessageErrorCount()); }
@Test public void testCreatesNewTimeSliceAfterTimeDelay() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); AdaptrisMessage message = createMessage(true); interceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS)); assertEquals(0, interceptor.getStats().size()); submitMessage(message); interceptor.setTimesliceDuration(new TimeInterval(1L, TimeUnit.SECONDS)); assertEquals(1, interceptor.getStats().size()); submitMessage(message); submitMessage(message); assertEquals(2, interceptor.getStats().size()); assertEquals(1, ((MessageStatistic) interceptor.getStats().get(0)).getTotalMessageCount()); assertEquals(2, ((MessageStatistic) interceptor.getStats().get(1)).getTotalMessageCount()); }
@Test public void testDoesNotCreateMoreHistoryThanSpecified() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); AdaptrisMessage message = createMessage(true); interceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS)); assertEquals(0, interceptor.getStats().size()); submitMessage(message); assertEquals(1, interceptor.getStats().size()); submitMessage(message); assertEquals(2, interceptor.getStats().size()); submitMessage(message); assertEquals(2, interceptor.getStats().size()); }
@Test public void testMultiThreadedSingleMetricsInterceptorInstance() throws Exception { LifecycleHelper.init(interceptor); LifecycleHelper.start(interceptor); interceptor.setTimesliceDuration(new TimeInterval(2L, TimeUnit.SECONDS)); new MetricsInserterThread(20).run(); new MetricsInserterThread(10).run(); new MetricsInserterThread(30).run(); new MetricsInserterThread(50).run(); new MetricsInserterThread(20).run(); Thread.sleep(300); assertEquals(130, ((MessageStatistic) interceptor.getStats().get(0)).getTotalMessageCount()); }