Skip to content

Commit

Permalink
fix(ct): add Multi cluster test
Browse files Browse the repository at this point in the history
  • Loading branch information
HJ-Young committed Sep 12, 2024
1 parent 956226e commit 4fa78c2
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/cluster-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
run: |
mvn clean package -U -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -ntp
- name: Run cluster test
- name: Run simple cluster test
run: |
mvn test -pl hugegraph-cluster-test/hugegraph-clustertest-test -am -P simple-cluster-test -DskipCommonsTests=true
- name: Run multi cluster test
run: |
mvn test -pl hugegraph-cluster-test/hugegraph-clustertest-test -am -P multi-cluster-test -DskipCommonsTests=true
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public AbstractNodeWrapper() {
this.configPath = getNodePath();
}

public AbstractNodeWrapper(int clusterIndex, int index) {
this.clusterIndex = clusterIndex;
this.index = index;
fileNames = new ArrayList<>();
this.configPath = getNodePath();
}

/**
* Node Dir should be created before changing Config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public PDNodeWrapper() {
}

public PDNodeWrapper(int clusterIndex, int index) {
super();
this.clusterIndex = clusterIndex;
this.index = index;
super(clusterIndex, index);
this.fileNames = new ArrayList<>(
Arrays.asList(LOG4J_FILE,
LICENSE_FILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
public class ServerNodeWrapper extends AbstractNodeWrapper {

public ServerNodeWrapper(int clusterIndex, int index) {
super();
this.clusterIndex = clusterIndex;
this.index = index;
super(clusterIndex, index);
this.fileNames = new ArrayList<>(
List.of(LOG4J_FILE,
HUGEGRAPH_SERVER_KEYSTORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public StoreNodeWrapper() {
}

public StoreNodeWrapper(int clusterId, int index) {
super();
super(clusterId, index);
this.fileNames = new ArrayList<>(
List.of(LOG4J_FILE));
this.clusterIndex = clusterId;
this.index = index;
this.workPath = STORE_LIB_PATH;
this.startLine = "o.a.h.s.n.StoreNodeApplication - Starting StoreNodeApplication";
createNodeDir(getNodePath() + CONF_DIR + File.separator);
Expand Down
12 changes: 12 additions & 0 deletions hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
</includes>
</configuration>
</execution>
<execution>
<id>multi-cluster-test</id>
<configuration>
<testSourceDirectory>${basedir}/src/main/java/
</testSourceDirectory>
<testClassesDirectory>${basedir}/target/classes/
</testClassesDirectory>
<includes>
<include>**/MultiClusterSuiteTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hugegraph.MultiClusterTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.hugegraph.ct.env.BaseEnv;
import org.apache.hugegraph.ct.env.MultiNodeEnv;
import org.junit.AfterClass;
import org.junit.BeforeClass;

public class BaseMultiClusterTest {

protected static BaseEnv env;

protected static Process p;

@BeforeClass
public static void initEnv() throws InterruptedException {
env = new MultiNodeEnv();
env.startCluster();
}

@AfterClass
public static void clearEnv() throws InterruptedException {
env.clearCluster();
Thread.sleep(2000);
}

protected String execCurl(String[] cmds) throws IOException {
ProcessBuilder process = new ProcessBuilder(cmds);
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
p.destroy();
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hugegraph.MultiClusterTest;

import java.io.IOException;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class MultiClusterDeployTest extends BaseMultiClusterTest {

@Test
public void testPDNodesDeployment() throws IOException {
List<String> addrs = env.getPDRestAddrs();
for (String addr : addrs) {
String url = addr;
String[] cmds = {"curl", url};
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cmds.length; i++) {
sb.append(cmds[i] + " ");
}
String responseMsg = execCurl(cmds);
Assert.assertEquals(responseMsg, "");
}
}

@Test
public void testStoreNodesDeployment() throws IOException, InterruptedException {
List<String> addrs = env.getStoreRestAddrs();
for (String addr : addrs) {
String url = addr;
String[] cmds = {"curl", url};
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cmds.length; i++) {
sb.append(cmds[i] + " ");
}
String responseMsg = execCurl(cmds);
Assert.assertTrue(responseMsg.startsWith("{"));
}
}

@Test
public void testServerNodesDeployment() throws IOException, InterruptedException {
List<String> addrs = env.getServerRestAddrs();
for (String addr : addrs) {
String url = addr;
String[] cmds = {"curl", url};
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cmds.length; i++) {
sb.append(cmds[i] + " ");
}
String responseMsg = execCurl(cmds);
Assert.assertTrue(responseMsg.startsWith("{"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hugegraph.MultiClusterTest;

import java.io.File;

import org.junit.Assert;
import org.junit.Test;

public class MultiClusterFileTest extends BaseMultiClusterTest {

@Test
public void checkPDNodeDir() {
for (String nodeDir : env.getPDNodeDir()) {
Assert.assertTrue(new File(nodeDir).isDirectory());
}
}

@Test
public void checkStoreNodeDir() {
for (String nodeDir : env.getStoreNodeDir()) {
Assert.assertTrue(new File(nodeDir).isDirectory());
}
}

@Test
public void checkServerNodeDir() {
for (String nodeDir : env.getServerNodeDir()) {
Assert.assertTrue(new File(nodeDir).isDirectory());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hugegraph.MultiClusterTest;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import lombok.extern.slf4j.Slf4j;

@RunWith(Suite.class)
@Suite.SuiteClasses({
MultiClusterDeployTest.class,
MultiClusterFileTest.class,
})
@Slf4j
public class MultiClusterSuiteTest {

}
24 changes: 24 additions & 0 deletions hugegraph-cluster-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@
</plugins>
</build>
</profile>
<profile>
<id>multi-cluster-test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<executions>
<execution>
<id>multi-cluster-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>

0 comments on commit 4fa78c2

Please sign in to comment.