JBoss Remoting SVN: r6098 - remoting2/branches/2.2.3-SP2_JBREM-1242/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: jbertram(a)redhat.com
Date: 2010-09-07 16:55:43 -0400 (Tue, 07 Sep 2010)
New Revision: 6098
Modified:
remoting2/branches/2.2.3-SP2_JBREM-1242/src/main/org/jboss/remoting/Client.java
Log:
JBPAPP-5030
Modified: remoting2/branches/2.2.3-SP2_JBREM-1242/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2.3-SP2_JBREM-1242/src/main/org/jboss/remoting/Client.java 2010-09-07 20:33:01 UTC (rev 6097)
+++ remoting2/branches/2.2.3-SP2_JBREM-1242/src/main/org/jboss/remoting/Client.java 2010-09-07 20:55:43 UTC (rev 6098)
@@ -1919,7 +1919,26 @@
temp.put(CONNECTION_LISTENER, listener);
}
if (trace) log.trace(this + " calling MicroRemoteClientInvoker.establishLease()");
- invoker.establishLease(sessionId, temp, leasePeriod);
+
+ // Synchronizing on connectionValidatorLock to prevent a deadlock:
+ //
+ // 1. a. This method calls MicroRemoteClientInvoker.establishLease()
+ // b. MicroRemoteClientInvoker.establishLease() synchronizes on MicroRemoteClientInvoker.clientLeaseLock
+ // and calls Client.addConnectionListener()
+ // c. Client.addConnectionListener() synchronizes on Client.connectionValidatorLock
+ //
+ // 2. a. Client.addConnectionListener() synchronizes on Client.connectionValidatorLock and calls
+ // new ConnectionValidator()
+ // b. new ConnectionValidator() calls MicroRemoteClientInvoker.getLeasePinger(), which
+ // synchronizes on MicroRemoteClientInvoker.clientLeaseLock
+ //
+ // By synchronizing on connectionValidatorLock here, we assure that both sequences acquire
+ // Client.connectionValidatorLock first and then acquire MicroRemoteClientInvoker.clientLeaseLock.
+ //
+ synchronized(connectionValidatorLock)
+ {
+ invoker.establishLease(sessionId, temp, leasePeriod);
+ }
}
else if (listener != null)
{
14 years, 3 months
JBoss Remoting SVN: r6097 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 16:33:01 -0400 (Tue, 07 Sep 2010)
New Revision: 6097
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
Log:
JBREM-1228: Counter is set to a non-negative number.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07 20:17:51 UTC (rev 6096)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07 20:33:01 UTC (rev 6097)
@@ -61,7 +61,7 @@
private static final Logger log = Logger.getLogger(ClientServerRemoteConfigurationTestCase.class);
- private static int counter = new Random(Math.abs(new Date().getTime())).nextInt();
+ private static int counter = Math.abs(new Random(new Date().getTime()).nextInt());
@BeforeMethod
public void setUp() {
14 years, 3 months
JBoss Remoting SVN: r6096 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 16:17:51 -0400 (Tue, 07 Sep 2010)
New Revision: 6096
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
Log:
JBREM-1228: Now starts counter at a random value
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07 20:04:56 UTC (rev 6095)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07 20:17:51 UTC (rev 6096)
@@ -29,7 +29,9 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Date;
import java.util.HashSet;
+import java.util.Random;
import java.util.ServiceLoader;
import org.jboss.remoting3.Client;
@@ -59,7 +61,7 @@
private static final Logger log = Logger.getLogger(ClientServerRemoteConfigurationTestCase.class);
- private static int counter;
+ private static int counter = new Random(Math.abs(new Date().getTime())).nextInt();
@BeforeMethod
public void setUp() {
14 years, 3 months
JBoss Remoting SVN: r6095 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 16:04:56 -0400 (Tue, 07 Sep 2010)
New Revision: 6095
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java
Log:
JBREM-1228: New unit test.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java 2010-09-07 20:04:56 UTC (rev 6095)
@@ -0,0 +1,411 @@
+/*
+ * 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.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.net.URI;
+
+import org.jboss.remoting3.ServiceURI;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 5, 2010
+ */
+@Test(suiteName = "ServiceURI")
+public class ServiceURITestCase extends RemotingRootTestBase {
+
+ private static final Logger log = Logger.getLogger(ServiceURITestCase.class);
+
+ public static int counter;
+
+ @Test
+ public void testServiceURI() throws Exception {
+ enter();
+ try {
+
+ // Test ServiceURI.isRemotingServiceUri().
+ assertTrue(ServiceURI.isRemotingServiceUri(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+ assertFalse(ServiceURI.isRemotingServiceUri(new URI(ServiceURI.SCHEME + ":/scheme-specific-part")));
+ assertFalse(ServiceURI.isRemotingServiceUri(new URI("http:scheme-specific-part")));
+ assertFalse(ServiceURI.isRemotingServiceUri(new URI("noscheme")));
+
+ // Test ServiceURI.getServiceType().
+ try {
+ ServiceURI.getServiceType(new URI("http:scheme-specific-part"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ assertEquals("servicetype", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":servicetype:scheme-specific-part")));
+ assertEquals("servicetype", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":serviceType:scheme-specific-part")));
+ assertEquals("scheme-specific-part", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+
+ // Test ServiceURI.getInstanceName().
+ try {
+ ServiceURI.getInstanceName(new URI("http:scheme-specific-part"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ assertEquals("", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+ assertEquals("scheme-specific-part", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:scheme-specific-part")));
+ assertEquals("instancename", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:instancename:scheme-specific-part")));
+ assertEquals("instancename", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:instanceName:scheme-specific-part")));
+
+ // Test ServiceURI.getEndpointName().
+ try {
+ ServiceURI.getEndpointName(new URI("http:scheme-specific-part"));
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ assertEquals("", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+ assertEquals("", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:scheme-specific-part")));
+ assertEquals("scheme-specific-part", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:scheme-specific-part")));
+ assertEquals("endpointname", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:endpointname:scheme-specific-part")));
+ assertEquals("endpointname", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:endpointName:scheme-specific-part")));
+
+ // Test ServiceURI.create().
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, null, null).toString());
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, null, "").toString());
+ assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create(null, null, "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, "", null).toString());
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, "", "").toString());
+ assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create(null, "", "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create(null, "instancename", null).toString());
+ assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create(null, "instancename", "").toString());
+ assertEquals(ServiceURI.SCHEME + "::instancename:endpointname", ServiceURI.create(null, "instancename", "endpointname").toString());
+//
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", null, null).toString());
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", null, "").toString());
+ assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create("", null, "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", "", null).toString());
+ assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", "", "").toString());
+ assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create("", "", "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create("", "instancename", null).toString());
+ assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create("", "instancename", "").toString());
+ assertEquals(ServiceURI.SCHEME + "::instancename:endpointname", ServiceURI.create("", "instancename", "endpointname").toString());
+//
+ assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", null, null).toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", null, "").toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype::endpointname", ServiceURI.create("servicetype", null, "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", "", null).toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", "", "").toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype::endpointname", ServiceURI.create("servicetype", "", "endpointname").toString());
+
+ assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:", ServiceURI.create("servicetype", "instancename", null).toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:", ServiceURI.create("servicetype", "instancename", "").toString());
+ assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:endpointname", ServiceURI.create("servicetype", "instancename", "endpointname").toString());
+
+ // Test ServiceURI.validateServiceType().
+ try {
+ ServiceURI.validateServiceType(null);
+ fail("expected NullPointerException");
+ } catch (NullPointerException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected NullPointerException");
+ }
+ ServiceURI.validateServiceType("_");
+ ServiceURI.validateServiceType("a");
+ ServiceURI.validateServiceType("__");
+ ServiceURI.validateServiceType("_a");
+ ServiceURI.validateServiceType("_0");
+ ServiceURI.validateServiceType("a_");
+ ServiceURI.validateServiceType("aa");
+ ServiceURI.validateServiceType("a0");
+ ServiceURI.validateServiceType("_a0a");
+ ServiceURI.validateServiceType("_00a");
+ ServiceURI.validateServiceType("a_0a");
+ ServiceURI.validateServiceType("aa0a");
+ ServiceURI.validateServiceType("a00a");
+ ServiceURI.validateServiceType("a._");
+ ServiceURI.validateServiceType("a.a");
+ ServiceURI.validateServiceType("a.__");
+ ServiceURI.validateServiceType("a._a");
+ ServiceURI.validateServiceType("a._0");
+ ServiceURI.validateServiceType("a.a_");
+ ServiceURI.validateServiceType("a.aa");
+ ServiceURI.validateServiceType("a.a0");
+ ServiceURI.validateServiceType("a.a._");
+ ServiceURI.validateServiceType("a.a.a");
+ ServiceURI.validateServiceType("a.a.__");
+ ServiceURI.validateServiceType("a.a._a");
+ ServiceURI.validateServiceType("a.a._0");
+ ServiceURI.validateServiceType("a.a.a_");
+ ServiceURI.validateServiceType("a.a.aa");
+ ServiceURI.validateServiceType("a.a.a0");
+ try {
+ ServiceURI.validateServiceType("");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateServiceType("0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateServiceType("-");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateServiceType("a.");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateServiceType("a.0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateServiceType("a.a.0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+
+ // Test ServiceURI.validateInstanceName().
+ try {
+ ServiceURI.validateInstanceName(null);
+ fail("expected NullPointerException");
+ } catch (NullPointerException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected NullPointerException");
+ }
+ ServiceURI.validateInstanceName("_");
+ ServiceURI.validateInstanceName("a");
+ ServiceURI.validateInstanceName("0");
+ ServiceURI.validateInstanceName("__");
+ ServiceURI.validateInstanceName("_a");
+ ServiceURI.validateInstanceName("_0");
+ ServiceURI.validateInstanceName("a_");
+ ServiceURI.validateInstanceName("aa");
+ ServiceURI.validateInstanceName("a0");
+ ServiceURI.validateInstanceName("0_");
+ ServiceURI.validateInstanceName("0a");
+ ServiceURI.validateInstanceName("00");
+ ServiceURI.validateInstanceName("_a0a");
+ ServiceURI.validateInstanceName("_00a");
+ ServiceURI.validateInstanceName("a_0a");
+ ServiceURI.validateInstanceName("aa0a");
+ ServiceURI.validateInstanceName("a00a");
+ ServiceURI.validateInstanceName("0_0a");
+ ServiceURI.validateInstanceName("0a0a");
+ ServiceURI.validateInstanceName("000a");
+ ServiceURI.validateInstanceName("a._");
+ ServiceURI.validateInstanceName("a.a");
+ ServiceURI.validateInstanceName("a.0");
+ ServiceURI.validateInstanceName("a.__");
+ ServiceURI.validateInstanceName("a._a");
+ ServiceURI.validateInstanceName("a._0");
+ ServiceURI.validateInstanceName("a.a_");
+ ServiceURI.validateInstanceName("a.aa");
+ ServiceURI.validateInstanceName("a.a0");
+ ServiceURI.validateInstanceName("a.0_");
+ ServiceURI.validateInstanceName("a.0a");
+ ServiceURI.validateInstanceName("a.00");
+ ServiceURI.validateInstanceName("a.a._");
+ ServiceURI.validateInstanceName("a.a.a");
+ ServiceURI.validateInstanceName("a.a.0");
+ ServiceURI.validateInstanceName("a.a.__");
+ ServiceURI.validateInstanceName("a.a._a");
+ ServiceURI.validateInstanceName("a.a._0");
+ ServiceURI.validateInstanceName("a.a.a_");
+ ServiceURI.validateInstanceName("a.a.aa");
+ ServiceURI.validateInstanceName("a.a.a0");
+ ServiceURI.validateInstanceName("a.a.0_");
+ ServiceURI.validateInstanceName("a.a.0a");
+ ServiceURI.validateInstanceName("a.a.00");
+ try {
+ ServiceURI.validateInstanceName("");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateInstanceName("-");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateInstanceName("a.");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateInstanceName("a.-");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateInstanceName("a.a.-");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+
+ // Test ServiceURI.validateEndpointName().
+ try {
+ ServiceURI.validateEndpointName(null);
+ fail("expected NullPointerException");
+ } catch (NullPointerException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected NullPointerException");
+ }
+ ServiceURI.validateEndpointName("_");
+ ServiceURI.validateEndpointName("a");
+ ServiceURI.validateEndpointName("__");
+ ServiceURI.validateEndpointName("_a");
+ ServiceURI.validateEndpointName("_0");
+ ServiceURI.validateEndpointName("a_");
+ ServiceURI.validateEndpointName("aa");
+ ServiceURI.validateEndpointName("a0");
+ ServiceURI.validateEndpointName("_a0a");
+ ServiceURI.validateEndpointName("_00a");
+ ServiceURI.validateEndpointName("a_0a");
+ ServiceURI.validateEndpointName("aa0a");
+ ServiceURI.validateEndpointName("a00a");
+ ServiceURI.validateEndpointName("a._");
+ ServiceURI.validateEndpointName("a.a");
+ ServiceURI.validateEndpointName("a.__");
+ ServiceURI.validateEndpointName("a._a");
+ ServiceURI.validateEndpointName("a._0");
+ ServiceURI.validateEndpointName("a.a_");
+ ServiceURI.validateEndpointName("a.aa");
+ ServiceURI.validateEndpointName("a.a0");
+ ServiceURI.validateEndpointName("a.a._");
+ ServiceURI.validateEndpointName("a.a.a");
+ ServiceURI.validateEndpointName("a.a.__");
+ ServiceURI.validateEndpointName("a.a._a");
+ ServiceURI.validateEndpointName("a.a._0");
+ ServiceURI.validateEndpointName("a.a.a_");
+ ServiceURI.validateEndpointName("a.a.aa");
+ ServiceURI.validateEndpointName("a.a.a0");
+ try {
+ ServiceURI.validateEndpointName("");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateEndpointName("0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateEndpointName("-");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateEndpointName("a.");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateEndpointName("a.0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ try {
+ ServiceURI.validateEndpointName("a.a.0");
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ log.info("got expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ fail("expected IllegalArgumentException");
+ }
+ log.info(getName() + " PASSES");
+ } finally {
+ exit();
+ }
+ }
+}
14 years, 3 months
JBoss Remoting SVN: r6094 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)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(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 3, 2010
+ */
+@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();
+ }
+ }
+}
14 years, 3 months
JBoss Remoting SVN: r6093 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:56:10 -0400 (Tue, 07 Sep 2010)
New Revision: 6093
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingLocalTestBase.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingTestBase.java
Log:
JBREM-1228: Moved a couple of methods from RemotingTestBase to RemotingLocalTestBase.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingLocalTestBase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingLocalTestBase.java 2010-09-07 19:55:26 UTC (rev 6092)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingLocalTestBase.java 2010-09-07 19:56:10 UTC (rev 6093)
@@ -45,12 +45,9 @@
import org.jboss.remoting3.RequestListener;
import org.jboss.remoting3.Endpoint.ServiceBuilder;
import org.jboss.remoting3.spi.ProtocolServiceType;
-import org.jboss.remoting3.test.ClientServerRemoteConfigurationTestCase.TestRequestListener;
import org.jboss.xnio.AcceptingServer;
-import org.jboss.xnio.IoFuture;
import org.jboss.xnio.OptionMap;
import org.jboss.xnio.Xnio;
-import org.jboss.xnio.IoFuture.Status;
import org.jboss.xnio.log.Logger;
/**
@@ -98,6 +95,14 @@
protected void addConnectionProvider(ServerPackage sp, int id) throws IOException {
}
+ protected OptionMap getConnectionOptionMap() {
+ return OptionMap.EMPTY;
+ }
+
+ protected String getRemotingScheme() {
+ return "local";
+ }
+
public static class ServerPackage {
public ThreadPoolExecutor executor;
public Endpoint endpoint;
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingTestBase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingTestBase.java 2010-09-07 19:55:26 UTC (rev 6092)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemotingTestBase.java 2010-09-07 19:56:10 UTC (rev 6093)
@@ -116,10 +116,6 @@
return new RemoteProtocolDescriptor();
}
- protected OptionMap getConnectionOptionMap() {
- return OptionMap.EMPTY;
- }
-
protected void createTcpServer(ServerPackage sp, ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener) throws IOException {
log.debug(this + " creating TcpServer");
TcpServer tcpServer = sp.xnio.createTcpServer(listener, OptionMap.EMPTY);
14 years, 3 months
JBoss Remoting SVN: r6092 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:55:26 -0400 (Tue, 07 Sep 2010)
New Revision: 6092
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalCallbackTestCase.java
Log:
JBREM-1228: New unit test.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalCallbackTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalCallbackTestCase.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalCallbackTestCase.java 2010-09-07 19:55:26 UTC (rev 6092)
@@ -0,0 +1,213 @@
+/*
+ * 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.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.ClientConnector;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.xnio.IoFuture;
+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(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 3, 2010
+ */
+//@SuppressWarnings("unused")
+@Test(suiteName = "LocalCallback")
+public class LocalCallbackTestCase extends RemotingLocalTestBase {
+
+ protected static final String SERVICE_TYPE = "testservice";
+ protected static final String INSTANCE_NAME= "testinstance";
+ protected static final String CALLBACK_REQUEST = "callbackRequest";
+ protected static final String CALLBACK = "callback";
+ protected static final String OK = "ok";
+
+ private static final Logger log = Logger.getLogger(LocalCallbackTestCase.class);
+
+ private static int counter;
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() throws IOException {
+ }
+
+ @Test
+ public void testCallbackByRequestContext() throws Exception {
+ enter();
+ ServerPackage sp = null;
+ Connection connection = null;
+ Client<Object, Object> client = null;
+
+ try {
+ int id = counter++;
+
+ // Set up service.
+ TestRequestListener testRequestListener = new TestRequestListener();
+ sp = setupServer(null, id, testRequestListener, SERVICE_TYPE, INSTANCE_NAME);
+
+ // Set up connection and client.
+ connection = setupConnection(sp);
+ client = setupClient(connection, SERVICE_TYPE, INSTANCE_NAME);
+
+ // Test callback.
+ assertEquals(OK, client.invoke(CALLBACK_REQUEST));
+ assertTrue(testRequestListener.receivedCallbackRequest);
+ assertTrue(testRequestListener.receivedCallback);
+ assertFalse(testRequestListener.receivedClientConnector);
+ assertTrue(testRequestListener.sentCallback);
+
+ log.debug(getName() + " PASSES");
+ } finally {
+ if (client != null) {
+ client.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ if (sp != null) {
+ sp.close();
+ }
+ exit();
+ }
+ }
+
+ @Test
+ public void testCallbackByClientConnector() throws Exception {
+ enter();
+ ServerPackage sp = null;
+ Connection connection = null;
+ Client<Object, Object> client = null;
+
+ try {
+ int id = counter++;
+
+ // Set up service.
+ TestRequestListener testRequestListener = new TestRequestListener();
+ sp = setupServer(null, id, testRequestListener, SERVICE_TYPE, INSTANCE_NAME);
+
+ // Set up connection and client.
+ connection = setupConnection(sp);
+ 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.receivedCallbackRequest);
+ assertFalse(testRequestListener.receivedCallback);
+ assertTrue(testRequestListener.receivedClientConnector);
+ assertTrue(testRequestListener.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 (sp != null) {
+ sp.close();
+ }
+ exit();
+ }
+ }
+
+ protected Connection setupConnection(ServerPackage sp) throws IOException, URISyntaxException {
+ Endpoint endpoint = sp.endpoint;
+ URI uri = new URI(getRemotingScheme() + "://localhost");
+ Connection connection = getFutureResult(endpoint.connect(uri, getConnectionOptionMap(), "user", null, "password".toCharArray()), "unable to connect to " + uri);
+ return connection;
+ }
+
+ protected Client<Object, Object> setupClient(Connection connection, String serviceType, String instanceName) throws IOException, URISyntaxException {
+ Client<Object, Object> client = getFutureResult(connection.openClient(serviceType, instanceName, Object.class, Object.class), "unable to open client to " + serviceType + ":" + instanceName);
+ return client;
+ }
+
+ static public class TestRequestListener implements RequestListener<Object, Object> {
+ public boolean receivedCallbackRequest;
+ public boolean receivedCallback;
+ public boolean receivedClientConnector;
+ public boolean sentCallback;
+
+ public TestRequestListener() {
+ new Exception(this + ": TestRequestListener()").printStackTrace();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void handleRequest(final RequestContext<Object> requestContext, final Object request) throws RemoteExecutionException {
+ try {
+ log.info(this + " got request %s: ", request);
+ if (request.equals(CALLBACK_REQUEST)) {
+ receivedCallbackRequest = true;
+ Connection connection = requestContext.getContext().getConnection();
+ IoFuture<? extends Client<Object, Object>> future = connection.openClient(SERVICE_TYPE, INSTANCE_NAME, Object.class, Object.class);
+ Client<Object, Object> client = getFutureResult(future, 5000, "Unable to create Client");
+ sentCallback = OK.equals(client.invoke(CALLBACK));
+ requestContext.sendReply(OK);
+ log.info(this + " sent callback using RequestContext: " + sentCallback);
+ } else if (request.equals(CALLBACK)) {
+ receivedCallback = true;
+ requestContext.sendReply(OK);
+ } else if (request instanceof ClientConnector<?, ?>) {
+ receivedClientConnector = true;
+ ClientConnector<Object, Object> clientConnector = (ClientConnector) request;
+ Client<Object, Object> callbackClient = getFutureResult(clientConnector.getFutureClient(), 5000, "unable to get callback client");
+ sentCallback = OK.equals(callbackClient.invoke(CALLBACK));
+ requestContext.sendReply(OK);
+ log.info(this + " sent callback using ClientConnector: " + sentCallback);
+ } else {
+ throw new RuntimeException("unexpected request: " + request);
+ }
+ } catch (IOException e) {
+ log.error(e, "reply");
+ throw new RemoteExecutionException(e);
+ }
+ }
+ }
+}
14 years, 3 months
JBoss Remoting SVN: r6091 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:49:06 -0400 (Tue, 07 Sep 2010)
New Revision: 6091
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientConnectorMisuseTestCase.java
Log:
JBREM-1228: New unit test.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientConnectorMisuseTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientConnectorMisuseTestCase.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientConnectorMisuseTestCase.java 2010-09-07 19:49:06 UTC (rev 6091)
@@ -0,0 +1,160 @@
+/*
+ * 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 java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ServiceLoader;
+
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.ClientConnector;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.spi.RemotingServiceDescriptor;
+import org.jboss.xnio.log.Logger;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests an attempt to use a ClientConnector locally.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright August 27, 2010
+ */
+@Test(suiteName = "ClientConnectorMisuse")
+public class ClientConnectorMisuseTestCase extends RemotingTestBase {
+
+ private static final Logger log = Logger.getLogger(ClientConnectorMisuseTestCase.class);
+
+ private static int counter;
+
+ @BeforeMethod
+ public void setUp() {
+ ServiceLoader.load(RemotingServiceDescriptor.class);
+ }
+
+ @AfterMethod
+ public void tearDown() throws IOException {
+ }
+
+ /**
+ * Distinct Executors, Endpoints, Xnio's, TcpServers, RequestListeners.
+ * One instance of one service in each Endpoint.
+ * Two Connections per TcpServer, two Clients per Connection.
+ */
+ @Test
+ public void testClientConnectorMisuse() throws Exception {
+ enter();
+ ServerPackage sp = null;
+ Connection connection = null;
+ Client<Object, Object> client = null;
+
+ try {
+ int id = counter++;
+
+ // Set up services.
+ TestRequestListener testRequestListener = new TestRequestListener(id);
+ sp = setupServer(null, id, testRequestListener, "test", "test");
+
+ // Set up connection and client.
+ connection = setupConnection(sp.port);
+ client = setupClient(connection, "test", "test");
+
+ // Test connection.
+ assertEquals(id, client.invoke("dummy"), "Should be equal");
+
+ // Get ClientConnector and attempt to use it locally.
+ ClientConnector<Object, Object> clientConnector = null;
+ clientConnector = connection.createClientConnector(new RequestListener<Object, Object>() {
+ public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException { }
+ }, Object.class, Object.class);
+
+ try {
+ Client<Object, Object> client2 = getFutureResult(clientConnector.getFutureClient(), "unable to get client");
+ client2.invoke(new Object());
+ Assert.fail("expected SecurityException");
+ } catch (SecurityException e) {
+ log.info("received expected SecurityException");
+ }
+
+ log.info(getName() + " PASSES");
+ } finally {
+ if (client != null) {
+ client.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ if (sp != null) {
+ sp.close();
+ }
+ exit();
+ }
+ }
+
+ protected Connection setupConnection(int port) throws IOException, URISyntaxException {
+ Endpoint endpoint = Remoting.getConfiguredEndpoint();
+ URI uri = new URI(getRemotingScheme() + "://localhost:" + port);
+ Connection connection = getFutureResult(endpoint.connect(uri, getConnectionOptionMap(), "user", null, "password".toCharArray()), "unable to connect to " + uri);
+ return connection;
+ }
+
+ protected Client<Object, Object> setupClient(Connection connection, String serviceType, String instanceName) throws IOException, URISyntaxException {
+ Client<Object, Object> client = getFutureResult(connection.openClient(serviceType, instanceName, Object.class, Object.class), "unable to open client to " + serviceType + ":" + instanceName);
+ return client;
+ }
+
+ static class TestRequestListener implements RequestListener<Object, Object> {
+ public int counter = 0;
+ private int answer;
+
+ public TestRequestListener(int answer) {
+ this.answer = answer;
+ }
+
+ public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException {
+ try {
+ counter++;
+ context.sendReply(answer);
+ } catch (IOException e) {
+ try {
+ context.sendFailure("error returning response", e);
+ } catch (IOException e1) {
+ e.printStackTrace();
+ throw new RemoteExecutionException("error returning exception", e1);
+ }
+ }
+ }
+ }
+}
14 years, 3 months
JBoss Remoting SVN: r6090 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:46:30 -0400 (Tue, 07 Sep 2010)
New Revision: 6090
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java
Log:
JBREM-1228: createTcpServer() uses port 0.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java 2010-09-07 19:44:50 UTC (rev 6089)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java 2010-09-07 19:46:30 UTC (rev 6090)
@@ -86,8 +86,8 @@
}
@Override
- protected void createTcpServer(ServerPackage sp, ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener, int port) throws IOException {
- log.info(this + " creating SslTcpServer");
+ protected void createTcpServer(ServerPackage sp, ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener) throws IOException {
+ log.debug(this + " creating SslTcpServer");
Builder builder = OptionMap.builder();
builder.setSequence(Options.SSL_ENABLED_CIPHER_SUITES, CIPHER_SUITES);
builder.setSequence(Options.SSL_ENABLED_PROTOCOLS, PROTOCOLS);
@@ -99,7 +99,7 @@
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
- IoFuture<? extends BoundChannel<InetSocketAddress>> future = sslTcpServer.bind(new InetSocketAddress("localhost", port));
+ IoFuture<? extends BoundChannel<InetSocketAddress>> future = sslTcpServer.bind(new InetSocketAddress("localhost", 0));
getFutureResult(future, "unable to bind " + sp.tcpServer);
sp.tcpServer = sslTcpServer;
sp.port = sslTcpServer.getChannels().iterator().next().getLocalAddress().getPort();
14 years, 3 months
JBoss Remoting SVN: r6089 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:44:50 -0400 (Tue, 07 Sep 2010)
New Revision: 6089
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java
Log:
JBREM-1228: Extends RemotingRootTestBase instead of RemotingTestBase; added new tests.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java 2010-09-07 19:37:19 UTC (rev 6088)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java 2010-09-07 19:44:50 UTC (rev 6089)
@@ -25,6 +25,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
+import static org.testng.Assert.fail;
import java.io.IOException;
import java.util.HashMap;
@@ -38,6 +39,7 @@
import org.jboss.remoting3.RemotingOptions;
import org.jboss.remoting3.RequestContext;
import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.ServiceRegistrationException;
import org.jboss.remoting3.ServiceRegistrationListener;
import org.jboss.remoting3.Endpoint.ServiceBuilder;
import org.jboss.xnio.OptionMap;
@@ -58,7 +60,7 @@
* @param <O>
*/
@Test(suiteName = "ServiceRegistration")
-public class ServiceRegistrationTestCase<O> extends RemotingTestBase {
+public class ServiceRegistrationTestCase<O> extends RemotingRootTestBase {
private static final Logger log = Logger.getLogger(ServiceRegistrationTestCase.class);
private static Object lock = new Object();
@@ -71,12 +73,50 @@
public void tearDown() throws IOException {
}
+ @SuppressWarnings("unchecked")
@Test
+ public void testRegistrationErrors() throws Exception {
+ enter();
+
+ Endpoint endpoint = Remoting.getConfiguredEndpoint();
+ final ServiceBuilder<?, ?> sb = endpoint.serviceBuilder();
+ sb.setInstanceName("instance");
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ sb.setServiceType("service");
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.setRequestType(null);}});
+ sb.setRequestType(RequestType.class);
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.setReplyType(null);}});
+ sb.setReplyType(ReplyType.class);
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.setOptionMap(null);}});
+ final ServiceBuilder<RequestType, ReplyType> sb2 = (ServiceBuilder<RequestType, ReplyType>) sb;
+ sb2.setClientListener(new TestClientListener());
+ OptionMap optionMap = OptionMap.builder().set(RemotingOptions.METRIC, -1).getMap();
+ sb2.setOptionMap(optionMap);
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ sb.setOptionMap(OptionMap.EMPTY);
+ sb.setInstanceName(":instance");
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ sb.setInstanceName("instance");
+ sb.setServiceType("0service");
+ testIllegalArgumentException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ sb.setServiceType("service");
+ sb.register();
+ testServiceRegistrationException(sb, new TestAction() {public void run() throws Exception {sb.register();}});
+ }
+
+ @Test
public void testRegistration() throws Exception {
enter();
Endpoint endpoint = Remoting.getConfiguredEndpoint();
- TestServiceRegistrationListener registrationListener = new TestServiceRegistrationListener();
- endpoint.addServiceRegistrationListener(registrationListener, null);
+
+ // Register listener before registering a service.
+ TestServiceRegistrationListener registrationListener1 = new TestServiceRegistrationListener();
+ Registration serviceListenerRegistration = endpoint.addServiceRegistrationListener(registrationListener1, null);
+
+ // Register a service.
TestClassLoader testClassLoader = new TestClassLoader();
ClientListener<RequestType, ReplyType> testClientListener = new TestClientListener();
Registration registration = null;
@@ -92,21 +132,41 @@
sb.setOptionMap(optionMap);
sb.setClientListener(testClientListener);
registration = sb.register();
+
+ // Test listener.
+ synchronized (lock) {
+ lock.wait();
+ }
+ assertNotNull(registrationListener1.info);
+ assertSame(testClassLoader, registrationListener1.info.getServiceClassLoader());
+ assertEquals("instance", registrationListener1.info.getInstanceName());
+ assertEquals("service", registrationListener1.info.getServiceType());
+ assertEquals(SuperRequestType.class, registrationListener1.info.getRequestClass());
+ assertEquals(SubReplyType.class, registrationListener1.info.getReplyClass());
+ assertSame(optionMap, registrationListener1.info.getOptionMap());
+ // Register a listener after registering a service.
+ TestServiceRegistrationListener registrationListener2 = new TestServiceRegistrationListener();
+ endpoint.addServiceRegistrationListener(registrationListener2, null);
+
+ // Test listener.
synchronized (lock) {
lock.wait();
}
- assertNotNull(registrationListener.info);
- assertSame(testClassLoader, registrationListener.info.getServiceClassLoader());
- assertEquals("instance", registrationListener.info.getInstanceName());
- assertEquals("service", registrationListener.info.getServiceType());
- assertEquals(SuperRequestType.class, registrationListener.info.getRequestClass());
- assertEquals(SubReplyType.class, registrationListener.info.getReplyClass());
- assertSame(optionMap, registrationListener.info.getOptionMap());
+ assertNotNull(registrationListener2.info);
+ assertSame(testClassLoader, registrationListener2.info.getServiceClassLoader());
+ assertEquals("instance", registrationListener2.info.getInstanceName());
+ assertEquals("service", registrationListener2.info.getServiceType());
+ assertEquals(SuperRequestType.class, registrationListener2.info.getRequestClass());
+ assertEquals(SubReplyType.class, registrationListener2.info.getReplyClass());
+ assertSame(optionMap, registrationListener2.info.getOptionMap());
- log.info(getName() + " PASSES");
-
+ log.debug(getName() + " PASSES");
+
} finally {
+ if (serviceListenerRegistration != null) {
+ serviceListenerRegistration.close();
+ }
if (registration != null) {
registration.close();
}
@@ -116,7 +176,40 @@
exit();
}
}
-
+
+ protected void testIllegalArgumentException(ServiceBuilder<?, ?> sb, TestAction action) {
+ try {
+ action.run();
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // good
+ } catch (Exception e) {
+ fail("expected IllegalArgumentException");
+ }
+ }
+
+ protected void testServiceRegistrationException(ServiceBuilder<?, ?> sb, TestAction action) {
+ try {
+ action.run();
+ fail("expected ServiceRegistrationException");
+ } catch (ServiceRegistrationException e) {
+ // good
+ } catch (Exception e) {
+ fail("expected ServiceRegistrationException");
+ }
+ }
+
+ protected void testForNullPointerException(ServiceBuilder<RequestType, ReplyType> sb) {
+ try {
+ sb.register();
+ fail("expected NullPointerException");
+ } catch (NullPointerException e) {
+ // good
+ } catch (Exception e) {
+ fail("expected NullPointerException");
+ }
+ }
+
protected OptionMap buildOptionMap() {
Builder builder = OptionMap.builder();
builder.set(RemotingOptions.METRIC, 1);
@@ -127,7 +220,11 @@
builder.add(map);
return builder.getMap();
}
-
+
+ interface TestAction {
+ void run() throws Exception;
+ }
+
static class TestClassLoader extends ClassLoader {
}
@@ -158,6 +255,7 @@
public ServiceInfo info;
public void serviceRegistered(Registration listenerHandle, ServiceInfo info) {
+ log.info(this + ".serviceRegistered() entered");
this.info = info;
synchronized (lock) {
lock.notify();
14 years, 3 months