/** * This method adds an SQL String to the current thread local stack. This is needed so that * created prepared statements can be associated to the SQL Strings. * <p> * So if three times the prepared statement method is called with the same string, the stack * contains the string three times. Now the Prepared Statement is created which results in * calling the {@link #addPreparedStatement(Object, String)} method. The last added String is * taken and associated with the object. * * @param sql * The SQL String. */ protected void addSql(String sql) { sqlThreadLocalStack.push(sql); }
/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); if (enabled) { threadCpuTimeStack.push(Long.valueOf(threadMXBean.getCurrentThreadCpuTime())); } }
/** * {@inheritDoc} */ @Override public void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); }
/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); threadLast.set(Boolean.TRUE); }
/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); threadLast.set(Boolean.TRUE); }
/** * {@inheritDoc} */ @Override public void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); if (enabled) { threadCpuTimeStack.push(Long.valueOf(threadMXBean.getCurrentThreadCpuTime())); } }
/** * {@inheritDoc} */ @Override public void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); }
/** * {@inheritDoc} */ @Override public void afterConstructor(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { timeStack.push(new Double(timer.getCurrentTime())); if (enabled) { threadCpuTimeStack.push(Long.valueOf(threadMXBean.getCurrentThreadCpuTime())); } // just call the second after body method directly secondAfterBody(coreService, methodId, sensorTypeId, object, parameters, null, false, rsc); }
/** * {@inheritDoc} */ @Override public void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (skip(rsc)) { return; } InvocationSequenceData invocationSequenceData = threadLocalInvocationData.get(); if (null != invocationSequenceData) { if (methodId == invocationStartId.get().longValue()) { long count = invocationStartIdCount.get().longValue(); invocationStartIdCount.set(Long.valueOf(count - 1)); if (0 == (count - 1)) { timeStack.push(new Double(timer.getCurrentTime())); } } } }
/** * {@inheritDoc} */ @Override public void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { // no invocation marked -> skip if (!refMarker.isMarkerSet()) { return; } // remove mark from sub call refMarker.markEndCall(); if (refMarker.matchesFirst()) { // Get the timer and store it. timeStack.push(new Double(timer.getCurrentTime())); if (threadCPUTimeEnabled) { threadCpuTimeStack.push(Long.valueOf(threadMXBean.getCurrentThreadCpuTime())); } } }
@Test(dependsOnMethods = "emptyStack") public void oneValue() { Object object = mock(Object.class); threadLocalStack.push(object); Object returnValue = threadLocalStack.pop(); assertThat(returnValue, is(notNullValue())); assertThat(returnValue, is(object)); verifyZeroInteractions(object); }
@Test(dependsOnMethods = "emptyStack") public void getAndRemoveFirst() { Object objectOne = mock(Object.class); Object objectTwo = mock(Object.class); Object objectThree = mock(Object.class); threadLocalStack.push(objectOne); threadLocalStack.push(objectTwo); threadLocalStack.push(objectThree); assertThat(threadLocalStack.getAndRemoveFirst(), is(objectOne)); assertThat(threadLocalStack.getAndRemoveFirst(), is(objectTwo)); assertThat(threadLocalStack.getAndRemoveFirst(), is(objectThree)); verifyZeroInteractions(objectOne); verifyZeroInteractions(objectTwo); verifyZeroInteractions(objectThree); }
timeStack.push(new Double(timer.getCurrentTime()));
@Test(dependsOnMethods = "emptyStack", invocationCount = 10, threadPoolSize = 10) public void stackTest() { Object objectOne = mock(Object.class); Object objectTwo = mock(Object.class); Object objectThree = mock(Object.class); threadLocalStack.push(objectOne); threadLocalStack.push(objectTwo); threadLocalStack.push(objectThree); Object returnValueOne = threadLocalStack.pop(); Object returnValueTwo = threadLocalStack.pop(); Object returnValueThree = threadLocalStack.pop(); assertThat(returnValueOne, is(objectThree)); assertThat(returnValueTwo, is(objectTwo)); assertThat(returnValueThree, is(objectOne)); verifyZeroInteractions(objectOne); verifyZeroInteractions(objectTwo); verifyZeroInteractions(objectThree); }