Skip to content
Permalink
Browse files
add url direct test
  • Loading branch information
EarthChen committed Sep 9, 2021
1 parent 5a3b8e3 commit 183ad1434d6a87c22f212a4c99ab5559c6259223
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
@@ -18,6 +18,8 @@
package org.apache.dubbo.sample.tri;


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

import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTER_MODE_ALL;
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE;
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTER_MODE_INTERFACE;
@@ -32,13 +34,17 @@ public class TriSampleConstants {

public static final String ZK_ADDRESS = "zookeeper://127.0.0.1:2181";

public static final String ZK_ADDRESS_MODE_INSTANCE = "zookeeper://127.0.0.1:2181?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_INSTANCE;
public static final String ZK_ADDRESS_MODE_INSTANCE = ZK_ADDRESS + "?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_INSTANCE;

public static final String ZK_ADDRESS_MODE_INTERFACE = "zookeeper://127.0.0.1:2181?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_INTERFACE;
public static final String ZK_ADDRESS_MODE_INTERFACE = ZK_ADDRESS + "?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_INTERFACE;

public static final String ZK_ADDRESS_MODE_ALL = "zookeeper://127.0.0.1:2181?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_ALL;
public static final String ZK_ADDRESS_MODE_ALL = ZK_ADDRESS + "?" + REGISTER_MODE_KEY + "=" + DEFAULT_REGISTER_MODE_ALL;

public static final String HOST = "127.0.0.1";

public static final String DEFAULT_ADDRESS = "tri://" + HOST + ":" + SERVER_PORT;
public static final String LOCAL_HOST = "localhost";

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;
}
@@ -88,9 +88,22 @@ public void attachmentTest() {
final String value = "attachment-value";
RpcContext.removeClientAttachment();
RpcContext.getClientAttachment().setAttachment(key, value);
delegate.greetWithAttachment(GreeterRequest.newBuilder().setName("meta").build());
final String returned = (String) RpcContext.getServiceContext().getObjectAttachment(key);
Assert.assertEquals(value, returned);
GreeterReply reply = delegate.greetWithAttachment(GreeterRequest.newBuilder().setName("meta").build());
Assert.assertEquals("hello,meta",reply.getMessage());
final String returned = (String) RpcContext.getServerContext().getObjectAttachment(key);
Assert.assertEquals("hello," + value, returned);
}

@Test
public void attachmentTest2() {
final String key = "user-attachment";
final String value = "attachment-value";
RpcContext.removeClientAttachment();
RpcContext.getClientAttachment().setAttachment(key, value);
GreeterReply reply = delegateManual.greetWithAttachment(GreeterRequest.newBuilder().setName("meta").build());
Assert.assertEquals("hello,meta",reply.getMessage());
final String returned = (String) RpcContext.getServerContext().getObjectAttachment(key);
Assert.assertEquals("hello," + value, returned);
}

@Test
@@ -26,7 +26,7 @@ public static void init() {
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);
@@ -7,7 +7,8 @@
* this is by manual and other by dubbo compiler
*/
public interface PbGreeterManual {
// GreeterReply greetWithAttachment(GreeterRequest request);

GreeterReply greetWithAttachment(GreeterRequest request);
//
// GreeterReply greet(GreeterRequest request);

@@ -12,7 +12,7 @@ public class PbGreeterImpl implements PbGreeter, PbGreeterManual {
@Override
public GreeterReply greetWithAttachment(GreeterRequest request) {
final String key = "user-attachment";
final String value = RpcContext.getServerAttachment().getAttachment(key);
final String value = "hello,"+RpcContext.getServerAttachment().getAttachment(key);
RpcContext.getServerContext().setObjectAttachment(key, value);
return GreeterReply.newBuilder().setMessage("hello," + request.getName()).build();
}

0 comments on commit 183ad14

Please sign in to comment.