Skip to content

Commit 3874f15

Browse files
authored
[#2388] improvement(test): mr, tez, spark integration test use random port (#2397)
### What changes were proposed in this pull request? - Integration test of mr, tez, spark use random port - Re-enable `AccessClusterTest` ### Why are the changes needed? Fix: #2388 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? UT
1 parent 4def3cc commit 3874f15

File tree

39 files changed

+355
-803
lines changed

39 files changed

+355
-803
lines changed

common/src/test/java/org/apache/uniffle/common/port/PortRegistry.java

Lines changed: 0 additions & 178 deletions
This file was deleted.

integration-test/common/src/test/java/org/apache/uniffle/test/AccessClusterTest.java

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@
2929

3030
import com.google.common.collect.Sets;
3131
import com.google.common.util.concurrent.Uninterruptibles;
32-
import org.junit.jupiter.api.Disabled;
32+
import org.junit.jupiter.api.AfterEach;
3333
import org.junit.jupiter.api.Test;
3434
import org.junit.jupiter.api.io.TempDir;
3535

36-
import org.apache.uniffle.client.api.CoordinatorClient;
37-
import org.apache.uniffle.client.factory.CoordinatorClientFactory;
3836
import org.apache.uniffle.client.request.RssAccessClusterRequest;
3937
import org.apache.uniffle.client.response.RssAccessClusterResponse;
40-
import org.apache.uniffle.common.ClientType;
4138
import org.apache.uniffle.common.rpc.ServerType;
4239
import org.apache.uniffle.common.rpc.StatusCode;
4340
import org.apache.uniffle.common.util.Constants;
@@ -46,13 +43,13 @@
4643
import org.apache.uniffle.coordinator.access.AccessCheckResult;
4744
import org.apache.uniffle.coordinator.access.AccessInfo;
4845
import org.apache.uniffle.coordinator.access.checker.AccessChecker;
46+
import org.apache.uniffle.coordinator.metric.CoordinatorMetrics;
4947
import org.apache.uniffle.server.ShuffleServer;
5048
import org.apache.uniffle.server.ShuffleServerConf;
5149

5250
import static org.junit.jupiter.api.Assertions.assertEquals;
5351
import static org.junit.jupiter.api.Assertions.assertTrue;
5452

55-
@Disabled("flaky test")
5653
public class AccessClusterTest extends CoordinatorTestBase {
5754

5855
public static class MockedAccessChecker implements AccessChecker {
@@ -83,20 +80,27 @@ public void close() throws IOException {
8380
}
8481
}
8582

83+
@AfterEach
84+
public void afterEach() throws Exception {
85+
shutdownServers();
86+
CoordinatorMetrics.clear();
87+
}
88+
8689
@Test
8790
public void testUsingCustomExtraProperties() throws Exception {
88-
CoordinatorConf coordinatorConf = getCoordinatorConf();
91+
CoordinatorConf coordinatorConf = coordinatorConfWithoutPort();
8992
coordinatorConf.setString(
9093
"rss.coordinator.access.checkers",
9194
"org.apache.uniffle.test.AccessClusterTest$MockedAccessChecker");
92-
createCoordinatorServer(coordinatorConf);
93-
startServers();
95+
storeCoordinatorConf(coordinatorConf);
96+
startServersWithRandomPorts();
9497
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
9598
// case1: empty map
9699
String accessID = "acessid";
97100
RssAccessClusterRequest request =
98101
new RssAccessClusterRequest(
99102
accessID, Sets.newHashSet(Constants.SHUFFLE_SERVER_VERSION), 2000, "user");
103+
createClient();
100104
RssAccessClusterResponse response = coordinatorClient.accessCluster(request);
101105
assertEquals(StatusCode.ACCESS_DENIED, response.getStatusCode());
102106

@@ -125,8 +129,6 @@ public void testUsingCustomExtraProperties() throws Exception {
125129
"user");
126130
response = coordinatorClient.accessCluster(request);
127131
assertEquals(StatusCode.SUCCESS, response.getStatusCode());
128-
129-
shutdownServers();
130132
}
131133

132134
@Test
@@ -140,23 +142,23 @@ public void test(@TempDir File tempDir) throws Exception {
140142
printWriter.flush();
141143
printWriter.close();
142144

143-
CoordinatorConf coordinatorConf = getCoordinatorConf();
145+
CoordinatorConf coordinatorConf = coordinatorConfWithoutPort();
144146
coordinatorConf.setInteger("rss.coordinator.access.loadChecker.serverNum.threshold", 2);
145147
coordinatorConf.setString("rss.coordinator.access.candidates.path", cfgFile.getAbsolutePath());
146148
coordinatorConf.setString(
147149
"rss.coordinator.access.checkers",
148150
"org.apache.uniffle.coordinator.access.checker.AccessCandidatesChecker,"
149151
+ "org.apache.uniffle.coordinator.access.checker.AccessClusterLoadChecker");
150-
createCoordinatorServer(coordinatorConf);
152+
storeCoordinatorConf(coordinatorConf);
151153

152-
ShuffleServerConf shuffleServerConf = getShuffleServerConf(ServerType.GRPC);
153-
createShuffleServer(shuffleServerConf);
154-
startServers();
154+
storeShuffleServerConf(shuffleServerConfWithoutPort(0, tempDir, ServerType.GRPC));
155+
startServersWithRandomPorts();
155156
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
156157
String accessId = "111111";
157158
RssAccessClusterRequest request =
158159
new RssAccessClusterRequest(
159160
accessId, Sets.newHashSet(Constants.SHUFFLE_SERVER_VERSION), 2000, "user");
161+
createClient();
160162
RssAccessClusterResponse response = coordinatorClient.accessCluster(request);
161163
assertEquals(StatusCode.ACCESS_DENIED, response.getStatusCode());
162164
assertTrue(response.getMessage().startsWith("Denied by AccessCandidatesChecker"));
@@ -168,32 +170,19 @@ public void test(@TempDir File tempDir) throws Exception {
168170
response = coordinatorClient.accessCluster(request);
169171
assertEquals(StatusCode.ACCESS_DENIED, response.getStatusCode());
170172
assertTrue(response.getMessage().startsWith("Denied by AccessClusterLoadChecker"));
171-
172-
shuffleServerConf.setInteger(
173-
"rss.rpc.server.port", shuffleServerConf.getInteger(ShuffleServerConf.RPC_SERVER_PORT) + 2);
174-
shuffleServerConf.setInteger(
175-
"rss.jetty.http.port", shuffleServerConf.getInteger(ShuffleServerConf.JETTY_HTTP_PORT) + 1);
173+
ShuffleServerConf shuffleServerConf = shuffleServerConfWithoutPort(0, tempDir, ServerType.GRPC);
174+
shuffleServerConf.setString("rss.coordinator.quorum", getQuorum());
176175
ShuffleServer shuffleServer = new ShuffleServer(shuffleServerConf);
177176
shuffleServer.start();
177+
// this make sure the server can be shutdown
178+
grpcShuffleServers.add(shuffleServer);
178179
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
179180

180-
CoordinatorClient client =
181-
CoordinatorClientFactory.getInstance()
182-
.createCoordinatorClient(ClientType.GRPC, LOCALHOST, COORDINATOR_PORT_1 + 13);
183-
request =
184-
new RssAccessClusterRequest(
185-
accessId, Sets.newHashSet(Constants.SHUFFLE_SERVER_VERSION), 2000, "user");
186-
response = client.accessCluster(request);
187-
assertEquals(StatusCode.INTERNAL_ERROR, response.getStatusCode());
188-
assertTrue(response.getMessage().startsWith("UNAVAILABLE: io exception"));
189-
190181
request =
191182
new RssAccessClusterRequest(
192183
accessId, Sets.newHashSet(Constants.SHUFFLE_SERVER_VERSION), 2000, "user");
193184
response = coordinatorClient.accessCluster(request);
194185
assertEquals(StatusCode.SUCCESS, response.getStatusCode());
195186
assertTrue(response.getMessage().startsWith("SUCCESS"));
196-
shuffleServer.stopServer();
197-
shutdownServers();
198187
}
199188
}

integration-test/common/src/test/java/org/apache/uniffle/test/CoordinatorAdminServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void setUp() throws Exception {
5252

5353
@BeforeEach
5454
public void createClient() {
55-
String hostUrl = String.format("http://%s:%d", LOCALHOST, jettyPorts.get(0));
55+
String hostUrl = String.format("http://%s:%d", LOCALHOST, coordinators.get(0).getJettyPort());
5656
adminRestApi = new AdminRestApi(UniffleRestClient.builder(hostUrl).build());
5757
}
5858

integration-test/common/src/test/java/org/apache/uniffle/test/CoordinatorGrpcTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public void getShuffleAssignmentsTest(@TempDir File tmpDir) throws Exception {
143143
CoordinatorTestUtils.waitForRegister(coordinatorClient, 2);
144144

145145
grpcShuffleServers.get(0).stopServer();
146-
List<Integer> ports = reserveJettyPorts(1);
147146
ShuffleServerConf shuffleServerConf = shuffleServerConfWithoutPort(0, tmpDir, ServerType.GRPC);
148147
shuffleServerConf.set(ShuffleServerConf.STORAGE_MEDIA_PROVIDER_ENV_KEY, "RSS_ENV_KEY");
149148
String baseDir = shuffleServerConf.get(ShuffleServerConf.RSS_STORAGE_BASE_PATH).get(0);
@@ -154,7 +153,7 @@ public void getShuffleAssignmentsTest(@TempDir File tmpDir) throws Exception {
154153
() -> {
155154
shuffleServerConf.setString("rss.coordinator.quorum", getQuorum());
156155
shuffleServerConf.setInteger(RssBaseConf.RPC_SERVER_PORT, 0);
157-
shuffleServerConf.setInteger(RssBaseConf.JETTY_HTTP_PORT, ports.get(0));
156+
shuffleServerConf.setInteger(RssBaseConf.JETTY_HTTP_PORT, 0);
158157
ShuffleServer ss = new ShuffleServer(shuffleServerConf);
159158
ss.start();
160159
grpcShuffleServers.set(0, ss);
@@ -298,7 +297,6 @@ public void shuffleServerHeartbeatTest(@TempDir File tempDir) throws Exception {
298297
assertTrue(node.getTags().contains(Constants.SHUFFLE_SERVER_VERSION));
299298
assertTrue(scm.getTagToNodes().get(Constants.SHUFFLE_SERVER_VERSION).contains(node));
300299

301-
List<Integer> ports = reserveJettyPorts(1);
302300
ShuffleServerConf shuffleServerConf = shuffleServerConfWithoutPort(0, tempDir, ServerType.GRPC);
303301
shuffleServerConf.set(ShuffleServerConf.STORAGE_MEDIA_PROVIDER_ENV_KEY, "RSS_ENV_KEY");
304302
String baseDir = shuffleServerConf.get(ShuffleServerConf.RSS_STORAGE_BASE_PATH).get(0);
@@ -311,7 +309,7 @@ public void shuffleServerHeartbeatTest(@TempDir File tempDir) throws Exception {
311309
shuffleServerConf.set(ShuffleServerConf.TAGS, Lists.newArrayList("SSD"));
312310
shuffleServerConf.setString("rss.coordinator.quorum", getQuorum());
313311
shuffleServerConf.setInteger(RssBaseConf.RPC_SERVER_PORT, 0);
314-
shuffleServerConf.setInteger(RssBaseConf.JETTY_HTTP_PORT, ports.get(0));
312+
shuffleServerConf.setInteger(RssBaseConf.JETTY_HTTP_PORT, 0);
315313
ShuffleServer ss = new ShuffleServer(shuffleServerConf);
316314
ss.start();
317315
grpcShuffleServers.set(0, ss);

0 commit comments

Comments
 (0)