@Test public void testSimpleMessageSendAndReceiveTransacted() throws Exception { setDummyTX(); setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); }
private void testSendAndReceive(Boolean ignoreJTA) throws Exception { setDummyTX(); setupDLQ(10); resourceAdapter = newResourceAdapter(); if (ignoreJTA != null) { resourceAdapter.setIgnoreJTA(ignoreJTA); } MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); }
@Override @Before public void setUp() throws Exception { useDummyTransactionManager(); super.setUp(); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setEntries("[\"java://jmsXA\"]"); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
@Test public void testSimpleMessageSendAndReceiveNotTransacted() throws Exception { setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); }
@Test public void testSimpleMessageSendAndReceiveSessionTransacted2() throws Exception { setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(Session.SESSION_TRANSACTED); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); }
@Test public void testSimpleMessageSendAndReceiveSessionTransacted() throws Exception { setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(true, Session.SESSION_TRANSACTED); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); }
ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager(); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(qResourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
@Test public void testJMSContext() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); JMSContext jmsctx = qraConnectionFactory.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE); assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, jmsctx.getSessionMode()); }
ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager(); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
@Test public void testConnectionCredentialsOKRecovery() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(mcf.getResourceRecovery()); }
@Test public void testConnectionCredentials() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testpassword"); session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); }
@Test public void testMultipleSessionsThrowsException() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { Session s2 = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); fail("should throw javax,jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6"); } catch (JMSException e) { } }
@Override @Before public void setUp() throws Exception { useDummyTransactionManager(); super.setUp(); ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager(); securityManager.getConfiguration().addUser("testuser", "testpassword"); securityManager.getConfiguration().addUser("guest", "guest"); securityManager.getConfiguration().setDefaultUser("guest"); securityManager.getConfiguration().addRole("testuser", "arole"); securityManager.getConfiguration().addRole("guest", "arole"); Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
@Override @Before public void setUp() throws Exception { super.setUp(); ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager(); securityManager.getConfiguration().addUser("testuser", "testpassword"); securityManager.getConfiguration().addUser("guest", "guest"); securityManager.getConfiguration().setDefaultUser("guest"); securityManager.getConfiguration().addRole("testuser", "arole"); securityManager.getConfiguration().addRole("guest", "arole"); Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setEntries("[\"java://jmsXA\"]"); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager(); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
@Test public void testConnectionCredentialsFailRecovery() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); try { QueueConnection queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword"); queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close(); fail("should throw esxception"); } catch (JMSException e) { //make sure the recovery is null assertNull(mcf.getResourceRecovery()); } }
@Override @Before public void setUp() throws Exception { useDummyTransactionManager(); super.setUp(); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("testuser", "testpassword"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("testuser", "arole"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "arole"); Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setEntries("[\"java://jmsXA\"]"); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
@Override @Before public void setUp() throws Exception { useDummyTransactionManager(); super.setUp(); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("testuser", "testpassword"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("testuser", "arole"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "arole"); Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setEntries("[\"java://jmsXA\"]"); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
@Test public void testConnectionCredentialsFail() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection(); queueConnection.close(); mc.destroy(); try { queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword"); queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close(); fail("should throw esxception"); } catch (JMSException e) { //pass } }
resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);