Skip to content
Permalink
Browse files
Merge pull request #367 from EarthChen/feat-url-call
[Triple] add url call test
  • Loading branch information
guohao committed Sep 17, 2021
2 parents a92b10f + 12b90bb commit 2a36f47c762a319623d568081455586f78d2876e
Showing 14 changed files with 113 additions and 25 deletions.
@@ -32,11 +32,13 @@ services:
- "org.apache.dubbo.sample.tri/TriPbConsumerTest.class"
- "org.apache.dubbo.sample.tri/TriWrapConsumerTest.class"
- "org.apache.dubbo.sample.tri/TriGenericTest.class"
# use url direct
- "org.apache.dubbo.sample.tri/direct/TriDirectPbConsumerTest.class"
- "org.apache.dubbo.sample.tri/direct/TriDirectWrapConsumerTest.class"
# grpc-->tri
- "org.apache.dubbo.sample.tri/grpc/Grpc*Test.class"
# tri-->grpc
# fixme Failure is always present (https://github.com/apache/dubbo/issues/8738)
#- "org.apache.dubbo.sample.tri.grpc/TriGrpcDirectPbConsumerTest.class"
- "org.apache.dubbo.sample.tri.grpc/TriGrpcDirectPbConsumerTest.class"
systemProps:
- zookeeper.host=dubbo-samples-triple
- zookeeper.port=2181
@@ -18,7 +18,7 @@
#

