Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX_BUG][server-test] dismiss of server warm-up time in RoundRobinSe… #4067

Merged
merged 1 commit into from
Nov 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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