tx = config.begin(); if (propertiesFile == null || propertiesFile.length() == 0)
static public boolean isNetworkConnected() { if (network==-1) { try { ReactiveAudit.config.incSuppress(); InetAddress.getByName("www.google.com"); network = 1; } catch (UnknownHostException e) { network = 0; } finally { ReactiveAudit.config.decSuppress(); } } return network==1; } }
final String url = getPropertiesURL(); new LoadParams(this, url).commit(); Handler console = new ConsoleHandler(); logger.fine(String.format("%-30s = %s", KEY_THREAD_PATTERN, getThreadPattern())); logger.fine(String.format("%-30s = %s", KEY_THROW_EXCEPTIONS, isThrow())); logger.fine(String.format("%-30s = %s", KEY_BOOTSTRAP_MODE, getBootStrapMode())); logger.fine(String.format("%-30s = %s", KEY_BOOTSTRAP_DELAY, getBootstrapDelay())); logger.fine(String.format("%-30s = %s", KEY_FILE_LATENCY, getFileLatency())); logger.fine(String.format("%-30s = %s",KEY_NETWORK_LATENCY,getNetworkLatency())); logger.fine(String.format("%-30s = %s",KEY_CPU_LATENCY ,getCPULatency()));
protected void logLatency(Latency latency, JoinPoint thisJoinPoint, ExceptionFactory ef) throws ReactiveAuditException { if (config.isStarted() && !config.isSuppressAudit() && isReactiveThread()) { final ReactiveAudit config = ReactiveAudit.config; final ReactiveAuditException e=ef.lazyException(); config.logIfNew(latency, e); if (config.isThrow()) // LOW, MEDIUM, HIGH ? throw e; } }
void reset() { try { incSuppress(); started = false; auditStarted = false; history.purge(); stack.clear(); historyThreadName.clear(); startup(); } finally { decSuppress(); } }
public static void push() { try { ReactiveAudit.config.incSuppress(); ReactiveAudit.config.push(); ReactiveAudit.off.commit(); } finally { ReactiveAudit.config.decSuppress(); } }
@Test public void setAllParams() config.reset(); config.begin() .throwExceptions(true) .threadPattern("") .bootStrapDelay(10) .commit(); assertEquals(true, config.isThrow()); assertEquals("", config.getThreadPattern()); assertEquals(Latency.HIGH, config.getFileLatency()); assertEquals(Latency.MEDIUM, config.getNetworkLatency()); assertEquals(LOW, config.getCPULatency()); assertEquals(10, config.getBootstrapDelay()); config.begin() .throwExceptions(false) .threadPattern("abc") .bootStrapDelay(0) .commit(); assertEquals(false, config.isThrow()); assertEquals("abc", config.getThreadPattern()); assertNull(config.getFileLatency()); assertNull(config.getNetworkLatency()); assertNull(config.getCPULatency()); assertEquals(0, config.getBootstrapDelay());
assertTrue(config.logger.getHandlers()[0] instanceof ConsoleHandler); assertEquals("format", ((AuditLogFormat) config.logger.getHandlers()[0].getFormatter()).getFormat()); assertEquals(true, config.isThrow()); assertEquals("abc", config.getThreadPattern()); assertEquals(ReactiveAudit.BootStrapMode.ANNOTATION,config.getBootStrapMode()); assertEquals(10, config.getBootstrapDelay()); ReactiveAudit.config.reset(); System.clearProperty(KEY_LOG_OUTPUT); System.clearProperty(KEY_LOG_FORMAT);
@Test public void variableProperties() { LoadParams.resetAllEnv(); String url = getClass().getResource("/testEnv.properties").toExternalForm(); ReactiveAudit.config.incSuppress(); try { new LoadParams(config, url).commit(); assertEquals(config.getThreadPattern(), System.getProperty("os.name")); } finally { ReactiveAudit.config.decSuppress(); } }
config.reset(); config.begin() .latencyFile("") .commit(); config.logIfNew(LOW, new FileReactiveAuditException(LOW, "")); assertEquals(0, log[0]); log[0] = 0; config.logIfNew(MEDIUM, new FileReactiveAuditException(MEDIUM, "")); assertEquals(0, log[0]); log[0] = 0; config.logIfNew(HIGH, new FileReactiveAuditException(HIGH, "")); assertEquals(0, log[0]); config.begin() .latencyFile("LOW") .commit(); config.logIfNew(LOW, new FileReactiveAuditException(LOW, "")); assertEquals(1, log[0]); log[0] = 0; config.logIfNew(MEDIUM, new FileReactiveAuditException(MEDIUM, "")); assertEquals(1, log[0]); log[0] = 0; config.logIfNew(HIGH, new FileReactiveAuditException(HIGH, "")); assertEquals(1, log[0]); config.begin() .latencyFile("MEDIUM")
@Override public void run() { assertTrue(ReactiveAudit.config.isSuppressAudit()); assertEquals(1, ReactiveAudit.config.getSuppress()); } };
@Test public void currentThread_nothing() { config.begin().threadPattern("(?!)").commit(); assertFalse(config.isThreadNameMatch(Thread.currentThread().getName())); }
@Before("execution(@com.octo.reactive.audit.lib.TolerateLatency * *(..) )") public void beforeAssume(JoinPoint thisJoinPoint) throws ReactiveAuditException { ReactiveAudit.config.incSuppress(); }
@After("execution(@com.octo.reactive.audit.lib.TolerateLatency * *(..))") public void afterAssume(JoinPoint thisJoinPoint) throws ReactiveAuditException { ReactiveAudit.config.decSuppress(); } }
@Test @TolerateLatency("Direct call") public void directCall() { assertTrue(ReactiveAudit.config.isSuppressAudit()); }
@TolerateLatency @Override public void run() { assertTrue(ReactiveAudit.config.isSuppressAudit()); assertEquals(2, ReactiveAudit.config.getSuppress()); } };
@Before("execution(* java.util.logger.Logger.*(..))") public void beforeLogger(JoinPoint thisJoinPoint) { ReactiveAudit.config.incSuppress(); }
@After("execution(* java.util.logger.Logger.*(..))") public void afterLogger(JoinPoint thisJoinPoint) throws ReactiveAuditException { ReactiveAudit.config.decSuppress(); } }