###set log levels###
log4j.rootLogger=debug, stdout
log4j.rootLogger=info, stdout
###output to the console###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
@@ -6,9 +6,9 @@
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.sample.tri.helper.StdoutStreamObserver;
import org.apache.dubbo.sample.tri.service.PbGreeterManual;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
@@ -24,6 +24,8 @@ public abstract class BasePbConsumerTest {

protected static PbGreeterManual delegateManual;

protected static DubboBootstrap appDubboBootstrap;

@Test
public void serverStream() throws InterruptedException {
int n = 10;
@@ -85,6 +87,7 @@ public void clientSendLargeSizeHeader() {


@Test(expected = RpcException.class)
@Ignore
public void serverSendLargeSizeHeader() {
final String key = "user-attachment";
GreeterReply reply = delegateManual.greetReturnBigAttachment(GreeterRequest.newBuilder().setName("meta").build());
@@ -128,6 +131,7 @@ public void methodNotFound() {

@AfterClass
public static void alterTest() {
appDubboBootstrap.stop();
DubboBootstrap.reset();
}

@@ -17,6 +17,11 @@ public class BaseTriWrapConsumerTest {

protected static WrapGreeter delegate;

protected static WrapGreeter longDelegate;

protected static DubboBootstrap appDubboBootstrap;


@Test
public void sayHelloUnaryRequestVoid() {
Assert.assertEquals("hello!void", delegate.sayHelloRequestVoid());
@@ -116,7 +121,7 @@ public void sayHelloLong() {
int power = 25;
for (int i = 0; i < power; i++) {
final int len = (1 << i);
final String response = delegate.sayHelloLong(len);
final String response = longDelegate.sayHelloLong(len);
System.out.println("Response len:" + response.length());
Assert.assertEquals(len, response.length());
}
@@ -16,23 +16,45 @@
public class TriGenericTest {
private static GenericService generic;


private static GenericService longGeneric;


protected static DubboBootstrap appDubboBootstrap;


@BeforeClass
public static void init() {
ReferenceConfig<GenericService> ref = new ReferenceConfig<>();
ref.setInterface("org.apache.dubbo.sample.tri.service.WrapGreeter");
ref.setCheck(false);
ref.setTimeout(30000);
ref.setTimeout(3000);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setGeneric("true");
ref.setLazy(true);

ReferenceConfig<GenericService> ref2 = new ReferenceConfig<>();
ref2.setInterface("org.apache.dubbo.sample.tri.service.WrapGreeter");
ref2.setCheck(false);
ref2.setTimeout(15000);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setGeneric("true");
ref2.setRetries(0);
ref2.setLazy(true);


DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriGenericTest.class.getName());
applicationConfig.setMetadataServicePort(TriSampleConstants.CONSUMER_METADATA_SERVICE_PORT);
bootstrap.application(applicationConfig)
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.reference(ref)
.reference(ref2)
.start();
generic = ref.get();
longGeneric = ref2.get();

appDubboBootstrap = bootstrap;
}

@Test
@@ -64,14 +86,16 @@ public void notFoundMethod() {

@Test
public void sayHelloLong() {
int len = 2 << 24;
final String resp = (String) generic.$invoke("sayHelloLong", new String[]{int.class.getName()}, new Object[]{len});
int len = 2 << 12;
final String resp = (String) longGeneric.$invoke("sayHelloLong", new String[]{int.class.getName()},
new Object[]{len});
Assert.assertEquals(len, resp.length());
}


@AfterClass
public static void alterTest() {
appDubboBootstrap.stop();
DubboBootstrap.reset();
}
}
@@ -18,14 +18,14 @@ public static void init() {
ref.setCheck(false);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);
ref.setTimeout(10000);
ref.setTimeout(3000);

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

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriPbConsumerTest.class.getName());
@@ -38,5 +38,6 @@ public static void init() {

delegate = ref.get();
delegateManual = ref2.get();
appDubboBootstrap = bootstrap;
}
}
@@ -22,6 +22,10 @@ public class TriWrapConsumerTest {

private static WrapGreeter delegate;

protected static WrapGreeter longDelegate;

protected static DubboBootstrap appDubboBootstrap;

@BeforeClass
public static void initStub() {
ReferenceConfig<WrapGreeter> ref = new ReferenceConfig<>();
@@ -31,14 +35,27 @@ public static void initStub() {
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);


ReferenceConfig<WrapGreeter> ref2 = new ReferenceConfig<>();
ref2.setInterface(WrapGreeter.class);
ref2.setCheck(false);
ref2.setTimeout(15000);
ref2.setRetries(0);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriWrapConsumerTest.class.getName());
applicationConfig.setMetadataServicePort(TriSampleConstants.CONSUMER_METADATA_SERVICE_PORT);
bootstrap.application(applicationConfig)
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.reference(ref)
.reference(ref2)
.start();
delegate = ref.get();
longDelegate = ref2.get();
appDubboBootstrap = bootstrap;

}

@Test
@@ -121,7 +138,8 @@ public void onCompleted() {
public void sayHelloStream() throws InterruptedException {
int n = 10;
CountDownLatch latch = new CountDownLatch(n);
final StreamObserver<String> request = delegate.sayHelloStream(new StdoutStreamObserver<String>("sayHelloStream") {
final StreamObserver<String> request = delegate.sayHelloStream(new StdoutStreamObserver<String>(
"sayHelloStream") {
@Override
public void onNext(String data) {
super.onNext(data);
@@ -140,14 +158,15 @@ public void sayHelloLong() {
int power = 25;
for (int i = 0; i < power; i++) {
final int len = (1 << i);
final String response = delegate.sayHelloLong(len);
final String response = longDelegate.sayHelloLong(len);
System.out.println("Response len:" + response.length());
Assert.assertEquals(len, response.length());
}
}

@AfterClass
public static void alterTest() {
appDubboBootstrap.stop();
DubboBootstrap.reset();
}
}
@@ -40,5 +40,6 @@ public static void init() {
.start();
delegate = ref.get();
delegateManual = ref2.get();
appDubboBootstrap=bootstrap;
}
}
@@ -7,9 +7,7 @@
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.BaseTriWrapConsumerTest;
import org.apache.dubbo.sample.tri.TriSampleConstants;
import org.apache.dubbo.sample.tri.direct.TriDirectWrapConsumerTest;
import org.apache.dubbo.sample.tri.service.WrapGreeter;

import org.junit.BeforeClass;

public class TriAppWrapConsumerTest extends BaseTriWrapConsumerTest {
@@ -23,14 +21,25 @@ public static void initStub() {
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);

ReferenceConfig<WrapGreeter> ref2 = new ReferenceConfig<>();
ref2.setInterface(WrapGreeter.class);
ref2.setCheck(false);
ref2.setTimeout(15000);
ref2.setRetries(0);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriAppWrapConsumerTest.class.getName());
applicationConfig.setMetadataServicePort(TriSampleConstants.CONSUMER_METADATA_SERVICE_PORT);
bootstrap.application(applicationConfig)
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS_MODE_INSTANCE))
.reference(ref)
.reference(ref2)
.start();
delegate = ref.get();
longDelegate = ref2.get();
appDubboBootstrap = bootstrap;
}

}
@@ -6,10 +6,8 @@
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.TriGenericTest;
import org.apache.dubbo.sample.tri.TriSampleConstants;
import org.apache.dubbo.sample.tri.service.PbGreeterManual;

import org.junit.BeforeClass;

public class TriDirectPbConsumerTest extends BasePbConsumerTest {
@@ -22,15 +20,15 @@ public static void init() {
ref.setUrl(TriSampleConstants.DEFAULT_ADDRESS);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);
ref.setTimeout(10000);
ref.setTimeout(3000);

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

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriDirectPbConsumerTest.class.getName());
@@ -41,5 +39,6 @@ public static void init() {
.start();
delegate = ref.get();
delegateManual = ref2.get();
appDubboBootstrap = bootstrap;
}
}
@@ -22,13 +22,24 @@ public static void initStub() {
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);

ReferenceConfig<WrapGreeter> ref2 = new ReferenceConfig<>();
ref2.setInterface(WrapGreeter.class);
ref2.setCheck(false);
ref2.setTimeout(15000);
ref2.setUrl(TriSampleConstants.DEFAULT_ADDRESS);
ref2.setRetries(0);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig(TriDirectWrapConsumerTest.class.getName());
applicationConfig.setMetadataServicePort(TriSampleConstants.CONSUMER_METADATA_SERVICE_PORT);
bootstrap.application(applicationConfig)
.reference(ref)
.start();
delegate = ref.get();
longDelegate = ref2.get();
appDubboBootstrap = bootstrap;
}

}
@@ -8,7 +8,6 @@
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 {
@@ -21,22 +20,25 @@ public static void init() {
ref.setUrl(TriSampleConstants.DEFAULT_ADDRESS);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setLazy(true);
ref.setTimeout(10000);
ref.setTimeout(3000);

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);
ref2.setTimeout(3000);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-consumer"))
ApplicationConfig applicationConfig = new ApplicationConfig(TriGrpcDirectPbConsumerTest.class.getName());
applicationConfig.setMetadataServicePort(TriSampleConstants.CONSUMER_METADATA_SERVICE_PORT);
bootstrap.application(applicationConfig)
.reference(ref)
.reference(ref2)
.start();
delegate = ref.get();
delegateManual = ref2.get();
appDubboBootstrap=bootstrap;
}
}
@@ -8,9 +8,7 @@
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.application.TriAppWrapConsumerTest;
import org.apache.dubbo.sample.tri.service.PbGreeterManual;

import org.junit.BeforeClass;

public class TriInterfacePbConsumerTest extends BasePbConsumerTest {
@@ -41,5 +39,6 @@ public static void init() {
.start();
delegate = ref.get();
delegateManual = ref2.get();
appDubboBootstrap=bootstrap;
}
}

0 comments on commit 2a36f47

Please sign in to comment.