Skip to content

Commit

Permalink
Revert dubbo module refactor
Browse files Browse the repository at this point in the history
Signed-off-by: crazyhzm <[email protected]>
  • Loading branch information
CrazyHZM committed Dec 19, 2023
1 parent 9f3000a commit e5c4f9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,27 @@ class MockInvokerTest {

@Test
void testParseMockValue() throws Exception {
Assertions.assertNull(org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("null"));
Assertions.assertNull(org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("empty"));
Assertions.assertNull(MockInvoker.parseMockValue("null"));
Assertions.assertNull(MockInvoker.parseMockValue("empty"));

Assertions.assertTrue((Boolean) org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("true"));
Assertions.assertFalse((Boolean) org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("false"));
Assertions.assertTrue((Boolean) MockInvoker.parseMockValue("true"));
Assertions.assertFalse((Boolean) MockInvoker.parseMockValue("false"));

Assertions.assertEquals(123, org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("123"));
Assertions.assertEquals("foo", org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("foo"));
Assertions.assertEquals("foo", org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("\"foo\""));
Assertions.assertEquals("foo", org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("\'foo\'"));
Assertions.assertEquals(123, MockInvoker.parseMockValue("123"));
Assertions.assertEquals("foo", MockInvoker.parseMockValue("foo"));
Assertions.assertEquals("foo", MockInvoker.parseMockValue("\"foo\""));
Assertions.assertEquals("foo", MockInvoker.parseMockValue("\'foo\'"));

Assertions.assertEquals(new HashMap<>(), org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("{}"));
Assertions.assertEquals(new ArrayList<>(), org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("[]"));
Assertions.assertEquals(
"foo", org.apache.dubbo.rpc.support.MockInvoker.parseMockValue("foo", new Type[] {String.class}));
Assertions.assertEquals(new HashMap<>(), MockInvoker.parseMockValue("{}"));
Assertions.assertEquals(new ArrayList<>(), MockInvoker.parseMockValue("[]"));
Assertions.assertEquals("foo", MockInvoker.parseMockValue("foo", new Type[] {String.class}));
}

@Test
void testInvoke() {
URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
url = url.addParameter(MOCK_KEY, "return ");
org.apache.dubbo.rpc.support.MockInvoker mockInvoker =
new org.apache.dubbo.rpc.support.MockInvoker(url, String.class);
MockInvoker mockInvoker = new MockInvoker(url, String.class);

RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Expand All @@ -71,8 +69,7 @@ void testGetDefaultObject() {
final Class<DemoServiceA> demoServiceAClass = DemoServiceA.class;
URL url = URL.valueOf("remote://1.2.3.4/" + demoServiceAClass.getName());
url = url.addParameter(MOCK_KEY, "force:true");
org.apache.dubbo.rpc.support.MockInvoker mockInvoker =
new org.apache.dubbo.rpc.support.MockInvoker(url, demoServiceAClass);
MockInvoker mockInvoker = new MockInvoker(url, demoServiceAClass);

RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("methodA");
Expand All @@ -82,7 +79,7 @@ void testGetDefaultObject() {
final Class<DemoServiceB> demoServiceBClass = DemoServiceB.class;
url = URL.valueOf("remote://1.2.3.4/" + demoServiceBClass.getName());
url = url.addParameter(MOCK_KEY, "force:true");
mockInvoker = new org.apache.dubbo.rpc.support.MockInvoker(url, demoServiceBClass);
mockInvoker = new MockInvoker(url, demoServiceBClass);
invocation = new RpcInvocation();
invocation.setMethodName("methodB");
Assertions.assertEquals(new HashMap<>(), mockInvoker.invoke(invocation).getObjectAttachments());
Expand All @@ -91,7 +88,7 @@ void testGetDefaultObject() {
@Test
void testInvokeThrowsRpcException1() {
URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
org.apache.dubbo.rpc.support.MockInvoker mockInvoker = new org.apache.dubbo.rpc.support.MockInvoker(url, null);
MockInvoker mockInvoker = new MockInvoker(url, null);

Assertions.assertThrows(RpcException.class, () -> mockInvoker.invoke(new RpcInvocation()));
}
Expand All @@ -100,8 +97,7 @@ void testInvokeThrowsRpcException1() {
void testInvokeThrowsRpcException2() {
URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
url = url.addParameter(MOCK_KEY, "fail");
org.apache.dubbo.rpc.support.MockInvoker mockInvoker =
new org.apache.dubbo.rpc.support.MockInvoker(url, String.class);
MockInvoker mockInvoker = new MockInvoker(url, String.class);

RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Expand All @@ -112,8 +108,7 @@ void testInvokeThrowsRpcException2() {
void testInvokeThrowsRpcException3() {
URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
url = url.addParameter(MOCK_KEY, "throw");
org.apache.dubbo.rpc.support.MockInvoker mockInvoker =
new org.apache.dubbo.rpc.support.MockInvoker(url, String.class);
MockInvoker mockInvoker = new MockInvoker(url, String.class);

RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Expand All @@ -130,42 +125,42 @@ void testGetThrowable() {
void testGetMockObject() {
Assertions.assertEquals(
"",
org.apache.dubbo.rpc.support.MockInvoker.getMockObject(
MockInvoker.getMockObject(
ApplicationModel.defaultModel().getExtensionDirector(), "java.lang.String", String.class));

Assertions.assertThrows(
IllegalStateException.class,
() -> org.apache.dubbo.rpc.support.MockInvoker.getMockObject(
() -> MockInvoker.getMockObject(
ApplicationModel.defaultModel().getExtensionDirector(), "true", String.class));
Assertions.assertThrows(
IllegalStateException.class,
() -> org.apache.dubbo.rpc.support.MockInvoker.getMockObject(
() -> MockInvoker.getMockObject(
ApplicationModel.defaultModel().getExtensionDirector(), "default", String.class));
Assertions.assertThrows(
IllegalStateException.class,
() -> org.apache.dubbo.rpc.support.MockInvoker.getMockObject(
() -> MockInvoker.getMockObject(
ApplicationModel.defaultModel().getExtensionDirector(), "java.lang.String", Integer.class));
Assertions.assertThrows(
IllegalStateException.class,
() -> org.apache.dubbo.rpc.support.MockInvoker.getMockObject(
() -> MockInvoker.getMockObject(
ApplicationModel.defaultModel().getExtensionDirector(),
"java.io.Serializable",
Serializable.class));
}

@Test
void testNormalizeMock() {
Assertions.assertNull(org.apache.dubbo.rpc.support.MockInvoker.normalizeMock(null));

Assertions.assertEquals("", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock(""));
Assertions.assertEquals("", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("fail:"));
Assertions.assertEquals("", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("force:"));
Assertions.assertEquals("throw", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("throw"));
Assertions.assertEquals("default", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("fail"));
Assertions.assertEquals("default", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("force"));
Assertions.assertEquals("default", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("true"));
Assertions.assertEquals("default", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("default"));
Assertions.assertEquals("return null", org.apache.dubbo.rpc.support.MockInvoker.normalizeMock("return"));
Assertions.assertNull(MockInvoker.normalizeMock(null));

Assertions.assertEquals("", MockInvoker.normalizeMock(""));
Assertions.assertEquals("", MockInvoker.normalizeMock("fail:"));
Assertions.assertEquals("", MockInvoker.normalizeMock("force:"));
Assertions.assertEquals("throw", MockInvoker.normalizeMock("throw"));
Assertions.assertEquals("default", MockInvoker.normalizeMock("fail"));
Assertions.assertEquals("default", MockInvoker.normalizeMock("force"));
Assertions.assertEquals("default", MockInvoker.normalizeMock("true"));
Assertions.assertEquals("default", MockInvoker.normalizeMock("default"));
Assertions.assertEquals("return null", MockInvoker.normalizeMock("return"));
Assertions.assertEquals("return null", MockInvoker.normalizeMock("return null"));
}
}
5 changes: 0 additions & 5 deletions dubbo-rpc/dubbo-rpc-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
<artifactId>hessian-lite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down
33 changes: 0 additions & 33 deletions dubbo-rpc/dubbo-rpc-api/src/test/resources/log4j2-test.xml

This file was deleted.

0 comments on commit e5c4f9c

Please sign in to comment.