Skip to content

Commit

Permalink
[FIX_BUG][server-test] dismiss of server warm-up time in RoundRobinSe…
Browse files Browse the repository at this point in the history
…lectorTest (#4067)
  • Loading branch information
CalvinKirs authored Nov 14, 2020
1 parent f047f51 commit 8a92105
Showing 1 changed file with 27 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* round robin selector
Expand All @@ -39,82 +39,59 @@ public void testSelectWithIllegalArgumentException() {
@Test
public void testSelect1() {
RoundRobinSelector selector = new RoundRobinSelector();
// dismiss of server warm-up time
long startTime = System.currentTimeMillis() - 60 * 10 * 1000;
List<Host> hostOneList = Arrays.asList(
new Host("192.168.1.1", 80, 20, startTime, "kris"),
new Host("192.168.1.2", 80, 10, startTime, "kris"));

List<Host> hostTwoList = Arrays.asList(
new Host("192.168.1.1", 80, 20, startTime, "kris"),
new Host("192.168.1.2", 80, 10, startTime, "kris"),
new Host("192.168.1.3", 80, 10, startTime, "kris"));

Host result;
result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.2", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.1", result.getIp());

// add new host
result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.2", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
// add new host
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.3", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.2", result.getIp());
result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"),
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostTwoList);
Assert.assertEquals("192.168.1.3", result.getIp());

// remove host3
result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.1", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.2", result.getIp());

result = selector.select(Arrays.asList(
new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"),
new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris")));
result = selector.select(hostOneList);
Assert.assertEquals("192.168.1.1", result.getIp());

}
Expand Down

0 comments on commit 8a92105

Please sign in to comment.