Search in sources :

Example 1 with AsyncPoolStatsTracker

use of com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker in project rest.li by linkedin.

the class TestAsyncPoolStatsTracker method testIncrements.

@Test
public void testIncrements() {
    AsyncPoolStatsTracker tracker = new AsyncPoolStatsTracker(() -> LIFECYCLE_STATS, () -> MAX_SIZE, () -> MIN_SIZE, () -> POOL_SIZE, () -> CHECKED_OUT, () -> IDLE_SIZE, CLOCK, new LongTracking());
    IntStream.range(0, DESTROY_ERROR_INCREMENTS).forEach(i -> tracker.incrementDestroyErrors());
    IntStream.range(0, DESTROY_INCREMENTS).forEach(i -> tracker.incrementDestroyed());
    IntStream.range(0, TIMEOUT_INCREMENTS).forEach(i -> tracker.incrementTimedOut());
    IntStream.range(0, CREATE_ERROR_INCREMENTS).forEach(i -> tracker.incrementCreateErrors());
    IntStream.range(0, BAD_DESTROY_INCREMENTS).forEach(i -> tracker.incrementBadDestroyed());
    IntStream.range(0, CREATED_INCREMENTS).forEach(i -> tracker.incrementCreated());
    AsyncPoolStats stats = tracker.getStats();
    Assert.assertEquals(stats.getTotalDestroyErrors(), DESTROY_ERROR_INCREMENTS);
    Assert.assertEquals(stats.getTotalDestroyed(), DESTROY_INCREMENTS);
    Assert.assertEquals(stats.getTotalTimedOut(), TIMEOUT_INCREMENTS);
    Assert.assertEquals(stats.getTotalCreateErrors(), CREATE_ERROR_INCREMENTS);
    Assert.assertEquals(stats.getTotalBadDestroyed(), BAD_DESTROY_INCREMENTS);
    Assert.assertEquals(stats.getTotalCreated(), CREATED_INCREMENTS);
    Assert.assertEquals(stats.getCheckedOut(), CHECKED_OUT);
    Assert.assertEquals(stats.getPoolSize(), POOL_SIZE);
}
Also used : LongTracking(com.linkedin.common.stats.LongTracking) AsyncPoolStatsTracker(com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker) AsyncPoolStats(com.linkedin.r2.transport.http.client.AsyncPoolStats) Test(org.testng.annotations.Test)

Example 2 with AsyncPoolStatsTracker

use of com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker in project rest.li by linkedin.

the class TestAsyncPoolStatsTracker method testDefaults.

@Test
public void testDefaults() {
    AsyncPoolStatsTracker tracker = new AsyncPoolStatsTracker(() -> LIFECYCLE_STATS, () -> MAX_SIZE, () -> MIN_SIZE, () -> POOL_SIZE, () -> CHECKED_OUT, () -> IDLE_SIZE, CLOCK, new LongTracking());
    AsyncPoolStats stats = tracker.getStats();
    Assert.assertSame(stats.getLifecycleStats(), LIFECYCLE_STATS);
    Assert.assertEquals(stats.getMaxPoolSize(), MAX_SIZE);
    Assert.assertEquals(stats.getMinPoolSize(), MIN_SIZE);
    Assert.assertEquals(stats.getIdleCount(), IDLE_SIZE);
    Assert.assertEquals(stats.getCheckedOut(), CHECKED_OUT);
    Assert.assertEquals(stats.getPoolSize(), POOL_SIZE);
    Assert.assertEquals(stats.getTotalDestroyErrors(), 0);
    Assert.assertEquals(stats.getTotalDestroyed(), 0);
    Assert.assertEquals(stats.getTotalTimedOut(), 0);
    Assert.assertEquals(stats.getTotalCreateErrors(), 0);
    Assert.assertEquals(stats.getTotalBadDestroyed(), 0);
    Assert.assertEquals(stats.getTotalCreated(), 0);
    Assert.assertEquals(stats.getWaitTime50Pct(), 0);
    Assert.assertEquals(stats.getWaitTime95Pct(), 0);
    Assert.assertEquals(stats.getWaitTime99Pct(), 0);
    Assert.assertEquals(stats.getWaitTimeAvg(), 0.0);
}
Also used : LongTracking(com.linkedin.common.stats.LongTracking) AsyncPoolStatsTracker(com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker) AsyncPoolStats(com.linkedin.r2.transport.http.client.AsyncPoolStats) Test(org.testng.annotations.Test)

Example 3 with AsyncPoolStatsTracker

use of com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker in project rest.li by linkedin.

the class TestAsyncPoolStatsTracker method testMinimumSamplingPeriod.

/**
 * Tests sampled values are the same when #getStats() are called within the same
 * sampling period. Also tests the samplers are correctly updated when #getStats
 * are called in successive sampling periods.
 */
