[jboss-remoting-commits] JBoss Remoting SVN: r6094 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Sep 7 16:01:29 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-09-07 16:01:29 -0400 (Tue, 07 Sep 2010)
New Revision: 6094

Added:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteCallbackTestCase.java
Log:
JBREM-1228: New unit test.

Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteCallbackTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteCallbackTestCase.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteCallbackTestCase.java	2010-09-07 20:01:29 UTC (rev 6094)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Random;
+
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.ClientConnector;
+import org.jboss.remoting3.Connection;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 3, 2010
+ */
+ at Test(suiteName = "RemoteCallback")
+public class RemoteCallbackTestCase extends LocalCallbackTestCase {
+   
+   private static final Logger log = Logger.getLogger(RemoteCallbackTestCase.class);
+   
+   private static int counter = new Random(new Date().getTime()).nextInt();
+   private static RemotingTestBase remotingTestBase = new RemotingTestBase();
+
+   @BeforeMethod
+   public void setUp() {
+   }
+
+   @AfterMethod
+   public void tearDown() throws IOException {
+   }
+
+   @Test
+   public void testCallbackByRequestContext() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      Connection connection = null;
+      Client<Object, Object> client = null;
+
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+
+         // Set up services.
+         sp0 = remotingTestBase.setupServer(null, id0, new TestRequestListener(), SERVICE_TYPE, INSTANCE_NAME);
+         sp1 = remotingTestBase.setupServer(null, id1, new TestRequestListener(), SERVICE_TYPE, INSTANCE_NAME);
+         
+         // Verify configuration.
+         assertNotSame(sp0.executor, sp1.executor, "Should be distinct");
+         assertNotSame(sp0.endpoint, sp1.endpoint, "Should be distinct");
+         assertNotSame(sp0.xnio, sp1.xnio, "Should be distinct");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         assertNotSame(sp0.requestListener, sp1.requestListener, "Should be distinct");
+
+         // Set up connection and client.
+         connection = remotingTestBase.setupConnection(sp0, sp1);
+         client = setupClient(connection, SERVICE_TYPE, INSTANCE_NAME);
+
+         // Test callback.
+         assertEquals(OK, client.invoke(CALLBACK_REQUEST));
+         
+         assertFalse(((TestRequestListener)(sp0.requestListener)).receivedCallbackRequest);
+         assertTrue(((TestRequestListener)(sp0.requestListener)).receivedCallback);
+         assertFalse(((TestRequestListener)(sp0.requestListener)).receivedClientConnector);
+         assertFalse(((TestRequestListener)(sp0.requestListener)).sentCallback);
+         
+         assertTrue(((TestRequestListener)(sp1.requestListener)).receivedCallbackRequest);
+         assertFalse(((TestRequestListener)(sp1.requestListener)).receivedCallback);
+         assertFalse(((TestRequestListener)(sp1.requestListener)).receivedClientConnector);
+         assertTrue(((TestRequestListener)(sp1.requestListener)).sentCallback);
+
+         log.debug(getName() + " PASSES");
+      } finally {
+         if (client != null) {
+            client.close();
+         }
+         if (connection != null) {
+            connection.close();
+         }
+         if (sp0 != null) {
+            sp0.close();
+         }
+         if (sp1 != null) {
+            sp1.close();
+         }
+         exit();
+      }
+   }
+
+   @Test
+   public void testCallbackByClientConnector() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      Connection connection = null;
+      Client<Object, Object> client = null;
+
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+
+         // Set up services.
+         sp0 = remotingTestBase.setupServer(null, id0, new TestRequestListener(), SERVICE_TYPE, INSTANCE_NAME);
+         sp1 = remotingTestBase.setupServer(null, id1, new TestRequestListener(), SERVICE_TYPE, INSTANCE_NAME);
+         
+         // Verify configuration.
+         assertNotSame(sp0.executor, sp1.executor, "Should be distinct");
+         assertNotSame(sp0.endpoint, sp1.endpoint, "Should be distinct");
+         assertNotSame(sp0.xnio, sp1.xnio, "Should be distinct");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         assertNotSame(sp0.requestListener, sp1.requestListener, "Should be distinct");
+
+         // Set up connection and client.
+         connection = remotingTestBase.setupConnection(sp0, sp1);
+         client = setupClient(connection, SERVICE_TYPE, INSTANCE_NAME);
+
+         // Test callback.
+         TestRequestListener callbackRequestListener = new TestRequestListener();
+         ClientConnector<Object, Object> clientConnector = connection.createClientConnector(callbackRequestListener, Object.class, Object.class);
+         assertEquals(OK, client.invoke(clientConnector));
+         
+         assertFalse(((TestRequestListener)(sp0.requestListener)).receivedCallbackRequest);
+         assertFalse(((TestRequestListener)(sp0.requestListener)).receivedCallback);
+         assertFalse(((TestRequestListener)(sp0.requestListener)).receivedClientConnector);
+         assertFalse(((TestRequestListener)(sp0.requestListener)).sentCallback);
+         
+         assertFalse(((TestRequestListener)(sp1.requestListener)).receivedCallbackRequest);
+         assertFalse(((TestRequestListener)(sp1.requestListener)).receivedCallback);
+         assertTrue(((TestRequestListener)(sp1.requestListener)).receivedClientConnector);
+         assertTrue(((TestRequestListener)(sp1.requestListener)).sentCallback);
+         
+         assertFalse(callbackRequestListener.receivedCallbackRequest);
+         assertTrue(callbackRequestListener.receivedCallback);
+         assertFalse(callbackRequestListener.receivedClientConnector);
+         assertFalse(callbackRequestListener.sentCallback);
+         
+         log.debug(getName() + " PASSES");
+      } finally {
+         if (client != null) {
+            client.close();
+         }
+         if (connection != null) {
+            connection.close();
+         }
+         if (sp0 != null) {
+            sp0.close();
+         }
+         if (sp1 != null) {
+            sp1.close();
+         }
+         exit();
+      }
+   }
+}



More information about the jboss-remoting-commits mailing list