Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[version 2.7.0]remove the StaticContext class and refactor the code related to Async #2688

Merged
merged 13 commits into from
Oct 30, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.apache.dubbo.rpc.cluster.Router;
import org.apache.dubbo.rpc.cluster.RouterFactory;
import org.apache.dubbo.rpc.cluster.router.MockInvoker;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -47,8 +47,9 @@ public class TagRouterTest {
public static void setUpBeforeClass() throws Exception {
}

@Before
public void setUp() throws Exception {
@After
public void teardown() throws Exception {
RpcContext.getContext().clearAttachments();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -74,6 +75,11 @@ public class AbstractClusterInvokerTest {
public static void setUpBeforeClass() throws Exception {
}

@After
public void teardown() throws Exception {
RpcContext.getContext().clearAttachments();
}

@SuppressWarnings({"unchecked"})
@Before
public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,17 @@ public class Constants {

public static final String ON_DISCONNECT_KEY = "ondisconnect";

public static final String ON_INVOKE_METHOD_KEY = "oninvoke.method";
public static final String ON_INVOKE_METHOD_KEY = "oninvokeMethod";
Jeff-Lv marked this conversation as resolved.
Show resolved Hide resolved

public static final String ON_RETURN_METHOD_KEY = "onreturn.method";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rename?

public static final String ON_RETURN_METHOD_KEY = "onreturnMethod";

public static final String ON_THROW_METHOD_KEY = "onthrow.method";
public static final String ON_THROW_METHOD_KEY = "onthrowMethod";

public static final String ON_INVOKE_INSTANCE_KEY = "oninvoke.instance";
public static final String ON_INVOKE_INSTANCE_KEY = "oninvokeInstance";

public static final String ON_RETURN_INSTANCE_KEY = "onreturn.instance";
public static final String ON_RETURN_INSTANCE_KEY = "onreturnInstance";

public static final String ON_THROW_INSTANCE_KEY = "onthrow.instance";
public static final String ON_THROW_INSTANCE_KEY = "onthrowInstance";

public static final String OVERRIDE_PROTOCOL = "override";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.config.MethodConfig;
import com.alibaba.dubbo.config.ArgumentConfig;

import org.apache.dubbo.rpc.model.ConsumerMethodModel;
import org.apache.dubbo.service.Person;
import org.hamcrest.Matchers;
import org.junit.Test;

Expand All @@ -34,6 +37,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class MethodConfigTest {
@Test
Expand Down Expand Up @@ -97,12 +101,23 @@ public void testSticky() throws Exception {
assertThat(method.getSticky(), is(true));
}

@Test
public void testConverMethodConfig2AsyncInfo() throws Exception{
org.apache.dubbo.config.MethodConfig methodConfig = new org.apache.dubbo.config.MethodConfig();
methodConfig.setOninvokeMethod("setName");
methodConfig.setOninvoke(new Person());

ConsumerMethodModel.AsyncMethodInfo methodInfo = org.apache.dubbo.config.MethodConfig.convertMethodConfig2AyncInfo(methodConfig);

assertTrue(methodInfo.getOninvokeMethod().equals( Person.class.getMethod("setName", String.class)));
}

@Test
public void testOnreturn() throws Exception {
MethodConfig method = new MethodConfig();
method.setOnreturn("on-return-object");
assertThat(method.getOnreturn(), equalTo((Object) "on-return-object"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_RETURN_INSTANCE_KEY, (Object) "on-return-object"));
Map<String, String> parameters = new HashMap<String, String>();
Expand All @@ -115,7 +130,7 @@ public void testOnreturnMethod() throws Exception {
MethodConfig method = new MethodConfig();
method.setOnreturnMethod("on-return-method");
assertThat(method.getOnreturnMethod(), equalTo("on-return-method"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_RETURN_METHOD_KEY, (Object) "on-return-method"));
Map<String, String> parameters = new HashMap<String, String>();
Expand All @@ -128,7 +143,7 @@ public void testOnthrow() throws Exception {
MethodConfig method = new MethodConfig();
method.setOnthrow("on-throw-object");
assertThat(method.getOnthrow(), equalTo((Object) "on-throw-object"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_THROW_INSTANCE_KEY, (Object) "on-throw-object"));
Map<String, String> parameters = new HashMap<String, String>();
Expand All @@ -141,7 +156,7 @@ public void testOnthrowMethod() throws Exception {
MethodConfig method = new MethodConfig();
method.setOnthrowMethod("on-throw-method");
assertThat(method.getOnthrowMethod(), equalTo("on-throw-method"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_THROW_METHOD_KEY, (Object) "on-throw-method"));
Map<String, String> parameters = new HashMap<String, String>();
Expand All @@ -154,7 +169,7 @@ public void testOninvoke() throws Exception {
MethodConfig method = new MethodConfig();
method.setOninvoke("on-invoke-object");
assertThat(method.getOninvoke(), equalTo((Object) "on-invoke-object"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_INVOKE_INSTANCE_KEY, (Object) "on-invoke-object"));
Map<String, String> parameters = new HashMap<String, String>();
Expand All @@ -167,7 +182,7 @@ public void testOninvokeMethod() throws Exception {
MethodConfig method = new MethodConfig();
method.setOninvokeMethod("on-invoke-method");
assertThat(method.getOninvokeMethod(), equalTo("on-invoke-method"));
Map<Object, Object> attribute = new HashMap<Object, Object>();
Map<String, Object> attribute = new HashMap<String, Object>();
MethodConfig.appendAttributes(attribute, method);
assertThat(attribute, hasEntry((Object) Constants.ON_INVOKE_METHOD_KEY, (Object) "on-invoke-method"));
Map<String, String> parameters = new HashMap<String, String>();
Expand Down
Loading