@Test public void roundRobinWithSingleSlave() { // Given SlavePriority roundRobin = SlavePriorities.roundRobin(); // When Iterator<Slave> slaves = roundRobin.prioritize(slaves(2)).iterator(); // Then assertEquals(2, slaves.next().getServerId()); }
@Test public void roundRobinWithNoSlaves() { // Given SlavePriority roundRobin = SlavePriorities.roundRobin(); // When Iterator<Slave> slaves = roundRobin.prioritize(slaves()).iterator(); // Then assertFalse(slaves.hasNext()); }
@Test public void roundRobinWithTwoSlavesAndPushFactorTwo() { // Given SlavePriority roundRobin = SlavePriorities.roundRobin(); // When Iterator<Slave> slaves = roundRobin.prioritize(slaves(2, 3)).iterator(); // Then assertEquals(2, slaves.next().getServerId()); assertEquals(3, slaves.next().getServerId()); }
@Test public void roundRobinWithTwoSlavesAndPushFactorOneWhenSlaveIsRemoved() { // Given SlavePriority roundRobin = SlavePriorities.roundRobin(); // When Slave slave1 = roundRobin.prioritize(slaves(2, 3, 4)).iterator().next(); Slave slave2 = roundRobin.prioritize(slaves(2, 3, 4)).iterator().next(); Slave slave3 = roundRobin.prioritize(slaves(2, 3)).iterator().next(); // Then assertEquals(2, slave1.getServerId()); assertEquals(3, slave2.getServerId()); assertEquals(2, slave3.getServerId()); }