protected void deleteQueue(final int node, final String queueName) throws Exception { ClientSessionFactory sf = sfs[node]; if (sf == null) { throw new IllegalArgumentException("No sf at " + node); } ClientSession session = sf.createSession(false, true, true); session.deleteQueue(queueName); session.close(); }
@Test public void testBasicReceive() throws Exception { ClientSessionFactory cf = createSessionFactory(locator); ClientSession sendSession = cf.createSession(false, true, true); ClientProducer cp = sendSession.createProducer(addressA); ClientSession session = cf.createSession(false, true, true); session.createQueue(addressA, queueA, false); ClientConsumer cc = session.createConsumer(queueA); session.start(); cp.send(sendSession.createMessage(false)); Assert.assertNotNull(cc.receive()); session.close(); sendSession.close(); }
protected void doTestK(final ClientSessionFactory sf) throws Exception { ClientSession s = sf.createSession(false, false, false); s.createQueue(RandomReattachTest.ADDRESS, RandomReattachTest.ADDRESS, null, false); final int numConsumers = 100; for (int i = 0; i < numConsumers; i++) { ClientConsumer consumer = s.createConsumer(RandomReattachTest.ADDRESS); consumer.close(); } s.deleteQueue(RandomReattachTest.ADDRESS); s.close(); }
@Test public void testCreateMessageDurable() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); ClientMessage clientMessage = clientSession.createMessage(true); Assert.assertTrue(clientMessage.isDurable()); clientSession.close(); }
@Test public void testStart() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); clientSession.createQueue(queueName, queueName, false); clientSession.start(); clientSession.close(); }
@Test public void testCreateMessageNonDurable() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); ClientMessage clientMessage = clientSession.createMessage(false); Assert.assertFalse(clientMessage.isDurable()); clientSession.close(); }
protected void doTestK(final ClientSessionFactory sf, final int threadNum) throws Exception { ClientSession s = sf.createSession(false, false, false); s.addMetaData("data", RandomUtil.randomString()); s.createQueue(MultiThreadRandomReattachTestBase.ADDRESS, new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()), (SimpleString) null, false); final int numConsumers = 100; for (int i = 0; i < numConsumers; i++) { ClientConsumer consumer = s.createConsumer(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); consumer.close(); } s.deleteQueue(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); s.close(); }
protected void createQueue(final String address, final String queue) throws Exception { ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); try { session.createQueue(address, queue); } finally { session.close(); closeSessionFactory(sf); closeServerLocator(locator); } }
@Test public void testConsumeFromTemporaryQueueCreatedByOtherSession() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); session.createTemporaryQueue(address, queue); ClientProducer producer = session.createProducer(address); producer.send(session.createMessage(false)); ClientSession session2 = sf.createSession(false, true, true); session2.start(); ClientConsumer consumer = session2.createConsumer(queue); ClientMessage message = consumer.receive(500); assertNotNull(message); session2.close(); session.close(); }
@Test public void testCreateMessageType() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); ClientMessage clientMessage = clientSession.createMessage((byte) 99, false); Assert.assertEquals((byte) 99, clientMessage.getType()); clientSession.close(); }
@Before public void createQueue() throws Exception { ServerLocator locator = createFactory(isNetty()); ClientSessionFactory sf = createSessionFactory(locator); ClientSessionFactory sf2 = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true, true); server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false); session.close(); sf.close(); locator.close(); }
@Test public void testCoreHttpClientIdle() throws Exception { locator.setConnectionTTL(500); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.createQueue(QUEUE, QUEUE, null, false); ClientProducer producer = session.createProducer(QUEUE); Thread.sleep(500 * 5); session.close(); }
@Test public void testGetVersion() throws Exception { cf = createSessionFactory(locator); ClientSession clientSession = cf.createSession(false, true, true); Assert.assertEquals(server.getVersion().getIncrementingVersion(), clientSession.getVersion()); clientSession.close(); }
protected void doTestJ(final ClientSessionFactory sf) throws Exception { ClientSession sessCreate = sf.createSession(false, true, true); sessCreate.createQueue(RandomReattachTest.ADDRESS, RandomReattachTest.ADDRESS, null, false); ClientSession sess = sf.createSession(false, true, true); sess.start(); ClientConsumer consumer = sess.createConsumer(RandomReattachTest.ADDRESS); ClientProducer producer = sess.createProducer(RandomReattachTest.ADDRESS); ClientMessage message = sess.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1); producer.send(message); ClientMessage message2 = consumer.receive(RandomReattachTest.RECEIVE_TIMEOUT); Assert.assertNotNull(message2); message2.acknowledge(); sess.close(); sessCreate.deleteQueue(RandomReattachTest.ADDRESS); sessCreate.close(); }
@Test public void testStaticConnectorListConstructor() throws Exception { TransportConfiguration[] tc = new TransportConfiguration[]{liveTC}; ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(tc); assertFactoryParams(locator, tc, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); Assert.assertNotNull(session); session.close(); testSettersThrowException(cf); cf.close(); }
@Test public void testReceiveTimesoutCorrectly() throws Exception { ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); session.createQueue(addressA, queueA, false); ClientConsumer cc = session.createConsumer(queueA); session.start(); long time = System.currentTimeMillis(); cc.receive(1000); Assert.assertTrue(System.currentTimeMillis() - time >= 1000); session.close(); }
@Test public void testSynchronousClose() throws Exception { Assert.assertEquals(0, server.getActiveMQServerControl().listRemoteAddresses().length); ClientSessionFactory sf = createSessionFactory(); for (int i = 0; i < 2000; i++) { ClientSession session = sf.createSession(false, true, true); session.close(); } sf.close(); sf.getServerLocator().close(); } }
protected void doTestI(final ClientSessionFactory sf) throws Exception { ClientSession sessCreate = sf.createSession(false, true, true); sessCreate.createQueue(RandomReattachTest.ADDRESS, RandomReattachTest.ADDRESS, null, false); ClientSession sess = sf.createSession(false, true, true); sess.start(); ClientConsumer consumer = sess.createConsumer(RandomReattachTest.ADDRESS); ClientProducer producer = sess.createProducer(RandomReattachTest.ADDRESS); ClientMessage message = sess.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1); producer.send(message); ClientMessage message2 = consumer.receive(RandomReattachTest.RECEIVE_TIMEOUT); Assert.assertNotNull(message2); message2.acknowledge(); sess.close(); sessCreate.deleteQueue(RandomReattachTest.ADDRESS); sessCreate.close(); }
@Test public void testDiscoveryConstructor() throws Exception { ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(groupConfiguration); assertFactoryParams(locator, null, groupConfiguration, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); Assert.assertNotNull(session); session.close(); testSettersThrowException(cf); cf.close(); locator.close(); }
@Test public void testFailXID() throws Exception { Xid xid = newXID(); ClientSession session = sessionFactory.createSession(true, false, false); session.start(xid, XAResource.TMNOFLAGS); session.end(xid, XAResource.TMFAIL); session.rollback(xid); session.close(); }