MonitoringInterceptor implements Serializable { @AroundInvoke public Object intercept(InvocationContext context) throws Exception { if (DISABLED || !EJB_COUNTER.isDisplayed()) { return context.proceed(); } final String requestName = getRequestName(context); boolean systemError = false; try { EJB_COUNTER.bindContextIncludingCpu(requestName); return context.proceed(); } catch (final Error e) { systemError = true; throw e; } finally { EJB_COUNTER.addRequestForCurrentContext(systemError); } } MonitoringInterceptor(); @AroundInvoke Object intercept(InvocationContext context);  }
@Test public void testInvoke() throws Exception { final Counter ejbCounter = MonitoringProxy.getEjbCounter(); ejbCounter.clear(); final MonitoringInterceptor interceptor = new MonitoringInterceptor(); ejbCounter.setDisplayed(false); interceptor.intercept(new InvokeContext(false)); assertSame("requestsCount", 0, ejbCounter.getRequestsCount()); ejbCounter.setDisplayed(true); interceptor.intercept(new InvokeContext(false)); assertSame("requestsCount", 1, ejbCounter.getRequestsCount()); ejbCounter.clear(); try { interceptor.intercept(new InvokeContext(true)); } catch (final Error e) { assertSame("requestsCount", 1, ejbCounter.getRequestsCount()); } }
@Test public void testMonitoringTarget() throws Exception { final Counter ejbCounter = MonitoringProxy.getEjbCounter(); ejbCounter.clear(); final MonitoringTargetInterceptor interceptor = new MonitoringTargetInterceptor(); ejbCounter.setDisplayed(true); interceptor.intercept(new InvokeContext(false)); assertSame("requestsCount", 1, ejbCounter.getRequestsCount()); }
@Test public void testMonitoringCdi() throws Exception { final Counter ejbCounter = MonitoringProxy.getEjbCounter(); ejbCounter.clear(); final MonitoringCdiInterceptor interceptor = new MonitoringCdiInterceptor(); ejbCounter.setDisplayed(true); interceptor.intercept(new InvokeContext(false)); assertSame("requestsCount", 1, ejbCounter.getRequestsCount()); }
@Test public void testMonitoringAsynchronousCdi() throws Exception { final Counter ejbCounter = MonitoringProxy.getEjbCounter(); ejbCounter.clear(); final MonitoringAsynchronousCdiInterceptor interceptor = new MonitoringAsynchronousCdiInterceptor(); ejbCounter.setDisplayed(true); interceptor.intercept(new InvokeContext(false)); assertSame("requestsCount", 1, ejbCounter.getRequestsCount()); }