@Test
public void testMinimumSamplingPeriod() {
    SettableClock clock = new SettableClock();
    AsyncPoolStatsTracker tracker = new AsyncPoolStatsTracker(() -> LIFECYCLE_STATS, () -> MAX_SIZE, () -> MIN_SIZE, () -> _poolSize, () -> _checkedOut, () -> IDLE_SIZE, clock, new LongTracking());
    // Samples the max values
    tracker.sampleMaxPoolSize();
    tracker.sampleMaxCheckedOut();
    tracker.sampleMaxWaitTime(WAIT_TIME);
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT);
    Assert.assertEquals(tracker.getStats().getSampleMaxWaitTime(), WAIT_TIME);
    // Without incrementing time we should still be getting the old sampled values
    _poolSize = POOL_SIZE + 10;
    tracker.sampleMaxPoolSize();
    _checkedOut = CHECKED_OUT + 10;
    tracker.sampleMaxCheckedOut();
    tracker.sampleMaxWaitTime(WAIT_TIME + 100);
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT);
    Assert.assertEquals(tracker.getStats().getSampleMaxWaitTime(), WAIT_TIME);
    // After incrementing time we should be getting the new sampled values
    clock.addDuration(SAMPLING_DURATION_INCREMENT);
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE + 10);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT + 10);
    Assert.assertEquals(tracker.getStats().getSampleMaxWaitTime(), WAIT_TIME + 100);
}
Also used : LongTracking(com.linkedin.common.stats.LongTracking) SettableClock(com.linkedin.util.clock.SettableClock) AsyncPoolStatsTracker(com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker) Test(org.testng.annotations.Test)

Example 4 with AsyncPoolStatsTracker

use of com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker in project rest.li by linkedin.

the class TestAsyncPoolStatsTracker method testSamplers.

@Test
public void testSamplers() {
    SettableClock clock = new SettableClock();
    AsyncPoolStatsTracker tracker = new AsyncPoolStatsTracker(() -> LIFECYCLE_STATS, () -> MAX_SIZE, () -> MIN_SIZE, () -> _poolSize, () -> _checkedOut, () -> IDLE_SIZE, clock, new LongTracking());
    // Samples the max values
    tracker.sampleMaxPoolSize();
    tracker.sampleMaxCheckedOut();
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT);
    // Samples at smaller values compared the old samples
    _poolSize = POOL_SIZE - 10;
    _checkedOut = CHECKED_OUT - 10;
    tracker.sampleMaxPoolSize();
    tracker.sampleMaxCheckedOut();
    clock.addDuration(SAMPLING_DURATION_INCREMENT);
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT);
    // Samples the max pool size at POOL_SIZE + 10
    _poolSize = POOL_SIZE + 10;
    _checkedOut = CHECKED_OUT + 10;
    tracker.sampleMaxPoolSize();
    tracker.sampleMaxCheckedOut();
    clock.addDuration(SAMPLING_DURATION_INCREMENT);
    Assert.assertEquals(tracker.getStats().getSampleMaxCheckedOut(), CHECKED_OUT + 10);
    Assert.assertEquals(tracker.getStats().getSampleMaxPoolSize(), POOL_SIZE + 10);
}
Also used : LongTracking(com.linkedin.common.stats.LongTracking) SettableClock(com.linkedin.util.clock.SettableClock) AsyncPoolStatsTracker(com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker) Test(org.testng.annotations.Test)

Example 5 with AsyncPoolStatsTracker

use of com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker in project rest.li by linkedin.

the class TestAsyncPoolStatsTracker method testSuppliers.

@Test
public void testSuppliers() {
    AsyncPoolStatsTracker tracker = new AsyncPoolStatsTracker(() -> LIFECYCLE_STATS, () -> MAX_SIZE, () -> MIN_SIZE, () -> _poolSize, () -> _checkedOut, () -> IDLE_SIZE, CLOCK, new LongTracking());
    for (int i = 0; i < 10; i++) {
        _poolSize++;
        _checkedOut++;
        Assert.assertEquals(tracker.getStats().getPoolSize(), _poolSize);
        Assert.assertEquals(tracker.getStats().getCheckedOut(), _checkedOut);
    }
}
Also used : LongTracking(com.linkedin.common.stats.LongTracking) AsyncPoolStatsTracker(com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker) Test(org.testng.annotations.Test)

Aggregations

LongTracking (com.linkedin.common.stats.LongTracking)5 AsyncPoolStatsTracker (com.linkedin.r2.transport.http.client.AsyncPoolStatsTracker)5 Test (org.testng.annotations.Test)5 AsyncPoolStats (com.linkedin.r2.transport.http.client.AsyncPoolStats)2 SettableClock (com.linkedin.util.clock.SettableClock)2