final StackTraceElement[] stack = getStackTrace(); int pos = 0; for (final StackTraceElement traceElement : stack) setStackTrace(newStack); final StackTraceElement[] stack = getStackTrace(); final int newSize = Math.min(stack.length, LIMIT_STACK_SIZE_IF_DEBUG); final StackTraceElement[] newStack = new StackTraceElement[newSize]; System.arraycopy(stack, 0, newStack, 0, newSize); setStackTrace(newStack);
/** * Create an {@link AssertionError} with {@link Latency}, thread name and message. * * @param latency The latency for this exception. * @param message The message associated with this exception. */ protected ReactiveAuditException(Latency latency, String message) { super(message); this.threadName = Thread.currentThread().getName(); this.latency = latency; updateStackTraceElements(); }
baseLatency = latencyCPU; if (baseLatency == null) return; if (e.getLatency().ordinal() < baseLatency.ordinal()) return; if (!history.isAlreadyLogged(e.getStackTrace())) logger.log(level, e.getMessage(), e);
@SuppressWarnings("PointlessBooleanExpression") @Test public void testPurgeStackTrace() throws NoSuchFieldException, IllegalAccessException { // If debug mode, test nothing Field field = ReactiveAuditException.class.getDeclaredField("debug"); field.setAccessible(true); if (((Boolean) field.get(null)) == true) return; TestTools.strict.commit(); try { latencyCall1(); fail(); } catch (ReactiveAuditException e) { StackTraceElement[] stack = e.getStackTrace(); for (StackTraceElement traceElement : stack) { assertFalse((traceElement.getClassName().startsWith(auditPackageName) && !traceElement.getClassName().endsWith("Test"))); // For inner unit test } } } }
@Test(expected = ReactiveAuditException.class) public void invokeWithLatencyMedium() { TestTools.strict.commit(); class Test { @WithLatency(Latency.MEDIUM) public void directCall() { fail(); } } try { new Test().directCall(); } catch (ReactiveAuditException e) { assertEquals(MEDIUM, e.getLatency()); throw e; } }
@Test(expected = ReactiveAuditException.class) public void invokeWithLatencyLow() { TestTools.strict.commit(); class Test { @WithLatency(LOW) public void directCall() { fail(); } } try { new Test().directCall(); } catch (ReactiveAuditException e) { assertEquals(LOW, e.getLatency()); throw e; } }
final StackTraceElement[] stack = getStackTrace(); int pos = 0; for (final StackTraceElement traceElement : stack) setStackTrace(newStack); final StackTraceElement[] stack = getStackTrace(); final int newSize = Math.min(stack.length, LIMIT_STACK_SIZE_IF_DEBUG); final StackTraceElement[] newStack = new StackTraceElement[newSize]; System.arraycopy(stack, 0, newStack, 0, newSize); setStackTrace(newStack);
/** * Create an {@link AssertionError} with {@link Latency}, thread name and message. * * @param latency The latency for this exception. * @param message The message associated with this exception. */ protected ReactiveAuditException(Latency latency, String message) { super(message); this.threadName = Thread.currentThread().getName(); this.latency = latency; updateStackTraceElements(); }
@Test(expected = ReactiveAuditException.class) public void invokeWithLatencyHigh() { TestTools.strict.commit(); class Test { @WithLatency(Latency.HIGH) public void directCall() { fail(); } } try { new Test().directCall(); } catch (ReactiveAuditException e) { assertEquals(HIGH, e.getLatency()); throw e; } } }
/** * Create an {@link AssertionError} with {@link Latency}, thread name and formatted message. * * @param latency The latency for this exception. * @param format The format message associated with this exception. * @param args The arguments to generate the message with the format. */ protected ReactiveAuditException(Latency latency, String format, Object... args) { super(String.format(format, args)); this.threadName = Thread.currentThread().getName(); updateStackTraceElements(); }
@Test(expected = ReactiveAuditException.class) public void invokeWithLatencyHigh() { TestTools.strict.commit(); class Test { @WithLatency(Latency.HIGH) public void directCall() { fail(); } } try { new Test().directCall(); } catch (ReactiveAuditException e) { assertEquals(HIGH, e.getLatency()); throw e; } } }
/** * Create an {@link AssertionError} with {@link Latency}, thread name and formatted message. * * @param latency The latency for this exception. * @param format The format message associated with this exception. * @param args The arguments to generate the message with the format. */ protected ReactiveAuditException(Latency latency, String format, Object... args) { super(String.format(format, args)); this.threadName = Thread.currentThread().getName(); updateStackTraceElements(); }