当前位置: 首页>>代码示例>>Java>>正文


Java Reservoir.update方法代码示例

本文整理汇总了Java中com.codahale.metrics.Reservoir.update方法的典型用法代码示例。如果您正苦于以下问题:Java Reservoir.update方法的具体用法?Java Reservoir.update怎么用?Java Reservoir.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codahale.metrics.Reservoir的用法示例。


在下文中一共展示了Reservoir.update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldCacheSnapshot

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void shouldCacheSnapshot() {
    Reservoir reservoir = new HdrBuilder().neverResetReservoir().buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    reservoir.update(30);
    reservoir.update(40);
    Snapshot secondSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, secondSnapshot);
    assertEquals(10, secondSnapshot.getMin());
    assertEquals(40, secondSnapshot.getMax());

    reservoir.update(9);
    reservoir.update(60);
    Snapshot thirdSnapshot = reservoir.getSnapshot();
    assertNotSame(secondSnapshot, thirdSnapshot);
    assertEquals(9, thirdSnapshot.getMin());
    assertEquals(60, thirdSnapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:23,代码来源:UniformAccumulatorTest.java

示例2: shouldCacheSnapshot

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void shouldCacheSnapshot() {
    Reservoir reservoir = new HdrBuilder().resetReservoirOnSnapshot().buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    reservoir.update(30);
    reservoir.update(40);
    Snapshot secondSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, secondSnapshot);
    assertEquals(30, secondSnapshot.getMin());
    assertEquals(40, secondSnapshot.getMax());

    reservoir.update(50);
    reservoir.update(60);
    Snapshot thirdSnapshot = reservoir.getSnapshot();
    assertNotSame(secondSnapshot, thirdSnapshot);
    assertEquals(50, thirdSnapshot.getMin());
    assertEquals(60, thirdSnapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:23,代码来源:ResetOnSnapshotAccumulatorTest.java

示例3: testSkipBigValues

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void testSkipBigValues() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.SKIP).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:17,代码来源:OverflowResolverTest.java

示例4: testReduceBigValuesToMax

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void testReduceBigValuesToMax() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.REDUCE_TO_HIGHEST_TRACKABLE).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:17,代码来源:OverflowResolverTest.java

示例5: runInParallel

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
public static void runInParallel(Reservoir reservoir, long durationMillis) throws InterruptedException {
    AtomicReference<Throwable> errorRef = new AtomicReference<>();

    Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
    long start = System.currentTimeMillis();
    final CountDownLatch latch = new CountDownLatch(threads.length);
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(() -> {
            try {
                // update reservoir 100 times and take snapshot on each cycle
                while (errorRef.get() == null && System.currentTimeMillis() - start < durationMillis) {
                    for (int j = 1; j <= 10; j++) {
                        reservoir.update(ThreadLocalRandom.current().nextInt(j));
                    }
                    reservoir.getSnapshot();
                }
            } catch (Exception e){
                e.printStackTrace();
                errorRef.set(e);
            } finally {
                latch.countDown();
            }
        });
        threads[i].start();
    }
    latch.await();
    //latch.await(duration.toMillis() + 4000, TimeUnit.MILLISECONDS);
    if (latch.getCount() > 0) {
        throw new IllegalStateException("" + latch.getCount() + " was not completed");
    }
    if (errorRef.get() != null) {
        throw new RuntimeException(errorRef.get());
    }
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:35,代码来源:HistogramUtil.java

