Skip to content
Permalink
Browse files
Add pb test
  • Loading branch information
guohao committed Sep 2, 2021
1 parent b1fd2f2 commit c4776a983add38984d7e22239fce0305b77fdb52
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
@@ -24,7 +24,7 @@ public static void init() {
ref.setGeneric("true");
ref.setLazy(true);
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("generic-consumer"))
bootstrap.application(new ApplicationConfig("demo-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(ref)
.start();
@@ -1,4 +1,88 @@
package org.apache.dubbo.sample.tri;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.hello.HelloReply;
import org.apache.dubbo.hello.HelloRequest;

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

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class PbTest {
private static PbGreeter delegate;

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

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(ref)
.start();

delegate = ref.get();
}

@Test
public void serverStream() throws InterruptedException {
int n = 10;
CountDownLatch latch = new CountDownLatch(n);
final HelloRequest request = HelloRequest.newBuilder()
.setName("request")
.build();
delegate.sayHelloServerStream(request, new StdoutStreamObserver<HelloReply>("sayHelloServerStream") {
@Override
public void onNext(HelloReply data) {
super.onNext(data);
latch.countDown();
}
});
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
}

@Test
public void stream() throws InterruptedException {
int n = 10;
CountDownLatch latch = new CountDownLatch(n);
final HelloRequest request = HelloRequest.newBuilder()
.setName("stream request")
.build();
final StreamObserver<HelloRequest> requestObserver = delegate.sayHelloStream(new StdoutStreamObserver<HelloReply>("sayHelloStream") {
@Override
public void onNext(HelloReply data) {
super.onNext(data);
latch.countDown();
}
});
for (int i = 0; i < n; i++) {
requestObserver.onNext(request);
}
requestObserver.onCompleted();
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
}

@Test
public void unaryHello() {
final HelloReply reply = delegate.sayHello(HelloRequest.newBuilder()
.setName("name")
.build());
Assert.assertNotNull(reply);
}

}
@@ -10,9 +10,9 @@

public class TestProvider {
public static void main(String[] args) {
// ServiceConfig<PbGreeter> pbService = new ServiceConfig<>();
// pbService.setInterface(IGreeter.class);
// pbService.setRef(new IGreeter1Impl());
ServiceConfig<PbGreeter> pbService = new ServiceConfig<>();
pbService.setInterface(PbGreeter.class);
pbService.setRef(new PbGreeterImpl());

ServiceConfig<WrapGreeter> wrapService = new ServiceConfig<>();
wrapService.setInterface(WrapGreeter.class);
@@ -23,7 +23,7 @@ public static void main(String[] args) {
bootstrap.application(new ApplicationConfig("demo-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
// .service(pbService)
.service(pbService)
.service(wrapService)
.start()
.await();

0 comments on commit c4776a9

Please sign in to comment.