use of com.linkedin.util.clock.SettableClock in project rest.li by linkedin.
the class TestServerRetryTracker method setUp.
@BeforeMethod
public void setUp() {
_clock = new SettableClock();
_serverRetryTracker = new ServerRetryTracker(ServerRetryFilter.DEFAULT_RETRY_LIMIT, ServerRetryFilter.DEFAULT_AGGREGATED_INTERVAL_NUM, ServerRetryFilter.DEFAULT_MAX_REQUEST_RETRY_RATIO, ServerRetryFilter.DEFAULT_UPDATE_INTERVAL_MS, _clock);
}
use of com.linkedin.util.clock.SettableClock 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);
}
use of com.linkedin.util.clock.SettableClock 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);
}
use of com.linkedin.util.clock.SettableClock in project rest.li by linkedin.
the class DegraderTrackerClientTest method testDoNotSlowStartWhenFalse.
@Test
public void testDoNotSlowStartWhenFalse() {
Map<Integer, PartitionData> partitionDataMap = createDefaultPartitionData(1d);
DegraderImpl.Config config = new DegraderImpl.Config();
double initialDropRate = 0.99d;
config.setInitialDropRate(initialDropRate);
DegraderTrackerClient client = new DegraderTrackerClientImpl(URI.create("http://test.qa.com:1234/foo"), partitionDataMap, new TestClient(), new SettableClock(), config, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS, TrackerClientImpl.DEFAULT_ERROR_STATUS_PATTERN, false);
DegraderControl degraderControl = client.getDegraderControl(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
Assert.assertEquals(degraderControl.getInitialDropRate(), initialDropRate, "Initial drop rate in config should not have been overridden by doNotSlowStart uri property.");
}
use of com.linkedin.util.clock.SettableClock in project rest.li by linkedin.
the class DegraderTrackerClientTest method testCallTrackingRestRequest.
@Test
public void testCallTrackingRestRequest() throws Exception {
URI uri = URI.create("http://test.qa.com:1234/foo");
SettableClock clock = new SettableClock();
AtomicInteger action = new AtomicInteger(0);
TransportClient tc = new TransportClient() {
@Override
public void restRequest(RestRequest request, RequestContext requestContext, Map<String, String> wireAttrs, TransportCallback<RestResponse> callback) {
clock.addDuration(5);
switch(action.get()) {
// success
case 0:
callback.onResponse(TransportResponseImpl.success(RestResponseFactory.noResponse()));
break;
// fail with rest exception
case 1:
callback.onResponse(TransportResponseImpl.error(RestException.forError(500, "rest exception")));
break;
// fail with timeout exception
case 2:
callback.onResponse(TransportResponseImpl.error(new RemoteInvocationException(new TimeoutException())));
break;
// fail with other exception
default:
callback.onResponse(TransportResponseImpl.error(new RuntimeException()));
break;
}
}
@Override
public void shutdown(Callback<None> callback) {
}
};
DegraderTrackerClientImpl client = (DegraderTrackerClientImpl) createTrackerClient(tc, clock, uri);
CallTracker callTracker = client.getCallTracker();
CallTracker.CallStats stats;
DegraderControl degraderControl = client.getDegraderControl(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
client.restRequest(new RestRequestBuilder(uri).build(), new RequestContext(), new HashMap<>(), new TestTransportCallback<>());
clock.addDuration(5000);
stats = callTracker.getCallStats();
Assert.assertEquals(stats.getCallCount(), 1);
Assert.assertEquals(stats.getErrorCount(), 0);
Assert.assertEquals(stats.getCallCountTotal(), 1);
Assert.assertEquals(stats.getErrorCountTotal(), 0);
Assert.assertEquals(degraderControl.getCurrentComputedDropRate(), 0.0, 0.001);
action.set(1);
client.restRequest(new RestRequestBuilder(uri).build(), new RequestContext(), new HashMap<>(), new TestTransportCallback<>());
clock.addDuration(5000);
stats = callTracker.getCallStats();
Assert.assertEquals(stats.getCallCount(), 1);
Assert.assertEquals(stats.getErrorCount(), 1);
Assert.assertEquals(stats.getCallCountTotal(), 2);
Assert.assertEquals(stats.getErrorCountTotal(), 1);
Assert.assertEquals(degraderControl.getCurrentComputedDropRate(), 0.2, 0.001);
action.set(2);
client.restRequest(new RestRequestBuilder(uri).build(), new RequestContext(), new HashMap<>(), new TestTransportCallback<>());
clock.addDuration(5000);
stats = callTracker.getCallStats();
Assert.assertEquals(stats.getCallCount(), 1);
Assert.assertEquals(stats.getErrorCount(), 1);
Assert.assertEquals(stats.getCallCountTotal(), 3);
Assert.assertEquals(stats.getErrorCountTotal(), 2);
Assert.assertEquals(degraderControl.getCurrentComputedDropRate(), 0.4, 0.001);
action.set(3);
client.restRequest(new RestRequestBuilder(uri).build(), new RequestContext(), new HashMap<>(), new TestTransportCallback<>());
clock.addDuration(5000);
stats = callTracker.getCallStats();
Assert.assertEquals(stats.getCallCount(), 1);
Assert.assertEquals(stats.getErrorCount(), 1);
Assert.assertEquals(stats.getCallCountTotal(), 4);
Assert.assertEquals(stats.getErrorCountTotal(), 3);
Assert.assertEquals(degraderControl.getCurrentComputedDropRate(), 0.2, 0.001);
}
Aggregations