Refine search
/** * stop timer */ public void finished(){ this.timer.stop(); }
/** * Returns a timing {@link TimerContext}, which measures an elapsed time in nanoseconds. * * @return a new {@link TimerContext} */ public TimerContext time() { return new TimerContext(this, clock); }
@Override public Object call() throws Exception { // TODO perhaps this could be pushed down further into CountProducer Impl? // - this would leave generic submitter class for ( Count c : counts ) { logger.info( "found count {}", c ); } timer.stop(); return true; } } );
@Test public void testIndex() { clientTest = Mockito.spy(new MyClient()); //this is a field, which we mock IndexTimer indexTimerSpy = Mockito.spy(new IndexTimer()); //TimerContext we mock too TimerContext timerContextSpy = Mockito.spy(new TimerContext()); //IndexTimer.time returns our timer context Mockito.doReturn(timerContextSpy).when(indexTimerSpy).time(); //set indexTimer clientTest.setIndexTimer(indexTimerSpy); //calls method under test clientTest.index(null); //verify calls of methods Mockito.verify(indexTimerSpy).time(); Mockito.verify(timerContextSpy).stop(); // Prevent/stub logic when calling super.index(request) //Mockito.doNothing().when((YourSuperclass)clientTest).index(); }
@Override public Object call() throws Exception { cassandraCounterStore.save( counts ); timer.stop(); return true; } } );
@Override public void stop(final Object token, final String tagName, final boolean success) { final TimerContext timerContext = (TimerContext) token; timerContext.stop(); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { final Timer timer = timers.get(invocation.getMethod().getName()); final TimerContext timerCtx = timer != null ? timer.time() : null; try { return invocation.proceed(); } finally { if (timerCtx != null) { timerCtx.stop(); } } }
/** * Stops request timer. * * @param requestTimerContext * timer context */ public void stopTimer(TimerContext requestTimerContext) { requestTimerContext.stop(); } }
/** * Stop timer. */ public void stopTimer() { context.stop(); } }
//this creates or returns the metrics, basically every metric is only created once and registered in a registry private final Timer timerCanMakeHold = Metrics.newTimer(MyClass.class, "METRICNAME", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); final TimerContext timerContex = timerCanMakeHold.time(); try{ doSomeWork()//this is what you are timing }finally{ timerContex.stop(); }
private static ResultSet executeAndTimeQuery(PreparedStatement preparedStatement) throws SQLException { TimerContext timerContext = queryTimer.time(); int remainingRetries = insertRetries; while (remainingRetries > 0) { try { return preparedStatement.executeQuery(); } catch (SQLTransactionRollbackException tre) { remainingRetries--; continue; } catch (SQLException e) { errorCounter.inc(); throw e; } finally { timerContext.stop(); } } throw new SQLException("Failed insert after retries"); }
@Override public void stop(final Object token, final String tagName, final boolean success) { final TimerContext timerContext = (TimerContext) token; timerContext.stop(); }
private void stopTimer(TimerContext context) { if (enableTimers && context != null) { context.stop(); } }