WeightedRoundRobinMultiplexer implements RpcMultiplexer { public int getAndAdvanceCurrentIndex() { int idx = this.getCurrentIndex(); this.advanceIndex(); return idx; } WeightedRoundRobinMultiplexer(int aNumQueues, String ns,
    Configuration conf); int getAndAdvanceCurrentIndex(); static final String IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY; static final Logger LOG; }
@Test public void testDefaultPattern() { mux = new WeightedRoundRobinMultiplexer(1, "", new Configuration()); for(int i = 0; i < 10; i++) { assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); } mux = new WeightedRoundRobinMultiplexer(2, "", new Configuration()); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); mux = new WeightedRoundRobinMultiplexer(3, "", new Configuration()); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); mux = new WeightedRoundRobinMultiplexer(4, "", new Configuration()); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(3); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); }
@Test public void testCustomPattern() { Configuration conf = new Configuration(); conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY, "1", "1"); mux = new WeightedRoundRobinMultiplexer(2, "test.custom", conf); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY, "1", "3", "2"); mux = new WeightedRoundRobinMultiplexer(3, "test.custom", conf); for(int i = 0; i < 5; i++) { assertThat(mux.getAndAdvanceCurrentIndex()).isZero(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isOne(); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2); assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2); } }