@Test public void testEvenRouting() { MockLatencyWeightedRoute lastRoute = null; for (int i = 0; i < REPEAT; i++) { MockLatencyWeightedRoute route = router.getRoute(); assertNotEquals(lastRoute, route); if (route != null) { route.incr(); route.updateExpectedLatency(10); lastRoute = route; } else { fail(); } } double expected = 1.0 / (double) NUM_ROUTES; for (MockLatencyWeightedRoute route : routes) { assertTrue(Math.abs((double) route.count() / (double) REPEAT - expected) < 0.01); } }
public R getRoute() { synchronized (pq) { while (!pq.isEmpty()) { R route = pq.poll(); if (!route.isClosed()) { route.updateWeight(); pq.offer(route); return route; } } return null; } }
LatencyWeightedRouter { public R getRoute() { synchronized (pq) { while (!pq.isEmpty()) { R route = pq.poll(); if (!route.isClosed()) { route.updateWeight(); pq.offer(route); return route; } } return null; } } }
LatencyWeightedRouter { public R getRoute() { synchronized (pq) { while (!pq.isEmpty()) { R route = pq.poll(); if (!route.isClosed()) { route.updateWeight(); pq.offer(route); return route; } } return null; } } LatencyWeightedRouter(Collection<R> routes); }
LatencyWeightedRouter { public R getRoute() { synchronized (pq) { while (!pq.isEmpty()) { R route = pq.poll(); if (!route.isClosed()) { route.updateWeight(); pq.offer(route); return route; } } return null; } } LatencyWeightedRouter(Collection<R> routes); R getRoute(); }
LatencyWeightedRouter { public R getRoute() { synchronized (pq) { while (!pq.isEmpty()) { R route = pq.poll(); if (!route.isClosed()) { route.updateWeight(); pq.offer(route); return route; } } return null; } } LatencyWeightedRouter(Collection<R> routes); R getRoute(); static final long MAX_LATENCY; static final long DEFAULT_LATENCY; }