List<TrackerClient> clients = new ArrayList<TrackerClient>();
URI uri1 = URI.create("http://someTestService/someTestUrl");
URI uri2 = URI.create("http://abcxfweuoeueoueoueoukeueoueoueoueoueouo/2354");
TestClock clock1 = new TestClock();
TestClock clock2 = new TestClock();
TrackerClient client1 = getClient(uri1, clock1);
TrackerClient client2 = getClient(uri2, clock2);
clients.add(client1);
clients.add(client2);
// force client2 to be disabled
DegraderControl dcClient2Default = client2.getDegraderControl(DEFAULT_PARTITION_ID);
dcClient2Default.setOverrideMinCallCount(1);
dcClient2Default.setMinCallCount(1);
dcClient2Default.setMaxDropRate(1d);
dcClient2Default.setUpStep(0.4d);
dcClient2Default.setHighErrorRate(0);
CallCompletion cc = client2.getCallTracker().startCall();
clock2.addMs(1);
cc.endCallWithError();
clock1.addMs(15000);
clock2.addMs(5000);
System.err.println(dcClient2Default.getCurrentComputedDropRate());
System.err.println(client1.getDegraderControl(DEFAULT_PARTITION_ID).getCurrentComputedDropRate());
// trigger a state update
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients));
// now verify that the ring has degraded client 2 by 20%
ConsistentHashRing<URI> ring =
(ConsistentHashRing<URI>) strategy.getState().getPartitionState(DEFAULT_PARTITION_ID).getRing();
Map<URI, AtomicInteger> count = new HashMap<URI, AtomicInteger>();
count.put(uri1, new AtomicInteger(0));
count.put(uri2, new AtomicInteger(0));
for (Point<URI> point : ring.getPoints())
{
count.get(point.getT()).incrementAndGet();
}
// .4 degradation should degrade the weight of client2 by 40%
assertEquals(count.get(uri1).get(), 100);
assertEquals(count.get(uri2).get(), 60);
// now do a basic verification to verify getTrackerClient is properly weighting things
double calls = 10000d;
int client1Count = 0;
int client2Count = 0;
double tolerance = 0.05d;
for (int i = 0; i < calls; ++i)
{
TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 1, clients);
assertNotNull(client);
if (client.getUri().equals(uri1))
{
++client1Count;
}
else
{