Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientSessionFactory#createSession()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientSessionFactory#createSession() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerWindowSizeTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testConsumerWindowSizeAddressSettingsDifferentAddressAndQueueName() throws Exception { ActiveMQServer messagingService = createServer(false, isNetty()); final int defaultConsumerWindowSize = 1024 * 5; final AddressSettings settings = new AddressSettings(); settings.setDefaultConsumerWindowSize(defaultConsumerWindowSize); messagingService.getConfiguration() .getAddressesSettings().put(addressA.toString(), settings); messagingService.start(); messagingService.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setRoutingType(RoutingType.ANYCAST)); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); ClientConsumerImpl consumer = (ClientConsumerImpl) session.createConsumer(queueA); session.start(); assertEquals(defaultConsumerWindowSize / 2, consumer.getClientWindowSize()); ServerSession ss = messagingService.getSessionByID(((ClientSessionImpl)session).getName()); ServerConsumerImpl cons = (ServerConsumerImpl) ss.locateConsumer(consumer.getConsumerContext().getId()); assertTrue(Wait.waitFor(() -> cons.getAvailableCredits().get() == consumer.getClientWindowSize() * 2, 5000, 50)); }
Example 2
Source File: ScaleDownHandler.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void scaleDownDuplicateIDs(Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap, ClientSessionFactory sessionFactory, SimpleString managementAddress, String user, String password) throws Exception { try (ClientSession session = sessionFactory.createSession(user, password, true, false, false, false, 0); ClientProducer producer = session.createProducer(managementAddress)) { //todo - https://issues.jboss.org/browse/HORNETQ-1336 for (Map.Entry<SimpleString, List<Pair<byte[], Long>>> entry : duplicateIDMap.entrySet()) { ClientMessage message = session.createMessage(false); List<Pair<byte[], Long>> list = entry.getValue(); String[] array = new String[list.size()]; for (int i = 0; i < list.size(); i++) { Pair<byte[], Long> pair = list.get(i); array[i] = new String(pair.getA()); } ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "updateDuplicateIdCache", entry.getKey().toString(), array); producer.send(message); } } }
Example 3
Source File: SessionSendAcknowledgementHandlerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testHandlerOnSendWithAnonymousProducer() throws Exception { final int MSG_COUNT = 750; ServerLocator locator = createInVMNonHALocator(); locator.setConfirmationWindowSize(256); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(); final AtomicInteger count = new AtomicInteger(0); ClientProducer producer = session.createProducer(); for (int i = 0; i < MSG_COUNT; i++) { ClientMessage message = session.createMessage(true); producer.send(address, message, message1 -> count.incrementAndGet()); } Wait.assertEquals(MSG_COUNT, () -> count.get(), 2000, 100); }
Example 4
Source File: ProducerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testProducerWithSmallWindowSizeAndLargeMessage() throws Exception { final CountDownLatch latch = new CountDownLatch(1); server.getRemotingService().addIncomingInterceptor(new Interceptor() { @Override public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException { if (packet.getType() == PacketImpl.SESS_SEND) { latch.countDown(); } return true; } }); ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100); ClientSessionFactory cf = locator.createSessionFactory(); ClientSession session = cf.createSession(false, true, true); ClientProducer producer = session.createProducer(QUEUE); ClientMessage message = session.createMessage(true); byte[] body = new byte[1000]; message.getBodyBuffer().writeBytes(body); producer.send(message); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); session.close(); locator.close(); }
Example 5
Source File: ShutdownServerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testShutdownServer() throws Throwable { ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true, false); session.createQueue(new QueueConfiguration(QUEUE)); ClientConsumer consumer = session.createConsumer(QUEUE); ClientProducer producer = session.createProducer(QUEUE); ClientMessage message = session.createMessage(Message.TEXT_TYPE, true, 0, System.currentTimeMillis(), (byte) 4); message.getBodyBuffer().writeString("hi"); message.putStringProperty("hello", "elo"); producer.send(message); ActiveMQServerImpl impl = (ActiveMQServerImpl) server; JournalStorageManager journal = (JournalStorageManager) impl.getStorageManager(); JDBCJournalImpl journalimpl = (JDBCJournalImpl) journal.getMessageJournal(); journalimpl.handleException(null, new Exception("failure")); Wait.waitFor(() -> !server.isStarted()); Assert.assertFalse(server.isStarted()); }
Example 6
Source File: LVQRecoveryTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); configuration = createDefaultInVMConfig(); server = createServer(true, configuration); server.start(); qs = new AddressSettings().setDefaultLastValueQueue(true); server.getAddressSettingsRepository().addMatch(address.toString(), qs); // then we create a client as normal locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0); ClientSessionFactory sessionFactory = createSessionFactory(locator); clientSession = sessionFactory.createSession(false, true, true); clientSessionXa = sessionFactory.createSession(true, false, false); clientSession.createQueue(new QueueConfiguration(qName1).setAddress(address)); }
Example 7
Source File: SecurityFailoverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected ClientSession createSession(ClientSessionFactory sf, boolean isXA, boolean autoCommitSends, boolean autoCommitAcks, int ackBatchSize) throws Exception { ClientSession session = sf.createSession("a", "b", isXA, autoCommitSends, autoCommitAcks, sf.getServerLocator().isPreAcknowledge(), ackBatchSize); addClientSession(session); return session; }
Example 8
Source File: FullQualifiedQueueTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMixedQueues() throws Exception { server.createQueue(new QueueConfiguration(multicastQ1).setAddress(mixedAddress)); server.createQueue(new QueueConfiguration(multicastQ2).setAddress(mixedAddress)); server.createQueue(new QueueConfiguration(multicastQ3).setAddress(mixedAddress)); server.createQueue(new QueueConfiguration(anycastQ1).setAddress(mixedAddress).setRoutingType(RoutingType.ANYCAST)); server.createQueue(new QueueConfiguration(anycastQ2).setAddress(mixedAddress).setRoutingType(RoutingType.ANYCAST)); server.createQueue(new QueueConfiguration(anycastQ3).setAddress(mixedAddress).setRoutingType(RoutingType.ANYCAST)); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(); session.start(); //send 3 messages ClientProducer producer = session.createProducer(mixedAddress); final int num = 3; sendMessages(session, producer, num); ClientConsumer consumer1 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, anycastQ1)); ClientConsumer consumer2 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, anycastQ2)); ClientConsumer consumer3 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, anycastQ3)); ClientConsumer consumer4 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, multicastQ1)); ClientConsumer consumer5 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, multicastQ2)); ClientConsumer consumer6 = session.createConsumer(CompositeAddress.toFullyQualified(mixedAddress, multicastQ3)); session.start(); //each anycast consumer receives one, each multicast receives three. ClientMessage m = consumer1.receive(2000); assertNotNull(m); instanceLog.debug("consumer1 : " + m); m.acknowledge(); m = consumer2.receive(2000); assertNotNull(m); instanceLog.debug("consumer2 : " + m); m.acknowledge(); m = consumer3.receive(2000); assertNotNull(m); instanceLog.debug("consumer3 : " + m); m.acknowledge(); for (int i = 0; i < num; i++) { m = consumer4.receive(2000); assertNotNull(m); instanceLog.debug("consumer4 : " + m); m.acknowledge(); m = consumer5.receive(2000); assertNotNull(m); instanceLog.debug("consumer5 : " + m); m.acknowledge(); m = consumer6.receive(2000); assertNotNull(m); instanceLog.debug("consumer6 : " + m); m.acknowledge(); } session.commit(); //queues are empty now for (SimpleString q : new SimpleString[]{anycastQ1, anycastQ2, anycastQ3, multicastQ1, multicastQ2, multicastQ3}) { QueueQueryResult query = server.queueQuery(CompositeAddress.toFullyQualified(mixedAddress, q)); assertTrue(query.isExists()); assertEquals(mixedAddress, query.getAddress()); assertEquals(q, query.getName()); assertEquals(0, query.getMessageCount()); } }
Example 9
Source File: ResourceAdapterTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testStartStopActivationManyTimes() throws Exception { ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(false, false, false); ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test"); session.createQueue(new QueueConfiguration(queue.getSimpleAddress())); session.close(); ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(INVM_CONNECTOR_FACTORY); ra.setUserName("userGlobal"); ra.setPassword("passwordGlobal"); ra.start(new BootstrapContext()); Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection(); conn.close(); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(ra); spec.setUseJNDI(false); spec.setUser("user"); spec.setPassword("password"); spec.setDestinationType("javax.jms.Topic"); spec.setDestination("test"); spec.setMinSession(1); spec.setMaxSession(15); ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec); ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator(); Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources(); for (int i = 0; i < 10; i++) { activation.start(); assertEquals(1, resources.size()); activation.stop(); } ra.stop(); assertEquals(0, resources.size()); locator.close(); }
Example 10
Source File: BridgeReconnectTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testFailoverAndReconnectImmediately() throws Exception { NodeManager nodeManager = new InVMNodeManager(false); server0 = createActiveMQServer(0, server0Params, isNetty(), nodeManager); server2 = createBackupActiveMQServer(2, server2Params, isNetty(), 0, nodeManager); TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc"); TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc"); connectors.put(server2tc.getName(), server2tc); server0.getConfiguration().setConnectorConfigurations(connectors); server1.getConfiguration().setConnectorConfigurations(connectors); reconnectAttempts = 1; BridgeConfiguration bridgeConfiguration = createBridgeConfig(); List<BridgeConfiguration> bridgeConfigs = new ArrayList<>(); bridgeConfigs.add(bridgeConfiguration); server0.getConfiguration().setBridgeConfigurations(bridgeConfigs); QueueConfiguration queueConfig0 = new QueueConfiguration(queueName).setAddress(testAddress); List<QueueConfiguration> queueConfigs0 = new ArrayList<>(); queueConfigs0.add(queueConfig0); server0.getConfiguration().setQueueConfigs(queueConfigs0); QueueConfiguration queueConfig1 = new QueueConfiguration(queueName).setAddress(forwardAddress); List<QueueConfiguration> queueConfigs1 = new ArrayList<>(); queueConfigs1.add(queueConfig1); server1.getConfiguration().setQueueConfigs(queueConfigs1); server2.getConfiguration().setQueueConfigs(queueConfigs1); startServers(); BridgeReconnectTest.log.debug("** failing connection"); // Now we will simulate a failure of the bridge connection between server0 and server1 server0.fail(true); waitForServerStart(server2); locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server2tc)); ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc)); session0 = csf0.createSession(false, true, true); ClientProducer prod0 = session0.createProducer(testAddress); ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc)); session2 = csf2.createSession(false, true, true); ClientConsumer cons2 = session2.createConsumer(queueName); session2.start(); final int numMessages = NUM_MESSAGES; SimpleString propKey = new SimpleString("propkey"); for (int i = 0; i < numMessages; i++) { ClientMessage message = session0.createMessage(true); message.putIntProperty(propKey, i); prod0.send(message); } for (int i = 0; i < numMessages; i++) { ClientMessage r1 = cons2.receive(1500); assertNotNull(r1); assertEquals(i, r1.getObjectProperty(propKey)); } closeServers(); assertNoMoreConnections(); }
Example 11
Source File: InterceptorTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testInterceptUsernameOnQueues() throws Exception { SimpleString ANOTHER_QUEUE = QUEUE.concat("another"); ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager(); securityManager.getConfiguration().addUser("dumb", "dumber"); securityManager.getConfiguration().addUser("an", "other"); server.getRemotingService().addIncomingInterceptor(new InterceptUserOnCreateQueue()); locator.setBlockOnDurableSend(true); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession("dumb", "dumber", false, false, false, false, 0); ClientSession sessionAnotherUser = sf.createSession("an", "other", false, false, false, false, 0); session.createQueue(new QueueConfiguration(QUEUE)); sessionAnotherUser.createQueue(new QueueConfiguration(ANOTHER_QUEUE).setAddress(QUEUE)); ClientProducer prod = session.createProducer(QUEUE); ClientProducer prodAnother = sessionAnotherUser.createProducer(QUEUE); ClientMessage msg = session.createMessage(true); prod.send(msg); session.commit(); prodAnother.send(msg); sessionAnotherUser.commit(); ClientConsumer consumer = session.createConsumer(QUEUE); ClientConsumer consumerAnother = sessionAnotherUser.createConsumer(ANOTHER_QUEUE); session.start(); sessionAnotherUser.start(); msg = consumer.receive(1000); assertNotNull(msg); assertEquals("dumb", msg.getStringProperty("userName")); msg.acknowledge(); assertNull(consumer.receiveImmediate()); msg = consumerAnother.receive(1000); assertNotNull(msg); assertEquals("an", msg.getStringProperty("userName")); msg.acknowledge(); assertNull(consumerAnother.receiveImmediate()); session.close(); sessionAnotherUser.close(); }
Example 12
Source File: PagingReceiveTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private ClientMessage receiveMessage() throws Exception { final ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(null, null, false, true, true, false, 0); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage message = consumer.receive(1000); session.commit(); if (message != null) { message.acknowledge(); } consumer.close(); session.close(); return message; }
Example 13
Source File: FailBackAutoTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
private ClientSession sendAndConsume(final ClientSessionFactory sf, final boolean createQueue) throws Exception { ClientSession session = sf.createSession(false, true, true); if (createQueue) { session.createQueue(new QueueConfiguration(ADDRESS)); } ClientProducer producer = session.createProducer(ADDRESS); final int numMessages = 1000; for (int i = 0; i < numMessages; i++) { ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1); message.putIntProperty(new SimpleString("count"), i); message.getBodyBuffer().writeString("aardvarks"); producer.send(message); } ClientConsumer consumer = session.createConsumer(ADDRESS); session.start(); for (int i = 0; i < numMessages; i++) { ClientMessage message2 = consumer.receive(); assertEquals("aardvarks", message2.getBodyBuffer().readString()); assertEquals(i, message2.getObjectProperty(new SimpleString("count"))); message2.acknowledge(); } ClientMessage message3 = consumer.receiveImmediate(); consumer.close(); assertNull(message3); return session; }
Example 14
Source File: ActiveMQCrashTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testHang() throws Exception { Configuration configuration = createDefaultInVMConfig().setPersistenceEnabled(false); server = addServer(ActiveMQServers.newActiveMQServer(configuration)); server.start(); server.getRemotingService().addIncomingInterceptor(new AckInterceptor(server)); // Force an ack at once - this means the send call will block locator.setConfirmationWindowSize(1); ClientSessionFactory clientSessionFactory = createSessionFactory(locator); ClientSession session = clientSessionFactory.createSession(); session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() { @Override public void sendAcknowledged(final Message message) { ackReceived = true; } }); ClientProducer producer = session.createProducer("fooQueue"); ClientMessage msg = session.createMessage(false); msg.putStringProperty("someKey", "someValue"); producer.send(msg); Thread.sleep(250); Assert.assertFalse(ackReceived); session.close(); }
Example 15
Source File: QueueBrowserTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testConsumerBrowserMessageAckDoesNothing() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(QUEUE).setDurable(false)); ClientProducer producer = session.createProducer(QUEUE); final int numMessages = 100; for (int i = 0; i < numMessages; i++) { ClientMessage message = createTextMessage(session, "m" + i); producer.send(message); } ClientConsumer consumer = session.createConsumer(QUEUE, null, true); for (int i = 0; i < numMessages; i++) { ClientMessage message2 = consumer.receive(1000); message2.acknowledge(); Assert.assertEquals("m" + i, message2.getBodyBuffer().readString()); } // assert that all the messages are there and none have been acked Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()).getDeliveringCount()); Assert.assertEquals(100, getMessageCount(((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()))); session.close(); }
Example 16
Source File: SessionSendAcknowledgementHandlerTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
public void verifySendAcknowledgements(int windowSize) throws Exception { ServerLocator locator = createInVMNonHALocator(); locator.setConfirmationWindowSize(windowSize); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession(null, null, false, true, true, false, 1); session.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(false)); ClientProducer prod = session.createProducer(address); final int numMessages = 1000; LatchAckHandler handler = new LatchAckHandler("session", new CountDownLatch(numMessages)); LatchAckHandler producerHandler = new LatchAckHandler("producer", new CountDownLatch(numMessages)); session.setSendAcknowledgementHandler(handler); for (int i = 0; i < numMessages; i++) { ClientMessage msg = session.createMessage(false); ClientMessage msg2 = session.createMessage(false); prod.send(msg); prod.send(address, msg2, producerHandler); } Assert.assertTrue("session must have acked, " + handler, handler.latch.await(5, TimeUnit.SECONDS)); Assert.assertTrue("producer specific handler must have acked, " + producerHandler, producerHandler.latch.await(5, TimeUnit.SECONDS)); }
Example 17
Source File: RandomReattachTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
protected void doTestJ(final ClientSessionFactory sf) throws Exception { ClientSession sessCreate = sf.createSession(false, true, true); sessCreate.createQueue(new QueueConfiguration(RandomReattachTest.ADDRESS).setDurable(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(); }
Example 18
Source File: InterruptedLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testInterruptLargeMessageSend() throws Exception { ClientSession session = null; LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt(); ActiveMQServer server = createServer(true, isNetty()); server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName()); server.start(); locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false); ClientSessionFactory sf = createSessionFactory(locator); session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(ADDRESS)); ClientProducer producer = session.createProducer(ADDRESS); Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true); clientFile.setExpiration(System.currentTimeMillis()); producer.send(clientFile); Thread.sleep(500); // // for (ServerSession srvSession : server.getSessions()) { // ((ServerSessionImpl) srvSession).clearLargeMessage(); // } server.fail(false); ActiveMQTestBase.forceGC(); server.start(); server.stop(); validateNoFilesOnLargeDir(); }
Example 19
Source File: PingTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testNoFailureWithPinging() throws Exception { ServerLocator locator = createNettyNonHALocator(); locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD); locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession(false, true, true); Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections()); Listener clientListener = new Listener(); session.addFailureListener(clientListener); RemotingConnection serverConn = null; while (serverConn == null) { Set<RemotingConnection> conns = server.getRemotingService().getConnections(); if (!conns.isEmpty()) { serverConn = server.getRemotingService().getConnections().iterator().next(); } else { // It's async so need to wait a while Thread.sleep(10); } } Listener serverListener = new Listener(); serverConn.addFailureListener(serverListener); Thread.sleep(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 10); Assert.assertNull(clientListener.getException()); Assert.assertNull(serverListener.getException()); RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next(); Assert.assertTrue(serverConn == serverConn2); session.close(); csf.close(); locator.close(); }
Example 20
Source File: PagingSyncTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testOrder1() throws Throwable { boolean persistentMessages = true; Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false); ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>()); server.start(); final int messageSize = 1024; final int numberOfMessages = 500; ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(false).setConsumerWindowSize(1024 * 1024); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, false, false); server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST)); server.createQueue(new QueueConfiguration(ADDRESS).setRoutingType(RoutingType.ANYCAST)); ClientProducer producer = session.createProducer(PagingTest.ADDRESS); byte[] body = new byte[messageSize]; ByteBuffer bb = ByteBuffer.wrap(body); for (int j = 1; j <= messageSize; j++) { bb.put(getSamplebyte(j)); } for (int i = 0; i < numberOfMessages; i++) { ClientMessage message = session.createMessage(persistentMessages); ActiveMQBuffer bodyLocal = message.getBodyBuffer(); bodyLocal.writeBytes(body); message.putIntProperty(new SimpleString("id"), i); producer.send(message); } session.commit(); session.close(); }