LoadBalancedLists { static public <E> LoadBalancedList<E> synchronizedList(LoadBalancedList<E> list) { return new ConcurrentLoadBalancedList<E>(list); }  static LoadBalancedList<E> synchronizedList(LoadBalancedList<E> list);  }
@Test public void getNext() throws Exception { LoadBalancedList<String> list = LoadBalancedLists.synchronizedList(new RoundRobinLoadBalancedList<String>()); list.set("Item1", 1); for (int i = 0; i < 50; i++) { Assert.assertTrue("Failed on i=" + i, "Item1".equals(list.getNext())); } list.remove("Item1"); for (int i = 0; i < 50; i++) { Assert.assertTrue("Failed on i=" + i, list.getNext() == null); } list.set("Item2", 1); for (int i = 0; i < 50; i++) { Assert.assertTrue("Failed on i=" + i, "Item2".equals(list.getNext())); } list.set("Item2", 0); for (int i = 0; i < 50; i++) { Assert.assertTrue("Failed on i=" + i, list.getNext() == null); } }
@Test public void getNextEqualWeight() throws Exception { LoadBalancedList<String> list = LoadBalancedLists.synchronizedList(new RoundRobinLoadBalancedList<String>()); list.set("Item1", 2); list.set("Item2", 2); list.set("Item3", 2); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); list.set("Item1", 1); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); list.set("Item1", 2); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); Assert.assertEquals("Item3", list.getNext()); Assert.assertEquals("Item1", list.getNext()); Assert.assertEquals("Item2", list.getNext()); }