Skip to content
Permalink
Browse files
adjust samples to work with 2.7.5-SNAPSHOT
  • Loading branch information
chickenlj committed Oct 30, 2019
1 parent 3fd4431 commit 64a40f07cc39ae9f89a37b512c9b6c537c2ea390
Showing 21 changed files with 72 additions and 65 deletions.
@@ -32,7 +32,7 @@ public String sayHello(String name) {
RpcContext context = RpcContext.getContext();

// the attachment will be remove after this
String index = context.getAttachment("index");
String index = (String) context.getAttachment("index");
System.out.println("receive attachment index: " + index);

System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name +
@@ -18,7 +18,6 @@
package org.apache.dubbo.samples.chain;

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.samples.chain.api.AmericanService;
import org.apache.dubbo.samples.chain.api.CatService;
import org.apache.dubbo.samples.chain.api.ChineseService;
@@ -31,6 +30,8 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;

public class FrontendConsumer {

private static ExecutorService executorService = Executors.newFixedThreadPool(3);
@@ -65,7 +66,7 @@ public static void dog(ClassPathXmlApplicationContext context) {
executorService.submit(() -> {
while (true) {
try {
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
DogService dogService = (DogService) context.getBean("dogService");
System.out.println(dogService.dog());
Thread.sleep(interval);
@@ -100,7 +101,7 @@ public static void chinese(ClassPathXmlApplicationContext context) {
executorService.submit(() -> {
while (true) {
try {
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
ChineseService chineseService = (ChineseService) context.getBean("chineseService");
System.out.println(chineseService.eat());
Thread.sleep(interval);
@@ -115,7 +116,7 @@ public static void american(ClassPathXmlApplicationContext context) {
executorService.submit(() -> {
while (true) {
try {
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
AmericanService americanService = (AmericanService) context.getBean("americanService");
System.out.println(americanService.eat());
Thread.sleep(interval);
@@ -20,12 +20,12 @@
package org.apache.dubbo.samples.governance;

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.samples.governance.api.DemoService;
import org.apache.dubbo.samples.governance.api.DemoService2;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;

public class BasicConsumer {
@@ -36,12 +36,12 @@ public static void main(String[] args) {
DemoService demoService = context.getBean("demoService", DemoService.class);
DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);

RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
String hello = demoService.sayHello("world");
System.out.println(hello);

RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
RpcContext.getContext().setAttachment(TAG_KEY, "tag2");
String hello2 = demoService2.sayHello("world again");
System.out.println(hello2);
}
@@ -19,7 +19,6 @@

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.samples.governance.api.DemoService;

import org.junit.Assert;
@@ -31,6 +30,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;

@RunWith(SpringJUnit4ClassRunner.class)
@@ -51,7 +51,7 @@ public static void setUp() throws Exception {
public void testDemoService1() throws Exception {
for (int i = 0; i < 10; i++) {
RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
Assert.assertTrue(demoService.sayHello("world").contains("20881"));
}
}
@@ -60,14 +60,14 @@ public void testDemoService1() throws Exception {
public void testDemoService2() throws Exception {
for (int i = 0; i < 10; i++) {
RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
RpcContext.getContext().setAttachment(TAG_KEY, "tag2");
Assert.assertTrue(demoService.sayHello("world").contains("20880"));
}
}

@Test(expected = RpcException.class)
public void testDemoService3() throws Exception {
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag3");
RpcContext.getContext().setAttachment(TAG_KEY, "tag3");
demoService.sayHello("world");
}
}
@@ -233,10 +233,10 @@ public static class DubboGreeterStub implements IGreeter {
private GreeterFutureStub futureStub;
private GreeterStub stub;

public DubboGreeterStub(io.grpc.Channel channel) {
blockingStub = GreeterGrpc.newBlockingStub(channel);
futureStub = GreeterGrpc.newFutureStub(channel);
stub = GreeterGrpc.newStub(channel);
public DubboGreeterStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
blockingStub = GreeterGrpc.newBlockingStub(channel).build(channel, callOptions);
futureStub = GreeterGrpc.newFutureStub(channel).build(channel, callOptions);
stub = GreeterGrpc.newStub(channel).build(channel, callOptions);
}

public io.grpc.examples.helloworld.HelloReply sayHello(io.grpc.examples.helloworld.HelloRequest request) {
@@ -255,9 +255,10 @@ public void sayHello(io.grpc.examples.helloworld.HelloRequest request,

}

public static DubboGreeterStub getDubboStub(io.grpc.Channel channel) {
public static DubboGreeterStub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {

return new DubboGreeterStub(channel);}
return new DubboGreeterStub(channel, callOptions);
}

private static final int METHODID_SAY_HELLO = 0;

@@ -2,18 +2,8 @@

import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;

/**
* <pre>
@@ -200,10 +190,10 @@ public static class DubboStreamingGreeterStub implements IStreamingGreeter {
private StreamingGreeterFutureStub futureStub;
private StreamingGreeterStub stub;

public DubboStreamingGreeterStub(io.grpc.Channel channel) {
blockingStub = StreamingGreeterGrpc.newBlockingStub(channel);
futureStub = StreamingGreeterGrpc.newFutureStub(channel);
stub = StreamingGreeterGrpc.newStub(channel);
public DubboStreamingGreeterStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
blockingStub = StreamingGreeterGrpc.newBlockingStub(channel).build(channel, callOptions);
futureStub = StreamingGreeterGrpc.newFutureStub(channel).build(channel, callOptions);
stub = StreamingGreeterGrpc.newStub(channel).build(channel, callOptions);
}

public io.grpc.stub.StreamObserver<io.grpc.examples.manualflowcontrol.HelloRequest> sayHelloStreaming(
@@ -213,9 +203,10 @@ public io.grpc.stub.StreamObserver<io.grpc.examples.manualflowcontrol.HelloReque

}

public static DubboStreamingGreeterStub getDubboStub(io.grpc.Channel channel) {
public static DubboStreamingGreeterStub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {

return new DubboStreamingGreeterStub(channel);}
return new DubboStreamingGreeterStub(channel, callOptions);
}

private static final int METHODID_SAY_HELLO_STREAMING = 0;

@@ -458,10 +458,10 @@ public static class DubboRouteGuideStub implements IRouteGuide {
private RouteGuideFutureStub futureStub;
private RouteGuideStub stub;

public DubboRouteGuideStub(io.grpc.Channel channel) {
blockingStub = RouteGuideGrpc.newBlockingStub(channel);
futureStub = RouteGuideGrpc.newFutureStub(channel);
stub = RouteGuideGrpc.newStub(channel);
public DubboRouteGuideStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
blockingStub = RouteGuideGrpc.newBlockingStub(channel).build(channel, callOptions);
futureStub = RouteGuideGrpc.newFutureStub(channel).build(channel, callOptions);
stub = RouteGuideGrpc.newStub(channel).build(channel, callOptions);
}

public io.grpc.examples.routeguide.Feature getFeature(io.grpc.examples.routeguide.Point request) {
@@ -500,9 +500,10 @@ public io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.RouteNote> routeC

}

public static DubboRouteGuideStub getDubboStub(io.grpc.Channel channel) {
public static DubboRouteGuideStub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {

return new DubboRouteGuideStub(channel);}
return new DubboRouteGuideStub(channel, callOptions);
}

private static final int METHODID_GET_FEATURE = 0;
private static final int METHODID_LIST_FEATURES = 1;
@@ -28,7 +28,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>2.7.4-performance-SNAPSHOT</dubbo.version>
<dubbo.version>2.7.5-SNAPSHOT</dubbo.version>
<junit.version>4.12</junit.version>
<spring-test.version>4.3.16.RELEASE</spring-test.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -17,7 +17,8 @@
package org.apache.dubbo.samples.metadatareport.configcenter;

import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -130,7 +131,7 @@ public static String getMetadata(String root, String serviceInterface, String ve
}

public static String getNodePath(String root, MetadataIdentifier metadataIdentifier) {
return toRootDir(root) + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
return toRootDir(root) + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
}

private static String toRootDir(String root) {
@@ -16,7 +16,8 @@
*/
package org.apache.dubbo.samples.metadatareport.local.annotation;

import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -45,7 +46,7 @@ public static String getMetadata(String root, String serviceInterface, String ve
}

public static String getNodePath(String root, MetadataIdentifier metadataIdentifier) {
return toRootDir(root) + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
return toRootDir(root) + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
}

private static String toRootDir(String root) {
@@ -16,7 +16,8 @@
*/
package org.apache.dubbo.samples.metadatareport.local.properties;

import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -44,7 +45,7 @@ public static String getMetadata(String root, String serviceInterface, String si
}

public static String getNodePath(String root, MetadataIdentifier metadataIdentifier) {
return toRootDir(root) + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
return toRootDir(root) + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
}

private static String toRootDir(String root) {
@@ -18,7 +18,8 @@
*/
package org.apache.dubbo.samples.metadatareport.local.xml;

import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -46,7 +47,7 @@ public static String getMetadata(String root, String serviceInterface, String si
}

public static String getNodePath(String root, MetadataIdentifier metadataIdentifier) {
return toRootDir(root) + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
return toRootDir(root) + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
}

private static String toRootDir(String root) {
@@ -20,12 +20,12 @@
package org.apache.dubbo.samples.governance;

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.samples.governance.api.DemoService;
import org.apache.dubbo.samples.governance.api.DemoService2;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;

public class BasicConsumer {
@@ -36,12 +36,12 @@ public static void main(String[] args) throws Exception {
DemoService demoService = context.getBean("demoService", DemoService.class);
DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);

RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
String hello = demoService.sayHello("world");
System.out.println(hello);

RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
RpcContext.getContext().setAttachment(TAG_KEY, "tag2");
String hello2 = demoService2.sayHello("world again");
System.out.println(hello2);
}
@@ -19,9 +19,9 @@

import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.samples.governance.api.DemoService;
import org.apache.dubbo.samples.governance.util.NacosUtils;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -32,6 +32,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;

@RunWith(SpringJUnit4ClassRunner.class)
@@ -56,7 +57,7 @@ public static void tearDown() throws Throwable {
public void testDemoService1() throws Exception {
for (int i = 0; i < 10; i++) {
RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
RpcContext.getContext().setAttachment(TAG_KEY, "tag1");
Assert.assertTrue(demoService.sayHello("world").contains("20881"));
}
}
@@ -65,14 +66,14 @@ public void testDemoService1() throws Exception {
public void testDemoService2() throws Exception {
for (int i = 0; i < 10; i++) {
RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
RpcContext.getContext().setAttachment(TAG_KEY, "tag2");
Assert.assertTrue(demoService.sayHello("world").contains("20880"));
}
}

@Test(expected = RpcException.class)
public void testDemoService3() throws Exception {
RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag3");
RpcContext.getContext().setAttachment(TAG_KEY, "tag3");
demoService.sayHello("world");
}
}
@@ -42,7 +42,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bom</artifactId>
<version>2.7.4-performance-SNAPSHOT</version>
<version>2.7.5-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

0 comments on commit 64a40f0

Please sign in to comment.