示例6: testPassThruBigValues2

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void testPassThruBigValues2() {
    Reservoir reservoir = new HdrBuilder()
            .withHighestTrackableValue(100, OverflowResolver.PASS_THRU)
            .buildReservoir();
    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(101, snapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:10,代码来源:OverflowResolverTest.java

示例7: test

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void test() {
    AtomicLong time = new AtomicLong(0);
    Clock wallClock = Clock.mock(time);
    Reservoir reservoir = new HdrBuilder(wallClock)
            .resetReservoirPeriodically(Duration.ofMillis(1000))
            .withBackgroundExecutor(MockExecutor.INSTANCE)
            .buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(10, snapshot.getMin());
    assertEquals(20, snapshot.getMax());

    time.getAndAdd(900); // 900
    reservoir.update(30);
    reservoir.update(40);
    snapshot = reservoir.getSnapshot();
    assertEquals(10, snapshot.getMin());
    assertEquals(40, snapshot.getMax());

    time.getAndAdd(99); // 999
    reservoir.update(8);
    reservoir.update(60);
    snapshot = reservoir.getSnapshot();
    assertEquals(8, snapshot.getMin());
    assertEquals(60, snapshot.getMax());

    time.getAndAdd(1); // 1000
    reservoir.update(70);
    reservoir.update(80);
    snapshot = reservoir.getSnapshot();
    assertEquals(70, snapshot.getMin());
    assertEquals(80, snapshot.getMax());

    time.getAndAdd(1001); // 2001
    reservoir.update(90);
    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(90, snapshot.getMin());
    assertEquals(100, snapshot.getMax());

    time.getAndAdd(1000); // 3001
    snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMin());
    assertEquals(0, snapshot.getMax());

    time.getAndAdd(1); // 3002
    reservoir.update(42);
    snapshot = reservoir.getSnapshot();
    assertEquals(42, snapshot.getMin());
    assertEquals(42, snapshot.getMax());

    time.getAndAdd(2000); // 5002
    snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMin());
    assertEquals(0, snapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:60,代码来源:ResetPeriodicallyAccumulatorTest.java

示例8: test

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void test() {
    AtomicLong time = new AtomicLong(0);
    Clock wallClock = Clock.mock(time);
    Reservoir reservoir = new HdrBuilder(wallClock)
            .resetReservoirPeriodicallyByChunks(Duration.ofMillis(3000), 3)
            .withBackgroundExecutor(MockExecutor.INSTANCE)
            .buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(10, snapshot.getMin());
    assertEquals(20, snapshot.getMax());

    time.getAndAdd(900); // 900
    reservoir.update(30);
    reservoir.update(40);
    snapshot = reservoir.getSnapshot();
    assertEquals(10, snapshot.getMin());
    assertEquals(40, snapshot.getMax());

    time.getAndAdd(99); // 999
    reservoir.update(9);
    reservoir.update(60);
    snapshot = reservoir.getSnapshot();
    assertEquals(9, snapshot.getMin());
    assertEquals(60, snapshot.getMax());

    time.getAndAdd(1); // 1000
    reservoir.update(12);
    reservoir.update(70);
    snapshot = reservoir.getSnapshot();
    assertEquals(9, snapshot.getMin());
    assertEquals(70, snapshot.getMax());

    time.getAndAdd(1001); // 2001
    reservoir.update(13);
    reservoir.update(80);
    snapshot = reservoir.getSnapshot();
    assertEquals(9, snapshot.getMin());
    assertEquals(80, snapshot.getMax());

    time.getAndAdd(1000); // 3001
    snapshot = reservoir.getSnapshot();
    assertEquals(9, snapshot.getMin());
    assertEquals(80, snapshot.getMax());

    time.getAndAdd(999); // 4000
    snapshot = reservoir.getSnapshot();
    assertEquals(12, snapshot.getMin());
    assertEquals(80, snapshot.getMax());
    reservoir.update(1);
    reservoir.update(200);
    snapshot = reservoir.getSnapshot();
    assertEquals(1, snapshot.getMin());
    assertEquals(200, snapshot.getMax());

    time.getAndAdd(10000); // 14000
    snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMin());
    assertEquals(0, snapshot.getMax());
    reservoir.update(3);

    time.addAndGet(3999); // 17999
    snapshot = reservoir.getSnapshot();
    assertEquals(3, snapshot.getMax());

    time.addAndGet(1); // 18000
    snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:73,代码来源:ResetByChunksAccumulatorTest.java

示例9: shouldCacheSnapshot

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test
public void shouldCacheSnapshot() {
    AtomicLong time = new AtomicLong(System.currentTimeMillis());
    Clock wallClock = Clock.mock(time);
    Reservoir reservoir = new HdrBuilder(wallClock)
            .resetReservoirOnSnapshot()
            .withSnapshotCachingDuration(Duration.ofMillis(1000))
            .buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    time.getAndAdd(900);
    reservoir.update(30);
    reservoir.update(40);
    Snapshot firstCachedSnapshot = reservoir.getSnapshot();
    assertSame(firstSnapshot, firstCachedSnapshot);
    assertEquals(10, firstCachedSnapshot.getMin());
    assertEquals(20, firstCachedSnapshot.getMax());

    time.getAndAdd(99);
    reservoir.update(50);
    reservoir.update(60);
    Snapshot secondCachedSnapshot = reservoir.getSnapshot();
    assertSame(firstSnapshot, secondCachedSnapshot);
    assertEquals(10, secondCachedSnapshot.getMin());
    assertEquals(20, secondCachedSnapshot.getMax());

    time.getAndAdd(1);
    reservoir.update(70);
    reservoir.update(80);
    Snapshot firstNewSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, firstNewSnapshot);
    assertEquals(30, firstNewSnapshot.getMin());
    assertEquals(80, firstNewSnapshot.getMax());

    time.getAndAdd(1001);
    reservoir.update(90);
    reservoir.update(100);
    Snapshot secondNewSnapshot = reservoir.getSnapshot();
    assertNotSame(firstNewSnapshot, secondNewSnapshot);
    assertEquals(90, secondNewSnapshot.getMin());
    assertEquals(100, secondNewSnapshot.getMax());
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:46,代码来源:SnapshotCachingTest.java

示例10: testPassThruBigValues

import com.codahale.metrics.Reservoir; //导入方法依赖的package包/类
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testPassThruBigValues() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.PASS_THRU).buildReservoir();
    reservoir.update(100000);
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:rolling-metrics,代码行数:6,代码来源:OverflowResolverTest.java


注:本文中的com.codahale.metrics.Reservoir.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。