/** * Removes the last added sql from the thread local stack. We don't need the String object here. */ protected void removeSql() { sqlThreadLocalStack.pop(); }
@Test(dependsOnMethods = "emptyStack", expectedExceptions = { NoSuchElementException.class }) public void noSuchElement() { threadLocalStack.pop(); }
@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); }
/** * {@inheritDoc} */ @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { // NOCHK:8-params double endTime = timeStack.pop().doubleValue(); double startTime = timeStack.pop().doubleValue(); if (threadLast.get().booleanValue()) { threadLast.set(Boolean.FALSE); double duration = endTime - startTime; String sql = parameters[0].toString(); Timestamp timestamp = new Timestamp(System.currentTimeMillis() - Math.round(duration)); long platformId = platformManager.getPlatformId(); SqlStatementData sqlData = new SqlStatementData(timestamp, platformId, sensorTypeId, methodId); sqlData.setPreparedStatement(false); sqlData.setSql(strConstraint.crop(sql)); sqlData.setDuration(duration); sqlData.calculateMin(duration); sqlData.calculateMax(duration); sqlData.setCount(1L); // populate the connection meta data. connectionMetaDataStorage.populate(sqlData, statementReflectionCache.getConnection(object.getClass(), object)); coreService.addDefaultData(sqlData); } }
@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); }
double endTime = timeStack.pop().doubleValue(); double startTime = timeStack.pop().doubleValue(); double duration = endTime - startTime; long cpuEndTime = threadCpuTimeStack.pop().longValue(); long cpuStartTime = threadCpuTimeStack.pop().longValue(); cpuDuration = (cpuEndTime - cpuStartTime) / 1000000.0d;
double endTime = timeStack.pop().doubleValue(); double startTime = timeStack.pop().doubleValue(); double duration = endTime - startTime; long cpuEndTime = threadCpuTimeStack.pop().longValue(); long cpuStartTime = threadCpuTimeStack.pop().longValue(); cpuDuration = (cpuEndTime - cpuStartTime) / 1000000.0d;