Skip to content

Commit db7a83c

Browse files
committed
# This is a combination of 2 commits.
# This is the 1st commit message: [WIP]Ftr: 支持java go集成测试互通 # The commit message #2 will be skipped: # 测试java测试的输出
1 parent 863cbac commit db7a83c

File tree

15 files changed

+121
-25
lines changed

15 files changed

+121
-25
lines changed

build/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,12 @@ integration: export DUBBO_GO_CONFIG_PATH ?= $(PROJECT_DIR)/go-client/conf/dubbog
156156
integration:
157157
$(info > Running integration test for application $(INTEGRATE_DIR))
158158
@go clean -testcache
159-
@go test -tags integration -v $(INTEGRATE_DIR)/tests/integration/...
159+
@go test -tags integration -v $(INTEGRATE_DIR)/tests/integration/...
160+
161+
## integration-java: Integration java test (for client)
162+
.PHONY: integration-java
163+
integration-java:
164+
@$(info > Running java test $(INTEGRATE_DIR), project name $(PROJECT_NAME))
165+
@chmod +x $(INTEGRATE_DIR)/tests/java/run.sh
166+
@$(shell )$(INTEGRATE_DIR)/tests/java/run.sh $(PROJECT_DIR)/java-client 2>&1 | tee $(LOG_FILE)
167+
@result=$? | exit $result

generic/default/java-client/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn install -DSkipTests
2-
mvn exec:java -Dexec.mainClass="org.apache.dubbo.ApiConsumer"
1+
mvn -e clean compile exec:java -Dexec.mainClass="org.apache.dubbo.ApiConsumer"

generic/default/java-server/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn install -DSkipTests
2-
mvn exec:java -Dexec.mainClass="org.apache.dubbo.ApiProvider"
1+
mvn -e clean compile exec:java -Dexec.mainClass="org.apache.dubbo.ApiProvider"

helloworld/java-client/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn install -DSkipTests
2-
mvn exec:java -Dexec.mainClass="com.apache.dubbo.sample.basic.ApiConsumer"
1+
mvn -e clean compile exec:java -Dexec.mainClass="com.apache.dubbo.sample.basic.ApiConsumer"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.apache.dubbo.sample;
2+
3+
import org.junit.Test;
4+
import junit.framework.TestCase;
5+
import static org.junit.Assert.*;
6+
7+
import org.apache.dubbo.common.constants.CommonConstants;
8+
import org.apache.dubbo.config.ApplicationConfig;
9+
import org.apache.dubbo.config.ReferenceConfig;
10+
import org.apache.dubbo.config.RegistryConfig;
11+
import org.apache.dubbo.sample.hello.Helloworld;
12+
13+
import java.io.IOException;
14+
import java.util.concurrent.TimeUnit;
15+
16+
import com.apache.dubbo.sample.basic.*;
17+
18+
public class TestHelloWorld {
19+
20+
@Test
21+
public void testHelloWorld() throws Exception {
22+
ReferenceConfig<IGreeter> ref = new ReferenceConfig<>();
23+
ref.setInterface(IGreeter.class);
24+
ref.setCheck(false);
25+
ref.setProtocol(CommonConstants.TRIPLE);
26+
ref.setLazy(true);
27+
ref.setTimeout(100000);
28+
ref.setApplication(new ApplicationConfig("demo-consumer"));
29+
ref.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
30+
final IGreeter iGreeter = ref.get();
31+
32+
System.out.println("dubbo ref started");
33+
Helloworld.HelloRequest req = Helloworld.HelloRequest.newBuilder().setName("laurence").build();
34+
try {
35+
final Helloworld.User reply = iGreeter.sayHello(req);
36+
TimeUnit.SECONDS.sleep(1);
37+
System.out.println("Reply:" + reply);
38+
TestCase.assertEquals(reply.getName(), "Hello laurence");
39+
TestCase.assertEquals(reply.getId(), "12345");
40+
TestCase.assertEquals(reply.getAge(), 21);
41+
} catch (Throwable t) {
42+
t.printStackTrace();
43+
System.exit(1);
44+
}
45+
}
46+
}

helloworld/java-server/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn install -DSkipTests
2-
mvn exec:java -Dexec.mainClass="com.apache.dubbo.sample.basic.ApiProvider"
1+
mvn -e clean compile exec:java -Dexec.mainClass="com.apache.dubbo.sample.basic.ApiProvider"

integrate_test.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,33 @@ INTEGRATE_DIR=$(pwd)/integrate_test/$1
3232
sleep 5
3333

3434
# start server
35-
make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" INTEGRATE_DIR="$INTEGRATE_DIR" -f build/Makefile start
35+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile start
3636
# waiting for registry
3737
sleep 5
3838

3939
# start integration
40-
make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" INTEGRATE_DIR="$INTEGRATE_DIR" -f build/Makefile integration
40+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile integration
4141
result=$?
4242

4343
# if fail print server log
4444
if [ $result != 0 ];then
45-
make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" INTEGRATE_DIR="$INTEGRATE_DIR" -f build/Makefile print-server-log
45+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile print-server-log
4646
fi
4747

48+
JAVA_TEST_SHELL=$INTEGRATE_DIR/tests/java
49+
if [ -e $JAVA_TEST_SHELL ]; then
50+
# run java test
51+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile integration-java
52+
result=$?
53+
54+
# if fail print server log
55+
if [ $result != 0 ];then
56+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile print-server-log
57+
fi
58+
fi
59+
60+
4861
# stop server
49-
make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" INTEGRATE_DIR="$INTEGRATE_DIR" -f build/Makefile clean
62+
make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) INTEGRATE_DIR=$INTEGRATE_DIR -f build/Makefile clean
5063

5164
exit $((result))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# !/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Provide test directory please, like : ./run.sh $(pwd)/helloworld/java-server"
5+
exit
6+
fi
7+
8+
cd $1
9+
10+
mvn test
11+
12+
result=$?
13+
if [ $result -gt 0 ]; then
14+
exit $result
15+
fi

rpc/dubbo/java-client/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn clean install -DSkipTests
2-
mvn -e exec:java -Dexec.mainClass="org.apache.dubbo.Consumer"
1+
mvn -e clean compile exec:java -Dexec.mainClass="org.apache.dubbo.Consumer"

rpc/dubbo/java-server/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mvn clean install -DSkipTests
2-
mvn -e exec:java -Dexec.mainClass="java.org.apache.dubbo.Provider"
1+
mvn -e clean compile exec:java -Dexec.mainClass="org.apache.dubbo.Provider"

0 commit comments

Comments
 (0)