Skip to content

Commit

Permalink
[version 2.7.0]remove the StaticContext class and refactor the code r…
Browse files Browse the repository at this point in the history
…elated to Async (#2688)

* [Dubbo] move the classes of model from config to rpc-api for reusing

* remove ServiceClassHolder and use the ApplicationModel replacedly

* [Dubbo] delete the unused imported of ApplicationModel

* Update dubbo-demo-consumer.xml

this commits is no need to commit to remote repo.

* remove StaticContext

* remove the unused imported classes of ReferenceConfig

* fix NPE of ConsumerModel

* fix the failed testcase of AbstractClusterInvokerTest

* [Dubbo] #PR2688 to fix the review issues
  • Loading branch information
Jeff-Lv authored and beiwei30 committed Oct 30, 2018
1 parent 99a00ba commit 36a1155
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 739 deletions.
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 @@ -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

0 comments on commit 36a1155

Please sign in to comment.