FunctionStatsImpl implements FunctionStats { @Override public void endFunctionExecutionWithException(long startTime, boolean haveResult) { long elapsedNanos = clock.getAsLong() - startTime; failureTimer.record(elapsedNanos, NANOSECONDS); statistics.incInt(functionExecutionsRunningId, -1); statistics.incInt(functionExecutionExceptionsId, 1); if (haveResult) { statistics.incInt(functionExecutionsHasResultRunningId, -1); } aggregateStatistics.endFunctionExecutionWithException(haveResult); } FunctionStatsImpl(String functionId, MeterRegistry meterRegistry, Statistics statistics,
      FunctionServiceStats functionServiceStats); @VisibleForTesting  FunctionStatsImpl(String functionId, MeterRegistry meterRegistry, Statistics statistics,
      FunctionServiceStats aggregateStatistics, long clockResult,
      boolean timeStatisticsEnabledResult); @VisibleForTesting  FunctionStatsImpl(String functionId, MeterRegistry meterRegistry, Statistics statistics,
      FunctionServiceStats aggregateStatistics, long clockResult,
      boolean timeStatisticsEnabledResult, Timer successTimerResult, Timer registerFailureResult); private  FunctionStatsImpl(String functionId, MeterRegistry meterRegistry, Statistics statistics,
      FunctionServiceStats aggregateStatistics, LongSupplier clock,
      BooleanSupplier timeStatisticsEnabled,
      BiFunction<String, MeterRegistry, Timer> registerSuccessTimerFunction,
      BiFunction<String, MeterRegistry, Timer> registerFailureTimerFunction); @Override void close(); @Override boolean isClosed(); @Override int getFunctionExecutionsCompleted(); @Override int getFunctionExecutionsRunning(); @Override void incResultsReturned(); @Override int getResultsReceived(); @Override void incResultsReceived(); @Override int getFunctionExecutionCalls(); @Override long startFunctionExecution(boolean haveResult); @Override void endFunctionExecution(long startTime, boolean haveResult); @Override void endFunctionExecutionWithException(long startTime, boolean haveResult); @Override @VisibleForTesting Statistics getStatistics(); @Override @VisibleForTesting MeterRegistry getMeterRegistry(); static StatisticsType getStatisticsType();  }
@Test public void endFunctionExecutionWithException_incrementsFailureTimerCount() { FunctionStats functionStats = new FunctionStatsImpl(FUNCTION_ID, meterRegistry, statistics, functionServiceStats); functionStats.endFunctionExecutionWithException(0, false); assertThat(failureTimer().count()) .as("Failure timer count") .isEqualTo(1); }
@Test public void endFunctionExecutionWithException_incrementsFailureTimerTotalTime() { long endTime = 5; FunctionStats functionStats = new FunctionStatsImpl(FUNCTION_ID, meterRegistry, statistics, functionServiceStats, endTime, false); long startTime = 0; functionStats.endFunctionExecutionWithException(startTime, false); long elapsedNanos = endTime - startTime; assertThat(failureTimer().totalTime(NANOSECONDS)) .as("Failure timer total time") .isEqualTo(elapsedNanos); }
@Test public void endFunctionExecutionWithException_incrementsAggregateStats() { FunctionStats functionStats = new FunctionStatsImpl(FUNCTION_ID, meterRegistry, statistics, functionServiceStats); boolean haveResult = true; functionStats.endFunctionExecutionWithException(0, haveResult); verify(functionServiceStats) .endFunctionExecutionWithException(haveResult); }