@Override public double actualCount() { return get().actualCount(); }
@Test public void testDoubleCounterAdd() { DoubleCounter c = new DoubleCounter(CONFIG, Clock.WALL); register(c); c.increment(0.2); assertEquals(0.2, registry.counter(ID).actualCount()); }
@Test public void testDownload() throws Exception { // Dummy download myFileSystem.downloadFile(Paths.get(""), Paths.get(configuration.getDataFileLocation()), 2); // Verify the success metric for download is incremented. Assert.assertEquals(1, (int) backupMetrics.getValidDownloads().actualCount()); }
@Test public void testDynamicTimerRecordSeconds() { DynamicTimer.record(CONFIG, 42); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
Assert.assertNotEquals(size, (int) backupMetrics.getValidUploads().actualCount());
@Test public void testBasicTimerRecordMillis() { BasicTimer d = new BasicTimer(CONFIG); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testBasicTimerRecordSeconds() { BasicTimer d = new BasicTimer(CONFIG, TimeUnit.SECONDS); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "SECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-9, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-9 * 42e-9, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-9, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testAsyncDownload() throws Exception { // Testing single async download. Future<Path> future = myFileSystem.asyncDownloadFile( Paths.get(""), Paths.get(configuration.getDataFileLocation()), 2); future.get(); // 1. Verify the success metric for download is incremented. Assert.assertEquals(1, (int) backupMetrics.getValidDownloads().actualCount()); // 2. Verify the queue size is '0' after success. Assert.assertEquals(0, myFileSystem.getDownloadTasksQueued()); }
@Test public void testUpload() throws Exception { Collection<File> files = generateFiles(1, 1, 1); // Dummy upload with compressed size. for (File file : files) { myFileSystem.uploadFile( file.toPath(), Paths.get(file.toString() + ".tmp"), getDummyPath(file.toPath()), 2, true); // Verify the success metric for upload is incremented. Assert.assertEquals(1, (int) backupMetrics.getValidUploads().actualCount()); // Verify delete of the original file if flag provided. Assert.assertFalse(file.exists()); break; } }
@Test public void testContextualTimerRecordMillis() { TagList context = BasicTagList.of("a", "1"); ContextualTimer d = new ContextualTimer(CONFIG, () -> context, BasicTimer::new); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS").withTag("a", "1"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testAsyncUploadBulk() throws Exception { // Testing the queue feature works. // 1. Give 1000 dummy files to upload. File upload takes some random time to upload Collection<File> files = generateFiles(1, 1, 20); List<Future<Path>> futures = new ArrayList<>(); for (File file : files) { futures.add( myFileSystem.asyncUploadFile( file.toPath(), Paths.get(file.toString() + ".tmp"), getDummyPath(file.toPath()), 2, true)); } // Verify all the work is finished. for (Future future : futures) { future.get(); } // 2. Success metric is incremented correctly Assert.assertEquals(files.size(), (int) backupMetrics.getValidUploads().actualCount()); // 3. The task queue is empty after upload is finished. Assert.assertEquals(0, myFileSystem.getUploadTasksQueued()); }
@Test public void testAsyncDownloadBulk() throws Exception { // Testing the queue feature works. // 1. Give 1000 dummy files to download. File download takes some random time to download. int totalFiles = 1000; List<Future<Path>> futureList = new ArrayList<>(); for (int i = 0; i < totalFiles; i++) futureList.add( myFileSystem.asyncDownloadFile( Paths.get("" + i), Paths.get(configuration.getDataFileLocation()), 2)); // Ensure processing is finished. for (Future future1 : futureList) { future1.get(); } // 2. Success metric is incremented correctly -> exactly 1000 times. Assert.assertEquals(totalFiles, (int) backupMetrics.getValidDownloads().actualCount()); // 3. The task queue is empty after download is finished. Assert.assertEquals(0, myFileSystem.getDownloadTasksQueued()); }
@Test public void testAsyncUpload() throws Exception { // Testing single async upload. Collection<File> files = generateFiles(1, 1, 1); for (File file : files) { myFileSystem .asyncUploadFile( file.toPath(), Paths.get(file.toString() + ".tmp"), getDummyPath(file.toPath()), 2, true) .get(); // 1. Verify the success metric for upload is incremented. Assert.assertEquals(1, (int) backupMetrics.getValidUploads().actualCount()); // 2. The task queue is empty after upload is finished. Assert.assertEquals(0, myFileSystem.getUploadTasksQueued()); break; } }
@Test public void testBucketTimerRecordMillis() { BucketConfig bc = new BucketConfig.Builder() .withBuckets(new long[] {10L, 50L}) .withTimeUnit(TimeUnit.MILLISECONDS) .build(); BucketTimer d = new BucketTimer(CONFIG, bc); register(d); d.record(42, TimeUnit.MILLISECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count).withTag("servo.bucket", "bucket=50ms")).count()); assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testStatsTimerRecordMillis() { StatsConfig sc = new StatsConfig.Builder() .withPercentiles(new double[] {50.0, 95.0}) .withPublishCount(true) .withPublishMax(true) .withPublishMean(true) .withSampleSize(10) .build(); StatsTimer d = new StatsTimer(CONFIG, sc); register(d); d.record(42, TimeUnit.MILLISECONDS); d.computeStats(); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_50")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_95")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "avg")).value(), 1e-12); }
/** * The cumulative count since this counter was last reset. How often a counter * is reset depends on the underlying registry implementation. */ default long count() { return (long) actualCount(); }
@Override public double actualCount() { Iterator<Counter> it = meters.iterator(); return it.hasNext() ? it.next().actualCount() : 0.0; } }
@Test public void counterAdd() { Counter c = registry.counter("foo"); Assertions.assertEquals(0.0, c.actualCount(), 1e-12); c.add(1.5); Assertions.assertEquals(1.5, c.actualCount(), 1e-12); }
@Test public void testAddInfinity() { Counter c = new DefaultCounter(clock, NoopId.INSTANCE); c.add(Double.POSITIVE_INFINITY); Assertions.assertEquals(c.actualCount(), 0.0, 1e-12); }
@Test public void testAddNegativeAmount() { Counter c = new DefaultCounter(clock, NoopId.INSTANCE); c.add(-42.0); Assertions.assertEquals(c.actualCount(), 0.0, 1e-12); }