Skip to content

Commit

Permalink
[hotfix] Fix port occupied in KvQueryTableTest (apache#3774)
Browse files Browse the repository at this point in the history
  • Loading branch information
FangYongs authored Jul 18, 2024
1 parent 982e7b1 commit b5697df
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -71,8 +72,8 @@ public void beforeEach() {
this.query0 = table.newLocalTableQuery().withIOManager(ioManager);
this.query1 = table.newLocalTableQuery().withIOManager(ioManager);

this.server0 = createServer(0, query0, 7777);
this.server1 = createServer(1, query1, 7900);
this.server0 = createServer(0, query0, 7700, 7799);
this.server1 = createServer(1, query1, 7900, 7999);
registryServers();

this.client =
Expand All @@ -86,14 +87,18 @@ private void registryServers() {
serviceManager.resetService(PRIMARY_KEY_LOOKUP, addresses);
}

private KvQueryServer createServer(int serverId, TableQuery query, int port) {
private KvQueryServer createServer(int serverId, TableQuery query, int minPort, int maxPort) {
try {
List<Integer> portList = new ArrayList<>();
for (int p = minPort; p <= maxPort; p++) {
portList.add(p);
}
KvQueryServer server =
new KvQueryServer(
serverId,
2,
InetAddress.getLocalHost().getHostName(),
Collections.singletonList(port).iterator(),
portList.iterator(),
1,
1,
query,
Expand Down Expand Up @@ -159,8 +164,8 @@ public void testServerRestartSamePorts() throws Throwable {
innerTestServerRestart(
() -> {
shutdownServers();
KvQueryTableTest.this.server0 = createServer(0, query0, 7777);
KvQueryTableTest.this.server1 = createServer(1, query1, 7900);
KvQueryTableTest.this.server0 = createServer(0, query0, 7700, 7799);
KvQueryTableTest.this.server1 = createServer(1, query1, 7900, 7999);
registryServers();
});
}
Expand All @@ -170,8 +175,8 @@ public void testServerRestartSwitchPorts() throws Throwable {
innerTestServerRestart(
() -> {
shutdownServers();
KvQueryTableTest.this.server0 = createServer(0, query0, 7900);
KvQueryTableTest.this.server1 = createServer(1, query1, 7777);
KvQueryTableTest.this.server0 = createServer(0, query0, 7900, 7999);
KvQueryTableTest.this.server1 = createServer(1, query1, 7700, 7799);
registryServers();
});
}
Expand All @@ -181,8 +186,8 @@ public void testServerRestartChangePorts() throws Throwable {
innerTestServerRestart(
() -> {
shutdownServers();
KvQueryTableTest.this.server0 = createServer(0, query0, 7778);
KvQueryTableTest.this.server1 = createServer(1, query1, 7901);
KvQueryTableTest.this.server0 = createServer(0, query0, 7700, 7799);
KvQueryTableTest.this.server1 = createServer(1, query1, 7900, 7999);
registryServers();
});
}
Expand Down

0 comments on commit b5697df

Please sign in to comment.