Skip to content

Commit 216efb7

Browse files
authored
[Improve] add test case (#6536)
1 parent b0d70ce commit 216efb7

File tree

1 file changed

+106
-0
lines changed
  • seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e

1 file changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.engine.e2e;
19+
20+
import org.apache.seatunnel.engine.client.SeaTunnelClient;
21+
import org.apache.seatunnel.engine.common.config.ConfigProvider;
22+
import org.apache.seatunnel.engine.common.config.SeaTunnelConfig;
23+
import org.apache.seatunnel.engine.server.SeaTunnelServerStarter;
24+
25+
import org.junit.jupiter.api.Assertions;
26+
import org.junit.jupiter.api.Test;
27+
28+
import com.hazelcast.client.config.ClientConfig;
29+
import com.hazelcast.config.Config;
30+
import com.hazelcast.instance.impl.HazelcastInstanceImpl;
31+
32+
import java.util.Collections;
33+
import java.util.Map;
34+
35+
public class LocalModeIT {
36+
37+
SeaTunnelConfig seaTunnelConfig = ConfigProvider.locateAndGetSeaTunnelConfig();
38+
39+
@Test
40+
public void localModeWithPortNotInDefaultRange() {
41+
42+
HazelcastInstanceImpl node1 = null;
43+
SeaTunnelClient engineClient = null;
44+
try {
45+
Config hazelcastConfig = seaTunnelConfig.getHazelcastConfig();
46+
hazelcastConfig.getNetworkConfig().setPort(9999);
47+
SeaTunnelConfig updatedConfig = new SeaTunnelConfig();
48+
updatedConfig.setHazelcastConfig(hazelcastConfig);
49+
node1 = SeaTunnelServerStarter.createHazelcastInstance(updatedConfig);
50+
ClientConfig clientConfig = ConfigProvider.locateAndGetClientConfig();
51+
clientConfig
52+
.getConnectionStrategyConfig()
53+
.getConnectionRetryConfig()
54+
.setClusterConnectTimeoutMillis(3000);
55+
Assertions.assertThrows(
56+
IllegalStateException.class,
57+
() -> new SeaTunnelClient(clientConfig),
58+
"Unable to connect to any cluster.");
59+
} finally {
60+
if (engineClient != null) {
61+
engineClient.close();
62+
}
63+
if (node1 != null) {
64+
node1.shutdown();
65+
}
66+
}
67+
}
68+
69+
@Test
70+
public void localMode() {
71+
HazelcastInstanceImpl node1 = null;
72+
HazelcastInstanceImpl node2 = null;
73+
SeaTunnelClient engineClient = null;
74+
String cluster_name = "new_cluster_name";
75+
try {
76+
node1 = SeaTunnelServerStarter.createHazelcastInstance(seaTunnelConfig);
77+
78+
Config hazelcastConfig = seaTunnelConfig.getHazelcastConfig();
79+
hazelcastConfig.setClusterName(cluster_name).getNetworkConfig().setPort(9999);
80+
SeaTunnelConfig updatedConfig = new SeaTunnelConfig();
81+
updatedConfig.setHazelcastConfig(hazelcastConfig);
82+
node2 = SeaTunnelServerStarter.createHazelcastInstance(updatedConfig);
83+
84+
ClientConfig clientConfig = ConfigProvider.locateAndGetClientConfig();
85+
clientConfig.setClusterName(cluster_name);
86+
clientConfig
87+
.getNetworkConfig()
88+
.setAddresses(Collections.singletonList("localhost:9999"));
89+
engineClient = new SeaTunnelClient(clientConfig);
90+
91+
Map<String, String> clusterHealthMetrics = engineClient.getClusterHealthMetrics();
92+
Assertions.assertEquals(1, clusterHealthMetrics.size());
93+
Assertions.assertTrue(clusterHealthMetrics.containsKey("[localhost]:9999"));
94+
} finally {
95+
if (engineClient != null) {
96+
engineClient.close();
97+
}
98+
if (node1 != null) {
99+
node1.shutdown();
100+
}
101+
if (node2 != null) {
102+
node2.shutdown();
103+
}
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)