[jboss-svn-commits] JBL Code SVN: r21111 - in labs/jbossesb/trunk/product/rosetta: tests/src/org/jboss/soa/esb/listeners and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 18 09:52:51 EDT 2008
Author: tfennelly
Date: 2008-07-18 09:52:50 -0400 (Fri, 18 Jul 2008)
New Revision: 21111
Added:
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBRIntegratedUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/async_response.txt
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-01.xml
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-02.xml
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
Log:
https://jira.jboss.org/jira/browse/JBESB-1428
Made life very difficult for myself. Tried updating the test runner code but ran into one of those snowball issues where fixing it required fixing 2 other things etc etc, so I just reverted it back :-(
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2008-07-18 13:23:49 UTC (rev 21110)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2008-07-18 13:52:50 UTC (rev 21111)
@@ -22,6 +22,7 @@
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.remoting.HttpMarshaller;
import org.jboss.internal.soa.esb.remoting.HttpUnmarshaller;
+import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.ServerInvocationHandler;
@@ -48,6 +49,7 @@
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.jboss.soa.esb.util.ClassUtil;
import javax.management.MBeanServer;
import java.net.InetAddress;
@@ -141,6 +143,10 @@
* Is the listener synchronous.
*/
private boolean synchronous = true;
+ /**
+ * Asynchronous response.
+ */
+ private String asyncResponse;
/**
* Install our own marshaller/unmarshaller for HTTP.
@@ -163,6 +169,13 @@
serviceCategory = config.getAttribute(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG);
serviceName = config.getAttribute(ListenerTagNames.TARGET_SERVICE_NAME_TAG);
synchronous = !config.getAttribute("synchronous", "true").equalsIgnoreCase("false");
+ asyncResponse = config.getAttribute("asyncResponse");
+
+ if(asyncResponse != null) {
+ if(ClassUtil.getResourceAsStream(asyncResponse, getClass()) == null) {
+ throw new ConfigurationException("Asynchronous response resource file '" + asyncResponse + "' not found on classpath.");
+ }
+ }
}
/**
@@ -322,12 +335,6 @@
logger.debug("Returning response [" + response + "].");
}
- /*
- if(response instanceof String) {
- response = ((String)response).getBytes("UTF-8");
- }
- */
-
return response;
} else {
messageDeliveryAdapter.deliverAsync(invocationRequest);
@@ -340,7 +347,11 @@
throw t;
}
- return "<ack/>";
+ if(asyncResponse == null) {
+ return "<ack/>";
+ } else {
+ return StreamUtils.readStreamString(getClass().getResourceAsStream(asyncResponse), "UTF-8");
+ }
}
public void setMBeanServer(MBeanServer mBeanServer) {
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java 2008-07-18 13:23:49 UTC (rev 21110)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java 2008-07-18 13:52:50 UTC (rev 21111)
@@ -64,7 +64,7 @@
message.getBody().add("Hi there!");
invoker.deliverAsync(message);
- sleep(50);
+ waitForMockSet(message);
assertTrue(message == MockAction.message);
}
}.setServiceConfig("in-listener-config-01.xml");
@@ -234,10 +234,21 @@
message.getBody().add("Hi there!");
invoker.deliverAsync(message);
- sleep(50);
+ waitForMockSet(message);
assertTrue(message == MockAction.message);
}
+ private void waitForMockSet(Message message) {
+ long start = System.currentTimeMillis();
+
+ while(System.currentTimeMillis() - start < 5000) {
+ if(message == MockAction.message) {
+ return;
+ }
+ sleep(50);
+ }
+ }
+
private static void sleep(long millis) {
try {
Thread.sleep(millis);
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBRIntegratedUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBRIntegratedUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBRIntegratedUnitTest.java 2008-07-18 13:52:50 UTC (rev 21111)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import junit.framework.TestCase;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.testutils.AbstractTestRunner;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Client;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JBRIntegratedUnitTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ System.setProperty(Environment.DEFAULT_INVM_SCOPE, "GLOBAL");
+ }
+
+ protected void tearDown() throws Exception {
+ System.setProperty(Environment.DEFAULT_INVM_SCOPE, "NONE");
+ }
+
+ public void test_JBESB_1428_01() throws Exception {
+ new AbstractTestRunner() {
+ public void test() throws Exception {
+ String response = (String) sendMessageToServer("http://localhost:8769", "Hi there!!");
+ assertEquals("<ack/>", response);
+ }
+ }.setServiceConfig("jbr-async-config-01.xml").run();
+ }
+
+ public void test_JBESB_1428_02() throws Exception {
+ new AbstractTestRunner() {
+ public void test() throws Exception {
+ String response = (String) sendMessageToServer("http://localhost:8769", "Hi there!!");
+ assertEquals("<async_ack_from-file/>", response);
+ }
+ }.setServiceConfig("jbr-async-config-02.xml").run();
+ }
+
+ private Object sendMessageToServer(String url, Object messagePayload) throws Exception {
+ InvokerLocator locator = new InvokerLocator(url);
+
+ Client remotingClient = null;
+ try {
+ remotingClient = new Client(locator);
+ remotingClient.connect();
+
+ try {
+ return remotingClient.invoke(messagePayload);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ fail("Error making JBR Client invocation.");
+ throw new Exception(); // keep the compiler happy!!
+ }
+ } finally {
+ if(remotingClient != null) {
+ remotingClient.disconnect();
+ }
+ }
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBRIntegratedUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/async_response.txt
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/async_response.txt (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/async_response.txt 2008-07-18 13:52:50 UTC (rev 21111)
@@ -0,0 +1 @@
+<async_ack_from-file/>
\ No newline at end of file
Copied: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-01.xml (from rev 21087, labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/in-listener-config-01.xml)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-01.xml (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-01.xml 2008-07-18 13:52:50 UTC (rev 21111)
@@ -0,0 +1,23 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
+
+ <providers>
+ <jbr-provider name="http" protocol="http" host="localhost">
+ <jbr-bus busid="http1" port="8769" />
+ </jbr-provider>
+ </providers>
+
+ <services>
+ <service category="ServiceCat" name="ServiceName" description="Test Service">
+ <listeners>
+ <jbr-listener name="http" busidref="http1" is-gateway="true">
+ <property name="synchronous" value="false" />
+ </jbr-listener>
+ </listeners>
+ <actions mep="RequestResponse">
+ <action name="action" class="org.jboss.soa.esb.mock.MockAction" />
+ </actions>
+ </service>
+ </services>
+
+</jbossesb>
\ No newline at end of file
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-02.xml
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-02.xml (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-02.xml 2008-07-18 13:52:50 UTC (rev 21111)
@@ -0,0 +1,24 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
+
+ <providers>
+ <jbr-provider name="http" protocol="http" host="localhost">
+ <jbr-bus busid="http1" port="8769" />
+ </jbr-provider>
+ </providers>
+
+ <services>
+ <service category="ServiceCat" name="ServiceName" description="Test Service">
+ <listeners>
+ <jbr-listener name="http" busidref="http1" is-gateway="true">
+ <property name="synchronous" value="false" />
+ <property name="asyncResponse" value="/org/jboss/soa/esb/listeners/gateway/async_response.txt" />
+ </jbr-listener>
+ </listeners>
+ <actions mep="RequestResponse">
+ <action name="action" class="org.jboss.soa.esb.mock.MockAction" />
+ </actions>
+ </service>
+ </services>
+
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/jbr-async-config-02.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list