Author: ataylor
Date: 2011-12-21 08:42:08 -0500 (Wed, 21 Dec 2011)
New Revision: 11924
Added:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/BootstrapContext.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/MessageEndpointFactory.java
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/ra/inflow/HornetQActivation.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/ResourceAdapterTest.java
Log:
fix for ra jms meta data and tests
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/ra/inflow/HornetQActivation.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/ra/inflow/HornetQActivation.java 2011-12-21
12:29:50 UTC (rev 11923)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/ra/inflow/HornetQActivation.java 2011-12-21
13:42:08 UTC (rev 11924)
@@ -370,9 +370,10 @@
result.addMetaData("resource-adapter", "inbound");
result.addMetaData("jms-session", "");
- if (spec.getClientID() != null)
+ String clientID = ra.getClientID() == null?spec.getClientID():ra.getClientID();
+ if (clientID != null)
{
- result.addMetaData("jms-client-id", spec.getClientID());
+ result.addMetaData("jms-client-id", clientID);
}
HornetQActivation.log.debug("Using queue connection " + result);
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java 2011-12-21
12:29:50 UTC (rev 11923)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java 2011-12-21
13:42:08 UTC (rev 11924)
@@ -33,13 +33,15 @@
import junit.framework.Assert;
import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.management.JMSConnectionInfo;
import org.hornetq.api.jms.management.JMSConsumerInfo;
import org.hornetq.api.jms.management.JMSServerControl;
import org.hornetq.api.jms.management.JMSSessionInfo;
import org.hornetq.core.config.Configuration;
-import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
@@ -47,11 +49,17 @@
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;
+import org.hornetq.jms.client.HornetQDestination;
import org.hornetq.jms.client.HornetQMessage;
-import org.hornetq.jms.client.HornetQQueue;
import org.hornetq.jms.server.impl.JMSServerManagerImpl;
+import org.hornetq.jms.server.management.JMSManagementService;
+import org.hornetq.jms.server.management.impl.JMSManagementServiceImpl;
+import org.hornetq.ra.HornetQResourceAdapter;
+import org.hornetq.ra.inflow.HornetQActivation;
+import org.hornetq.ra.inflow.HornetQActivationSpec;
import org.hornetq.tests.integration.management.ManagementControlHelper;
import org.hornetq.tests.integration.management.ManagementTestBase;
+import org.hornetq.tests.unit.ra.MessageEndpointFactory;
import org.hornetq.tests.unit.util.InVMContext;
import org.hornetq.tests.util.RandomUtil;
@@ -469,6 +477,173 @@
}
}
}
+
+
+ public void testStartActivationListConnections() throws Exception
+ {
+ try
+ {
+ startHornetQServer(InVMAcceptorFactory.class.getName());
+ HornetQDestination queue =
(HornetQDestination)HornetQJMSClient.createQueue("test");
+ serverManager.createQueue(false, "test", null, true,
"test");
+
+ JMSServerControl control = createManagementControl();
+
+ HornetQResourceAdapter ra = new HornetQResourceAdapter();
+
+
ra.setConnectorClassName("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory");
+ ra.setUserName("userGlobal");
+ ra.setPassword("passwordGlobal");
+ ra.start(new org.hornetq.tests.unit.ra.BootstrapContext());
+ ra.setClientID("my-client-id");
+ ra.setUserName("user");
+ Connection conn = ra.getDefaultHornetQConnectionFactory().createConnection();
+
+ conn.close();
+
+ HornetQActivationSpec spec = new HornetQActivationSpec();
+
+ spec.setResourceAdapter(ra);
+
+ spec.setUseJNDI(false);
+
+ spec.setPassword("password");
+
+ spec.setDestinationType("Topic");
+ spec.setDestination("test");
+
+ spec.setMinSession(1);
+ spec.setMaxSession(1);
+
+ HornetQActivation activation = new HornetQActivation(ra, new
MessageEndpointFactory(), spec);
+
+ activation.start();
+
+ String cons = control.listConnectionsAsJSON();
+
+ JMSConnectionInfo[] jmsConnectionInfos = JMSConnectionInfo.from(cons);
+
+ assertEquals(1, jmsConnectionInfos.length);
+
+ assertEquals("user", jmsConnectionInfos[0].getUsername());
+
+ assertEquals("my-client-id", jmsConnectionInfos[0].getClientID());
+
+ activation.stop();
+
+ ra.stop();
+
+ }
+ finally
+ {
+ try
+ {
+ /*if (connection != null)
+ {
+ connection.close();
+ }*/
+
+ if (serverManager != null)
+ {
+ //serverManager.destroyQueue(queueName);
+ serverManager.stop();
+ }
+ }
+ catch (Throwable ignored)
+ {
+ ignored.printStackTrace();
+ }
+
+ if (server != null)
+ {
+ server.stop();
+ }
+ }
+ }
+
+ public void testStartActivationOverrideListConnections() throws Exception
+ {
+ try
+ {
+ startHornetQServer(InVMAcceptorFactory.class.getName());
+ HornetQDestination queue =
(HornetQDestination)HornetQJMSClient.createQueue("test");
+ serverManager.createQueue(false, "test", null, true,
"test");
+
+ JMSServerControl control = createManagementControl();
+
+ HornetQResourceAdapter ra = new HornetQResourceAdapter();
+
+
ra.setConnectorClassName("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory");
+ ra.setUserName("userGlobal");
+ ra.setPassword("passwordGlobal");
+ ra.start(new org.hornetq.tests.unit.ra.BootstrapContext());
+
+ Connection conn = ra.getDefaultHornetQConnectionFactory().createConnection();
+
+ conn.close();
+
+ HornetQActivationSpec spec = new HornetQActivationSpec();
+
+ spec.setResourceAdapter(ra);
+
+ spec.setUseJNDI(false);
+
+ spec.setClientId("my-client-id");
+
+ spec.setUser("user");
+ spec.setPassword("password");
+
+ spec.setDestinationType("Topic");
+ spec.setDestination("test");
+
+ spec.setMinSession(1);
+ spec.setMaxSession(1);
+
+ HornetQActivation activation = new HornetQActivation(ra, new
MessageEndpointFactory(), spec);
+
+ activation.start();
+
+ String cons = control.listConnectionsAsJSON();
+
+ JMSConnectionInfo[] jmsConnectionInfos = JMSConnectionInfo.from(cons);
+
+ assertEquals(1, jmsConnectionInfos.length);
+
+ assertEquals("user", jmsConnectionInfos[0].getUsername());
+
+ assertEquals("my-client-id", jmsConnectionInfos[0].getClientID());
+
+ activation.stop();
+
+ ra.stop();
+
+ }
+ finally
+ {
+ try
+ {
+ /*if (connection != null)
+ {
+ connection.close();
+ }*/
+
+ if (serverManager != null)
+ {
+ //serverManager.destroyQueue(queueName);
+ serverManager.stop();
+ }
+ }
+ catch (Throwable ignored)
+ {
+ ignored.printStackTrace();
+ }
+
+ if (server != null)
+ {
+ server.stop();
+ }
+ }
+ }
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Added: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/BootstrapContext.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/BootstrapContext.java
(rev 0)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/BootstrapContext.java 2011-12-21
13:42:08 UTC (rev 11924)
@@ -0,0 +1,65 @@
+package org.hornetq.tests.unit.ra;
+
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkListener;
+import javax.resource.spi.work.WorkManager;
+import java.util.Timer;
+
+public class BootstrapContext implements javax.resource.spi.BootstrapContext
+{
+ public Timer createTimer() throws UnavailableException
+ {
+ return null;
+ }
+
+ public WorkManager getWorkManager()
+ {
+ return new WorkManager()
+ {
+ public void doWork(final Work work) throws WorkException
+ {
+ }
+
+ public void doWork(final Work work,
+ final long l,
+ final ExecutionContext executionContext,
+ final WorkListener workListener) throws WorkException
+ {
+ }
+
+ public long startWork(final Work work) throws WorkException
+ {
+ return 0;
+ }
+
+ public long startWork(final Work work,
+ final long l,
+ final ExecutionContext executionContext,
+ final WorkListener workListener) throws WorkException
+ {
+ return 0;
+ }
+
+ public void scheduleWork(final Work work) throws WorkException
+ {
+ work.run();
+ }
+
+ public void scheduleWork(final Work work,
+ final long l,
+ final ExecutionContext executionContext,
+ final WorkListener workListener) throws WorkException
+ {
+ }
+ };
+ }
+
+ public XATerminator getXATerminator()
+ {
+ return null;
+ }
+}
\ No newline at end of file
Added:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/MessageEndpointFactory.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/MessageEndpointFactory.java
(rev 0)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/MessageEndpointFactory.java 2011-12-21
13:42:08 UTC (rev 11924)
@@ -0,0 +1,27 @@
+package org.hornetq.tests.unit.ra;
+
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.transaction.xa.XAResource;
+import java.lang.reflect.Method;
+
+public class MessageEndpointFactory implements
javax.resource.spi.endpoint.MessageEndpointFactory
+{
+
+ /* (non-Javadoc)
+ * @see
javax.resource.spi.endpoint.MessageEndpointFactory#createEndpoint(javax.transaction.xa.XAResource)
+ */
+ public MessageEndpoint createEndpoint(final XAResource arg0) throws
UnavailableException
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted(java.lang.reflect.Method)
+ */
+ public boolean isDeliveryTransacted(final Method arg0) throws NoSuchMethodException
+ {
+ return false;
+ }
+
+}
\ No newline at end of file
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/ResourceAdapterTest.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/ResourceAdapterTest.java 2011-12-21
12:29:50 UTC (rev 11923)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/ra/ResourceAdapterTest.java 2011-12-21
13:42:08 UTC (rev 11924)
@@ -13,7 +13,6 @@
package org.hornetq.tests.unit.ra;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -23,14 +22,11 @@
import javax.resource.spi.BootstrapContext;
import javax.resource.spi.UnavailableException;
import javax.resource.spi.XATerminator;
-import javax.resource.spi.endpoint.MessageEndpoint;
-import javax.resource.spi.endpoint.MessageEndpointFactory;
import javax.resource.spi.work.ExecutionContext;
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkException;
import javax.resource.spi.work.WorkListener;
import javax.resource.spi.work.WorkManager;
-import javax.transaction.xa.XAResource;
import junit.framework.Assert;
@@ -465,7 +461,7 @@
ra.setConnectorClassName("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory");
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
- ra.start(fakeCTX);
+ ra.start(new org.hornetq.tests.unit.ra.BootstrapContext());
Connection conn = ra.getDefaultHornetQConnectionFactory().createConnection();
@@ -486,7 +482,7 @@
spec.setMinSession(1);
spec.setMaxSession(1);
- HornetQActivation activation = new HornetQActivation(ra, new
FakeMessageEndpointFactory(), spec);
+ HornetQActivation activation = new HornetQActivation(ra, new
MessageEndpointFactory(), spec);
activation.start();
activation.stop();
@@ -526,81 +522,4 @@
}*/
}
- BootstrapContext fakeCTX = new BootstrapContext()
- {
-
- public Timer createTimer() throws UnavailableException
- {
- return null;
- }
-
- public WorkManager getWorkManager()
- {
- return new WorkManager()
- {
- public void doWork(final Work work) throws WorkException
- {
- }
-
- public void doWork(final Work work,
- final long l,
- final ExecutionContext executionContext,
- final WorkListener workListener) throws WorkException
- {
- }
-
- public long startWork(final Work work) throws WorkException
- {
- return 0;
- }
-
- public long startWork(final Work work,
- final long l,
- final ExecutionContext executionContext,
- final WorkListener workListener) throws WorkException
- {
- return 0;
- }
-
- public void scheduleWork(final Work work) throws WorkException
- {
- work.run();
- }
-
- public void scheduleWork(final Work work,
- final long l,
- final ExecutionContext executionContext,
- final WorkListener workListener) throws
WorkException
- {
- }
- };
- }
-
- public XATerminator getXATerminator()
- {
- return null;
- }
-
- };
-
- class FakeMessageEndpointFactory implements MessageEndpointFactory
- {
-
- /* (non-Javadoc)
- * @see
javax.resource.spi.endpoint.MessageEndpointFactory#createEndpoint(javax.transaction.xa.XAResource)
- */
- public MessageEndpoint createEndpoint(final XAResource arg0) throws
UnavailableException
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see
javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted(java.lang.reflect.Method)
- */
- public boolean isDeliveryTransacted(final Method arg0) throws
NoSuchMethodException
- {
- return false;
- }
-
- }
}