diff --git a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/ClientToServerTest.java b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/ClientToServerTest.java similarity index 98% rename from dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/ClientToServerTest.java rename to dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/ClientToServerTest.java index f3a5ad46ec093bbfcd2b716bf38d9bba3617ce4e..f1523bfbb490561a14b409cf08bc76158fade020 100644 --- a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/ClientToServerTest.java +++ b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/ClientToServerTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.dubbo.remoting.transport; +package com.alibaba.remoting.transport.mina; import junit.framework.Assert; import junit.framework.TestCase; diff --git a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/Hello.java b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/Hello.java similarity index 95% rename from dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/Hello.java rename to dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/Hello.java index c158d46631ce703eaba67fa5e6b9b3878663836d..84e50651d81e2f688333be9fc907c3bbbf6e714e 100644 --- a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/Hello.java +++ b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/Hello.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.dubbo.remoting.transport; +package com.alibaba.remoting.transport.mina; import java.io.Serializable; diff --git a/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/MinaClientToServerTest.java b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/MinaClientToServerTest.java index f78a5e41aee2b76f46555ea9a2c9451b24c06cea..01492fdd1965c3bf5a2e9b10ccef824eb98bdb33 100644 --- a/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/MinaClientToServerTest.java +++ b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/MinaClientToServerTest.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; import com.alibaba.dubbo.remoting.exchange.ExchangeServer; import com.alibaba.dubbo.remoting.exchange.Exchangers; import com.alibaba.dubbo.remoting.exchange.support.Replier; -import com.alibaba.dubbo.remoting.transport.ClientToServerTest; /** * MinaServerClientTest diff --git a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/World.java b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/World.java similarity index 95% rename from dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/World.java rename to dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/World.java index a62c9acf398b9987686c2a375fa24ee4bc3e328e..700136d921463a1c15dfc917d1107e646f2df564 100644 --- a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/World.java +++ b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/World.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.dubbo.remoting.transport; +package com.alibaba.remoting.transport.mina; import java.io.Serializable; diff --git a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/WorldHandler.java b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/WorldHandler.java similarity index 95% rename from dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/WorldHandler.java rename to dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/WorldHandler.java index 85a1e9ee12c95fe84ff69bc99de577b653931389..b9e95416b6d3652bf3ae0bcf880a22b543ba2065 100644 --- a/dubbo-remoting/src/test/java/com/alibaba/dubbo/remoting/transport/WorldHandler.java +++ b/dubbo-remoting-mina/src/test/java/com/alibaba/remoting/transport/mina/WorldHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.dubbo.remoting.transport; +package com.alibaba.remoting.transport.mina; import com.alibaba.dubbo.remoting.RemotingException; import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; diff --git a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientToServerTest.java b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientToServerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b080f20ea5f6454af334b33054cf973ed051a1bf --- /dev/null +++ b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientToServerTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 1999-2011 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.dubbo.remoting.transport.netty; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.junit.Test; + +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; +import com.alibaba.dubbo.remoting.exchange.ExchangeServer; +import com.alibaba.dubbo.remoting.exchange.ResponseFuture; +import com.alibaba.dubbo.remoting.exchange.support.Replier; + +/** + * ClientToServer + * + * @author william.liangf + */ +public abstract class ClientToServerTest extends TestCase { + + protected static final String LOCALHOST = "127.0.0.1"; + + protected ExchangeServer server; + + protected ExchangeChannel client; + + protected WorldHandler handler = new WorldHandler(); + + protected abstract ExchangeServer newServer(int port, Replier receiver) throws RemotingException; + + protected abstract ExchangeChannel newClient(int port) throws RemotingException; + + @Override + protected void setUp() throws Exception { + super.setUp(); + int port = (int) (1000 * Math.random() + 10000); + server = newServer(port, handler); + client = newClient(port); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + try { + if (server != null) + server.close(); + } finally { + if (client != null) + client.close(); + } + } + + @Test + public void testFuture() throws Exception { + ResponseFuture future = client.request(new World("world")); + Hello result = (Hello)future.get(); + Assert.assertEquals("hello,world", result.getName()); + } + +// @Test +// public void testCallback() throws Exception { +// final Object waitter = new Object(); +// client.invoke(new World("world"), new InvokeCallback() { +// public void callback(Hello result) { +// Assert.assertEquals("hello,world", result.getName()); +// synchronized (waitter) { +// waitter.notifyAll(); +// } +// } +// public void onException(Throwable exception) { +// } +// }); +// synchronized (waitter) { +// waitter.wait(); +// } +// } + +} \ No newline at end of file diff --git a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/Hello.java b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/Hello.java new file mode 100644 index 0000000000000000000000000000000000000000..9b70422a9367339f600026df775bbb27ecc6dea3 --- /dev/null +++ b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/Hello.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2011 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.dubbo.remoting.transport.netty; + +import java.io.Serializable; + +/** + * Result + * + * @author william.liangf + */ +public class Hello implements Serializable { + + private static final long serialVersionUID = 8563900571013747774L; + + private String name; + + public Hello() { + } + + public Hello(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/NettyClientToServerTest.java b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/NettyClientToServerTest.java index 8515c6f87dbce309ab0b3f182e509ce7abd14e08..a30b6d76e81fc3e2013b014462d44f91c44477c0 100644 --- a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/NettyClientToServerTest.java +++ b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/NettyClientToServerTest.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; import com.alibaba.dubbo.remoting.exchange.ExchangeServer; import com.alibaba.dubbo.remoting.exchange.Exchangers; import com.alibaba.dubbo.remoting.exchange.support.Replier; -import com.alibaba.dubbo.remoting.transport.ClientToServerTest; /** * NettyClientToServerTest diff --git a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/World.java b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/World.java new file mode 100644 index 0000000000000000000000000000000000000000..b190d3eb1e8a3fa032cd203fc3b1efa3a9928f71 --- /dev/null +++ b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/World.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2011 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.dubbo.remoting.transport.netty; + +import java.io.Serializable; + +/** + * Data + * + * @author william.liangf + */ +public class World implements Serializable { + + private static final long serialVersionUID = 8563900571013747774L; + + private String name; + + public World() { + } + + public World(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/WorldHandler.java b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/WorldHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..d795db1b6046f75e25a3a160bc671e0cf61ed750 --- /dev/null +++ b/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/WorldHandler.java @@ -0,0 +1,37 @@ +/* + * Copyright 1999-2011 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.dubbo.remoting.transport.netty; + +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; +import com.alibaba.dubbo.remoting.exchange.support.Replier; + +/** + * DataHandler + * + * @author william.liangf + */ +public class WorldHandler implements Replier { + + public Class interest() { + return World.class; + } + + public Object reply(ExchangeChannel channel, World msg) throws RemotingException { + return new Hello("hello," + msg.getName()); + } + +} \ No newline at end of file