@Test public void testGetValueTwice() { ManualClock manualClock = new ManualClock(60000L); StepCounter c = new StepCounter(MonitorConfig.builder("test").build(), manualClock); c.increment(); for (int i = 2; i < 10; ++i) { manualClock.set(i * 60000L); c.increment(); c.getValue(0); assertEquals(c.getValue(0).doubleValue(), 1 / 60.0, DELTA); } }
@Test public void testSimpleTransition() { long start = time(1); clock.set(start); StepCounter c = newInstance("c"); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 0L); clock.set(start + 2000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 1L); clock.set(start + 8000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 2L); clock.set(start + 12000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 2.0 / 10.0, DELTA); assertEquals(c.getCurrentCount(1), 1L); }
@Test public void testStepCounterIncrementAmount() { StepCounter c = new StepCounter(CONFIG); register(c); c.increment(42); assertEquals(42, registry.counter(ID).count()); }
public static StepCounter getStepCounter(String appName, String cacheName, String metric) { final String metricName = getMetricName(appName, null, metric); final String name = new StringBuilder(128).append(metricName).append((cacheName == null ? "" : "-" + cacheName + "-")).append("type=StepCounter").toString(); final StepCounter counter = (StepCounter) monitorMap.get(name); if (counter != null) return counter; writeLock.lock(); try { if (monitorMap.containsKey(name)) return (StepCounter) monitorMap.get(name); else { final StepCounter _counter = new StepCounter(getMonitorConfig(metricName, appName, cacheName, metric)); monitorMap.put(name, _counter); DefaultMonitorRegistry.getInstance().register(_counter); return _counter; } } finally { writeLock.unlock(); } }
@Test public void testIncrAfterMissedSteps() { clock.set(time(1)); StepCounter c = newInstance("foo"); c.increment(); clock.set(time(11)); assertEquals(c.getValue(1).doubleValue(), 0.1, DELTA); clock.set(time(31)); c.increment(); c.increment(); c.increment(); clock.set(time(41)); assertEquals(c.getValue(1).doubleValue(), 0.3, DELTA); } }
public long getCacheHits() { return getHitCounter().getValue().longValue(); }
/** * Get the total amount for all updates. */ public Long getTotalAmount() { return totalAmount.getCurrentCount(0); }
/** * {@inheritDoc} */ @Override public void initializeSpectator(TagList tags) { totalAmount.initializeSpectator(BasicTagList.concat(tags, STAT_TOTAL)); count.initializeSpectator(BasicTagList.concat(tags, STAT_COUNT)); max.initializeSpectator(BasicTagList.concat(tags, STAT_MAX)); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof BasicDistributionSummary)) { return false; } BasicDistributionSummary m = (BasicDistributionSummary) obj; return config.equals(m.getConfig()) && totalAmount.equals(m.totalAmount) && count.equals(m.count) && max.equals(m.max) && min.equals(m.min); } }
@Test public void testStepCounterIncrement() { StepCounter c = new StepCounter(CONFIG); register(c); c.increment(); assertEquals(1, registry.counter(ID).count()); }
/** * Erase all previous counters by creating a new loading cache with a short expiration time. */ @BeforeMethod public void setupInstance() throws Exception { LOGGER.info("Setting up DynamicCounter instance with a new cache"); DynamicCounter theInstance = getInstance(); Field counters = DynamicCounter.class.getDeclaredField("counters"); counters.setAccessible(true); ExpiringCache<MonitorConfig, Counter> newShortExpiringCache = new ExpiringCache<>(60000L, config -> new StepCounter(config, clock), 100L, clock); counters.set(theInstance, newShortExpiringCache); }
public long getBulkCalls() { return getBulkCounter().getValue().longValue(); }
/** * Get the total number of updates. */ public Long getCount() { return count.getCurrentCount(0); }
/** * {@inheritDoc} */ @Override public void initializeSpectator(TagList tags) { totalTime.initializeSpectator(BasicTagList.concat(tags, STAT_TOTAL)); count.initializeSpectator(BasicTagList.concat(tags, STAT_COUNT)); totalOfSquares.initializeSpectator(BasicTagList.concat(tags, STAT_TOTAL_SQ)); max.initializeSpectator(BasicTagList.concat(tags, STAT_MAX)); }