@Override public double getDouble(String name) { return getDouble(nameToDescriptor(name)); }
@Override public LongSupplier setLongSupplier(final StatisticDescriptor descriptor, final LongSupplier supplier) { return setLongSupplier(getLongId(descriptor), supplier); }
@Override public double getDouble(int id) { if (isOpen()) { return _getDouble(id); } else { return 0.0; } }
@Override public DoubleSupplier setDoubleSupplier(final StatisticDescriptor descriptor, final DoubleSupplier supplier) { return setDoubleSupplier(getDoubleId(descriptor), supplier); }
@Test public void invokeLongSuppliersShouldUpdateStats() { LongSupplier supplier1 = mock(LongSupplier.class); when(supplier1.getAsLong()).thenReturn(23L); stats.setLongSupplier(4, supplier1); assertEquals(0, stats.invokeSuppliers()); verify(supplier1).getAsLong(); assertEquals(23L, stats.getLong(4)); }
@Test public void invokeDoubleSuppliersShouldUpdateStats() { DoubleSupplier supplier1 = mock(DoubleSupplier.class); when(supplier1.getAsDouble()).thenReturn(23.3); stats.setDoubleSupplier(4, supplier1); assertEquals(0, stats.invokeSuppliers()); verify(supplier1).getAsDouble(); assertEquals(23.3, stats.getDouble(4), 0.1f); }
@Test public void invokeIntSuppliersShouldUpdateStats() { IntSupplier supplier1 = mock(IntSupplier.class); when(supplier1.getAsInt()).thenReturn(23); stats.setIntSupplier(4, supplier1); assertEquals(0, stats.invokeSuppliers()); verify(supplier1).getAsInt(); assertEquals(23, stats.getInt(4)); }
@Test public void invokeSuppliersShouldCatchSupplierErrorsAndReturnCount() { IntSupplier supplier1 = mock(IntSupplier.class); when(supplier1.getAsInt()).thenThrow(NullPointerException.class); stats.setIntSupplier(4, supplier1); assertEquals(1, stats.invokeSuppliers()); verify(supplier1).getAsInt(); }
private void sampleCallbacks() { if (cancelCriterion.isCancelInProgress()) { executor.shutdown(); } int errors = 0; int suppliers = 0; long start = System.nanoTime(); try { for (Statistics stats : statisticsManager.getStatsList()) { StatisticsImpl statistics = (StatisticsImpl) stats; errors += statistics.invokeSuppliers(); suppliers += statistics.getSupplierCount(); } } catch (VirtualMachineError e) { SystemFailure.initiateFailure(e); } catch (Throwable throwable) { logger.error("Error invoking statistic suppliers", throwable); } finally { long end = System.nanoTime(); statSamplerStats.incSampleCallbackDuration(TimeUnit.NANOSECONDS.toMillis(end - start)); statSamplerStats.incSampleCallbackErrors(errors); statSamplerStats.setSampleCallbacks(suppliers); } }
@Test public void getSupplierCountShouldReturnCorrectCount() { IntSupplier supplier1 = mock(IntSupplier.class); stats.setIntSupplier(4, supplier1); assertEquals(1, stats.getSupplierCount()); }
/** * Returns the value of the specified statistic descriptor. */ private Number _get(StatisticDescriptorImpl stat) { switch (stat.getTypeCode()) { case StatisticDescriptorImpl.INT: return Integer.valueOf(_getInt(stat.getId())); case StatisticDescriptorImpl.LONG: return Long.valueOf(_getLong(stat.getId())); case StatisticDescriptorImpl.DOUBLE: return Double.valueOf(_getDouble(stat.getId())); default: throw new RuntimeException( String.format("unexpected stat descriptor type code: %s", Byte.valueOf(stat.getTypeCode()))); } }
@Override public IntSupplier setIntSupplier(final StatisticDescriptor descriptor, final IntSupplier supplier) { return setIntSupplier(getIntId(descriptor), supplier); }
@Override public double getDouble(StatisticDescriptor descriptor) { return getDouble(getDoubleId(descriptor)); }
@Override public LongSupplier setLongSupplier(final String name, final LongSupplier supplier) { return setLongSupplier(nameToId(name), supplier); }
@Override public int getInt(String name) { return getInt(nameToDescriptor(name)); }
@Override public DoubleSupplier setDoubleSupplier(final String name, final DoubleSupplier supplier) { return setDoubleSupplier(nameToId(name), supplier); }
@Override public IntSupplier setIntSupplier(final String name, final IntSupplier supplier) { return setIntSupplier(nameToId(name), supplier); }
@Override public long getLong(String name) { return getLong(nameToDescriptor(name)); }