Skip to content
Permalink
Browse files
Integration grpc tri test config
  • Loading branch information
EarthChen committed Sep 15, 2021
1 parent 50f9340 commit 18c53f36d39b4cfdffd17c75363b6502809bb4ca
Showing 7 changed files with 86 additions and 22 deletions.
@@ -24,14 +24,18 @@ services:
type: test
basedir: .
tests:
# tri-->tri
- "org.apache.dubbo.sample.tri/Tri*Test.class"
# grpc consumer
# grpc-->tri
- "org.apache.dubbo.sample.tri/grpc/Grpc*Test.class"
# tri-->grpc
- "org.apache.dubbo.sample.tri.grpc/TriGrpcDirectPbConsumerTest.class"
systemProps:
- zookeeper.host=dubbo-samples-triple
- zookeeper.port=2181
- provider.host=dubbo-samples-triple
- provider.port=50052
- grpc.provider.port=50053
waitPortsBeforeRun:
- dubbo-samples-triple:2181
- dubbo-samples-triple:50052
@@ -40,23 +44,21 @@ services:

################################################
# grpc provider
dubbo-samples-triple-grpc:
type: app
basedir: .
mainClass: org.apache.dubbo.sample.tri.grpc.GrpcProvider

dubbo-samples-triple-grpc-test:
type: test
basedir: .
tests:
- "org.apache.dubbo.sample.tri.direct/TriDirectPbConsumerTest.class"
systemProps:
- provider.host=dubbo-samples-triple-grpc
- provider.port=50052
waitPortsBeforeRun:
- dubbo-samples-triple-grpc:50052
depends_on:
- dubbo-samples-triple-grpc
# dubbo-samples-triple-grpc:
# type: app
# basedir: .
# mainClass: org.apache.dubbo.sample.tri.grpc.GrpcProvider
#
# dubbo-samples-triple-grpc-test:
# type: test
# basedir: .
# tests:
# systemProps:
# - provider.host=dubbo-samples-triple-grpc
# waitPortsBeforeRun:
# - dubbo-samples-triple-grpc:50052
# depends_on:
# - dubbo-samples-triple-grpc



@@ -6,15 +6,27 @@
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.grpc.GrpcProvider;
import org.apache.dubbo.sample.tri.service.impl.PbGreeterImpl;
import org.apache.dubbo.sample.tri.service.PbGreeterManual;
import org.apache.dubbo.sample.tri.service.WrapGreeter;
import org.apache.dubbo.sample.tri.service.impl.WrapGreeterImpl;

import java.io.IOException;


public class TriProvider {

public static void main(String[] args) {
public static void main(String[] args) throws IOException, InterruptedException {
new Thread(()->{
try {
GrpcProvider.main(new String[0]);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
new EmbeddedZooKeeper(TriSampleConstants.ZK_PORT, false).start();

ServiceConfig<PbGreeter> pbService = new ServiceConfig<>();
@@ -28,7 +28,9 @@
public class TriSampleConstants {

// macos 11 later the 50051 is occupied by system (pid=1!!!)
public static final int SERVER_PORT = Integer.parseInt(System.getProperty("provider.port", "50052"));
public static final int SERVER_PORT = Integer.parseInt(System.getProperty("provider.port", "50052"));

public static final int GRPC_SERVER_PORT = Integer.parseInt(System.getProperty("grpc.provider.port", "50053"));

public static final int DEFAULT_DUBBO_PORT = 20880;

@@ -51,4 +53,7 @@ public class TriSampleConstants {
public static final String DEFAULT_ADDRESS = CommonConstants.TRIPLE + "://" + HOST + ":" + SERVER_PORT;

public static final String DEFAULT_MULTI_ADDRESS = CommonConstants.TRIPLE + "://" + HOST + ":" + SERVER_PORT + ";" + CommonConstants.TRIPLE + "://" + LOCAL_HOST + ":" + SERVER_PORT;

public static final String GRPC_DEFAULT_ADDRESS = CommonConstants.TRIPLE + "://" + HOST + ":" + GRPC_SERVER_PORT;

}
@@ -18,7 +18,7 @@

public class GrpcProvider {
public static void main(String[] args) throws IOException, InterruptedException {
final Server server = ServerBuilder.forPort(TriSampleConstants.SERVER_PORT)
final Server server = ServerBuilder.forPort(TriSampleConstants.GRPC_SERVER_PORT)
.addService(ServerInterceptors.intercept(new GrpcPbGreeterImpl(new PbGreeterImpl()), new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall,
@@ -23,7 +23,7 @@ public class GrpcConsumerTest {

@BeforeClass
public static void init() {
final ManagedChannel channel = ManagedChannelBuilder.forAddress(TriSampleConstants.HOST, TriSampleConstants.SERVER_PORT)
final ManagedChannel channel = ManagedChannelBuilder.forAddress(TriSampleConstants.HOST, TriSampleConstants.GRPC_SERVER_PORT)
.usePlaintext()
.build();
stub = PbGreeterGrpc.newStub(channel);
@@ -0,0 +1,42 @@
package org.apache.dubbo.sample.tri.grpc;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.BasePbConsumerTest;
import org.apache.dubbo.sample.tri.PbGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;
import org.apache.dubbo.sample.tri.service.PbGreeterManual;

import org.junit.BeforeClass;

public class TriGrpcDirectPbConsumerTest extends BasePbConsumerTest {

@BeforeClass
public static void init() {
ReferenceConfig<PbGreeter> ref = new ReferenceConfig<>();
ref.setInterface(PbGreeter.class);
ref.setCheck(false);
ref.setUrl(TriSampleConstants.DEFAULT_ADDRESS);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);
ref.setTimeout(10000);

ReferenceConfig<PbGreeterManual> ref2 = new ReferenceConfig<>();
ref2.setInterface(PbGreeterManual.class);
ref2.setCheck(false);
ref2.setUrl(TriSampleConstants.DEFAULT_ADDRESS);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);
ref2.setTimeout(10000);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-consumer"))
.reference(ref)
.reference(ref2)
.start();
delegate = ref.get();
delegateManual = ref2.get();
}
}
@@ -112,6 +112,9 @@ function process_case() {
case_dir=$1
case_no=$2

echo "case_dir=$case_dir"
echo "case_no=$case_no"

if [ -f $case_dir ]; then
case_dir=`dirname $case_dir`
fi

0 comments on commit 18c53f3

Please sign in to comment.