com.netflix.spectator.api.Counter.actualCount()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中com.netflix.spectator.api.Counter.actualCount()方法的一些代码示例,展示了Counter.actualCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Counter.actualCount()方法的具体详情如下:
包路径:com.netflix.spectator.api.Counter
类名称:Counter
方法名:actualCount

Counter.actualCount介绍

[英]The cumulative count as a floating point value since this counter was last reset. How often a counter is reset depends on the underlying registry implementation.
[中]自上次重置此计数器以来作为浮点值的累积计数。计数器重置的频率取决于基础注册表实现。

代码示例

代码示例来源:origin: Netflix/servo

@Override public double actualCount() {
 return get().actualCount();
}

代码示例来源:origin: Netflix/servo

@Test
public void testDoubleCounterAdd() {
 DoubleCounter c = new DoubleCounter(CONFIG, Clock.WALL);
 register(c);
 c.increment(0.2);
 assertEquals(0.2, registry.counter(ID).actualCount());
}

代码示例来源:origin: Netflix/Priam

@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());
}

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/Priam

Assert.assertNotEquals(size, (int) backupMetrics.getValidUploads().actualCount());

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/Priam

@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());
}

代码示例来源:origin: Netflix/Priam

@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;
  }
}

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/Priam

@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());
}

代码示例来源:origin: Netflix/Priam

@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());
}

代码示例来源:origin: Netflix/Priam

@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;
  }
}

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/servo

@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);
}

代码示例来源:origin: Netflix/spectator

/**
 * 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();
}

代码示例来源:origin: Netflix/spectator

@Override public double actualCount() {
  Iterator<Counter> it = meters.iterator();
  return it.hasNext() ? it.next().actualCount() : 0.0;
 }
}

代码示例来源:origin: Netflix/spectator

@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);
}

代码示例来源:origin: Netflix/spectator

@Test
public void testAddInfinity() {
 Counter c = new DefaultCounter(clock, NoopId.INSTANCE);
 c.add(Double.POSITIVE_INFINITY);
 Assertions.assertEquals(c.actualCount(), 0.0, 1e-12);
}

代码示例来源:origin: Netflix/spectator

@Test
public void testAddNegativeAmount() {
 Counter c = new DefaultCounter(clock, NoopId.INSTANCE);
 c.add(-42.0);
 Assertions.assertEquals(c.actualCount(), 0.0, 1e-12);
}

相关文章