Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientSessionFactory#close()

The following examples show how to use org.apache.activemq.artemis.api.core.client.ClientSessionFactory#close() . 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: CoreClientOverTwoWayOpenSSLServerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoWaySSLVerifyClientTrustAllTrueByURI() throws Exception {
   NettyAcceptor acceptor = (NettyAcceptor) server.getRemotingService().getAcceptor("nettySSL");
   acceptor.getConfiguration().put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true);
   server.getRemotingService().stop(false);
   server.getRemotingService().start();
   server.getRemotingService().startAcceptors();

   //Set trust all so this should work even with no trust store set
   StringBuilder uri = new StringBuilder("tcp://" + tc.getParams().get(TransportConstants.HOST_PROP_NAME).toString()
         + ":" + tc.getParams().get(TransportConstants.PORT_PROP_NAME).toString());

   uri.append("?").append(TransportConstants.SSL_ENABLED_PROP_NAME).append("=true");
   uri.append("&").append(TransportConstants.TRUST_ALL_PROP_NAME).append("=true");
   uri.append("&").append(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME).append("=").append(storeType);
   uri.append("&").append(TransportConstants.KEYSTORE_PATH_PROP_NAME).append("=").append(CLIENT_SIDE_KEYSTORE);
   uri.append("&").append(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME).append("=").append(PASSWORD);

   server.getRemotingService().addIncomingInterceptor(new MyInterceptor());

   ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocator(uri.toString()));
   ClientSessionFactory sf = createSessionFactory(locator);
   sf.close();
}
 
Example 2
Source File: SessionFactoryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: CoreClientOverTwoWayOpenSSLServerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoWaySSLVerifyClientTrustAllTrue() throws Exception {
   NettyAcceptor acceptor = (NettyAcceptor) server.getRemotingService().getAcceptor("nettySSL");
   acceptor.getConfiguration().put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true);
   server.getRemotingService().stop(false);
   server.getRemotingService().start();
   server.getRemotingService().startAcceptors();

   //Set trust all so this should work even with no trust store set
   tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
   tc.getParams().put(TransportConstants.TRUST_ALL_PROP_NAME, true);
   tc.getParams().put(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME, storeType);
   tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, CLIENT_SIDE_KEYSTORE);
   tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, PASSWORD);

   server.getRemotingService().addIncomingInterceptor(new MyInterceptor());

   ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
   ClientSessionFactory sf = createSessionFactory(locator);
   sf.close();
}
 
Example 4
Source File: AckBatchSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private int getMessageEncodeSize(final SimpleString address) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientMessage message = session.createMessage(false);
   // we need to set the destination so we can calculate the encodesize correctly
   message.setAddress(address);
   int encodeSize = message.getEncodeSize();
   session.close();
   cf.close();
   return encodeSize;
}
 
Example 5
Source File: PagingCounterTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCounter() throws Exception {
   ClientSessionFactory sf = createSessionFactory(sl);
   ClientSession session = sf.createSession();

   try {
      server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
      Queue queue = server.createQueue(new QueueConfiguration(new SimpleString("A1")).setRoutingType(RoutingType.ANYCAST));

      PageSubscriptionCounter counter = locateCounter(queue);

      StorageManager storage = server.getStorageManager();

      Transaction tx = new TransactionImpl(server.getStorageManager());

      counter.increment(tx, 1, 1000);

      assertEquals(0, counter.getValue());
      assertEquals(0, counter.getPersistentSize());

      tx.commit();

      storage.waitOnOperations();

      assertEquals(1, counter.getValue());
      assertEquals(1000, counter.getPersistentSize());
   } finally {
      sf.close();
      session.close();
   }
}
 
Example 6
Source File: ConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testStressConnection() throws Exception {

   for (int i = 0; i < 10; i++) {
      ServerLocator locatorSendx = createFactory(isNetty()).setReconnectAttempts(15);
      ClientSessionFactory factoryx = locatorSendx.createSessionFactory();
      factoryx.close();
      locatorSendx.close();
   }

}
 
Example 7
Source File: LDAPSecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJAASSecurityManagerAuthentication() throws Exception {
   server.start();
   ClientSessionFactory cf = locator.createSessionFactory();

   try {
      ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
      session.close();
   } catch (ActiveMQException e) {
      e.printStackTrace();
      Assert.fail("should not throw exception");
   }

   cf.close();
}
 
Example 8
Source File: ConsumerWindowSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private int getMessageEncodeSize(final SimpleString address) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientMessage message = session.createMessage(false);
   // we need to set the destination so we can calculate the encodesize correctly
   message.setAddress(address);
   int encodeSize = message.getEncodeSize();
   session.close();
   cf.close();
   return encodeSize;
}
 
Example 9
Source File: CommitRollbackTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncConsumerRollback() throws Exception {
   ActiveMQServer server = createServer(false);
   server.start();
   ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession sendSession = cf.createSession(false, true, true);
   final ClientSession session = cf.createSession(false, true, false);
   sendSession.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setDurable(false));
   ClientProducer cp = sendSession.createProducer(addressA);
   ClientConsumer cc = session.createConsumer(queueA);
   int numMessages = 100;
   for (int i = 0; i < numMessages; i++) {
      cp.send(sendSession.createMessage(false));
   }
   CountDownLatch latch = new CountDownLatch(numMessages);
   session.start();
   cc.setMessageHandler(new ackHandler(session, latch));
   Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
   Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
   Assert.assertEquals(numMessages, q.getDeliveringCount());
   Assert.assertEquals(numMessages, getMessageCount(q));
   session.stop();
   session.rollback();
   Assert.assertEquals(0, q.getDeliveringCount());
   Assert.assertEquals(numMessages, getMessageCount(q));
   latch = new CountDownLatch(numMessages);
   cc.setMessageHandler(new ackHandler(session, latch));
   session.start();
   Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
   sendSession.close();
   session.close();
   cf.close();

}
 
Example 10
Source File: NIOMultiThreadCompactorStressTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * @param xid
 * @throws ActiveMQException
 */
private void addEmptyTransaction(final Xid xid) throws Exception {
   ClientSessionFactory sf = createSessionFactory(locator);
   ClientSession session = sf.createSession(true, false, false);
   session.start(xid, XAResource.TMNOFLAGS);
   session.end(xid, XAResource.TMSUCCESS);
   session.prepare(xid);
   session.close();
   sf.close();
}
 
Example 11
Source File: ServerLocatorConnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleConnectorSingleServer() throws Exception {
   ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())));
   ClientSessionFactory csf = createSessionFactory(locator);
   csf.close();
   locator.close();
}
 
Example 12
Source File: FederationConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public synchronized void stop() {
   started = false;
   ClientSessionFactory clientSessionFactory = this.clientSessionFactory;
   if (clientSessionFactory != null) {
      clientSessionFactory.cleanup();
      clientSessionFactory.close();
      this.clientSessionFactory = null;
   }
}
 
Example 13
Source File: CoreClientOverOneWaySSLKerb5Test.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testOneWaySSLWithGoodClientCipherSuite() throws Exception {

   // hard coded match, default_keytab_name in minikdc-krb5.conf template
   File userKeyTab = new File("target/test.krb5.keytab");
   kdc.createPrincipal(userKeyTab, CLIENT_PRINCIPAL, SERVICE_PRINCIPAL);

   createCustomSslServer();

   tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
   tc.getParams().put(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME, getSuitableCipherSuite());
   tc.getParams().put(TransportConstants.SNIHOST_PROP_NAME, SNI_HOST); // static service name rather than dynamic machine name
   tc.getParams().put(TransportConstants.SSL_KRB5_CONFIG_PROP_NAME, "core-tls-krb5-client");
   final ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));

   ClientSessionFactory sf = null;
   try {
      sf = createSessionFactory(locator);
      ClientSession session = sf.createSession(false, true, true);
      session.createQueue(new QueueConfiguration(CoreClientOverOneWaySSLKerb5Test.QUEUE).setRoutingType(RoutingType.ANYCAST));
      ClientProducer producer = session.createProducer(CoreClientOverOneWaySSLKerb5Test.QUEUE);

      final String text = RandomUtil.randomString();
      ClientMessage message = createTextMessage(session, text);
      producer.send(message);

      ClientConsumer consumer = session.createConsumer(CoreClientOverOneWaySSLKerb5Test.QUEUE);
      session.start();

      ClientMessage m = consumer.receive(1000);
      Assert.assertNotNull(m);
      Assert.assertEquals(text, m.getReadOnlyBodyBuffer().readString());
      System.err.println("m:" + m + ", user:" + m.getValidatedUserID());
      Assert.assertNotNull("got validated user", m.getValidatedUserID());
      Assert.assertTrue("krb id in validated user", m.getValidatedUserID().contains(CLIENT_PRINCIPAL));

   } finally {
      if (sf != null) {
         sf.close();
      }
      locator.close();
   }

   // validate only ssl creds work, try and fake the principal w/o ssl
   final ServerLocator inVmLocator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(inVMTc));
   ClientSessionFactory inVmSf = null;
   try {
      inVmSf = createSessionFactory(inVmLocator);
      inVmSf.createSession(userPrincipal, "", false, false, false, false, 10);

      fail("supposed to throw exception");
   } catch (ActiveMQSecurityException e) {
      // expected
   } finally {
      if (inVmSf != null) {
         inVmSf.close();
      }
      inVmLocator.close();
   }
}
 
Example 14
Source File: SendStressTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void doTestStressSend(final boolean netty) throws Exception {
   ActiveMQServer server = createServer(false, netty);
   server.start();
   ServerLocator locator = createNonHALocator(netty);
   ClientSessionFactory sf = createSessionFactory(locator);

   ClientSession session = null;

   final int batchSize = 2000;

   final int numberOfMessages = 100000;

   try {
      server.start();

      session = sf.createSession(false, false);

      session.createQueue(new QueueConfiguration("queue").setAddress("address"));

      ClientProducer producer = session.createProducer("address");

      ClientMessage message = session.createMessage(false);

      message.getBodyBuffer().writeBytes(new byte[1024]);

      for (int i = 0; i < numberOfMessages; i++) {
         producer.send(message);
         if (i % batchSize == 0) {
            System.out.println("Sent " + i);
            session.commit();
         }
      }

      session.commit();

      session.close();

      session = sf.createSession(false, false);

      ClientConsumer consumer = session.createConsumer("queue");

      session.start();

      for (int i = 0; i < numberOfMessages; i++) {
         ClientMessage msg = consumer.receive(5000);
         Assert.assertNotNull(msg);
         msg.acknowledge();

         if (i % batchSize == 0) {
            System.out.println("Consumed " + i);
            session.commit();
         }
      }

      session.commit();
   } finally {
      if (session != null) {
         try {
            sf.close();
            session.close();
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      locator.close();
      server.stop();
   }

}
 
Example 15
Source File: SimpleClient.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {
   try {
      if (args.length != 1) {
         throw new Exception("require 1 argument: connector factory class name");
      }

      String connectorFactoryClassName = args[0];

      String queueName = RandomUtil.randomString();
      String messageText = RandomUtil.randomString();

      ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(connectorFactoryClassName)).setReconnectAttempts(1).setInitialConnectAttempts(1);
      try {
         ClientSessionFactory sf = locator.createSessionFactory();
         ClientSession session = sf.createSession(false, true, true);

         session.createQueue(new QueueConfiguration(queueName).setDurable(false));
         ClientProducer producer = session.createProducer(queueName);
         ClientConsumer consumer = session.createConsumer(queueName);

         ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
         message.getBodyBuffer().writeString(messageText);
         producer.send(message);

         session.start();

         ClientMessage receivedMsg = consumer.receive(5000);
         if (receivedMsg == null) {
            throw new Exception("did not receive the message");
         }

         String text = receivedMsg.getBodyBuffer().readString();
         if (text == null || !text.equals(messageText)) {
            throw new Exception("received " + text + ", was expecting " + messageText);
         }

         // clean all resources to exit cleanly
         consumer.close();
         session.deleteQueue(queueName);
         session.close();
         sf.close();
         System.out.println("OK");
      } finally {
         locator.close();
      }
   } catch (Throwable t) {
      t.printStackTrace(System.out);

      String allStack = t.getMessage() + "|";
      StackTraceElement[] stackTrace = t.getStackTrace();
      for (StackTraceElement stackTraceElement : stackTrace) {
         allStack += stackTraceElement.toString() + "|";
      }
      // System.out.println(t.getClass().getName());
      // System.out.println(t.getMessage());
      System.out.println(allStack);
      System.exit(1);
   }
}
 
Example 16
Source File: LargeMessageOnShutdownTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
@BMRules(
   rules = {
      @BMRule(
         name = "BlockOnFinalLargeMessagePacket",
         targetClass = "org.apache.activemq.artemis.core.server.impl.ServerSessionImpl",
         targetMethod = "doSend(Transaction,Message,SimpleString,boolean,boolean)",
         targetLocation = "EXIT",
         condition = "!flagged(\"testLargeMessageOnShutdown\")",
         action =
            "org.apache.activemq.artemis.tests.extras.byteman.LargeMessageOnShutdownTest.stopServer();" +
            "waitFor(\"testLargeMessageOnShutdown\", 5000);" +
            "flag(\"testLargeMessageOnShutdown\")"
      ),
      @BMRule(
         name = "ReleaseBlockOnSessionCleanup",
         targetClass = "org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler",
         targetMethod = "clearLargeMessage()",
         targetLocation = "EXIT",
         action = "signalWake(\"testLargeMessageOnShutdown\")"
      )
   }
)
public void testLargeMessageOnShutdown() throws Exception {

   byte[] payload = new byte[ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE * 2];

   // Send Large Message
   ClientSessionFactory csf1 = createSessionFactory(createNettyNonHALocator());
   try {
      ClientSession session1 = csf1.createSession();
      ClientProducer producer1 = session1.createProducer(queueName);
      ClientMessage message = session1.createMessage(true);

      message.setBodyInputStream(new ByteArrayInputStream(payload));
      producer1.send(message);
   } catch (Exception e) {
      // Expected due to shutdown.
   } finally {
      csf1.close();
   }

   waitForStoppedServer();
   startServer();

   // Consume Large Message
   ClientSessionFactory csf2 = createSessionFactory(createNettyNonHALocator());
   try {
      ClientSession session2 = csf2.createSession();
      session2.start();
      ClientConsumer consumer2 = session2.createConsumer(queueName);
      ClientMessage rmessage = consumer2.receive(10000);

      assertEquals(payload.length, rmessage.getBodyBuffer().readableBytes());
      assertEqualsBuffers(payload.length, ActiveMQBuffers.wrappedBuffer(payload), rmessage.getBodyBuffer());
   } finally {
      csf2.close();
   }
}
 
Example 17
Source File: SessionCloseOnGCTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testValidateFactoryGC2() throws Exception {
   locator.setUseGlobalPools(false);

   ClientSessionFactory factory = locator.createSessionFactory();

   ClientSession s1 = factory.createSession();
   ClientSession s2 = factory.createSession();

   s1.close();
   s2.close();

   WeakReference<ClientSession> wrs1 = new WeakReference<>(s1);
   WeakReference<ClientSession> wrs2 = new WeakReference<>(s2);

   s1 = null;
   s2 = null;

   locator.close();

   locator = null;
   ActiveMQTestBase.checkWeakReferences(wrs1, wrs2);

   WeakReference<ClientSessionFactory> fref = new WeakReference<>(factory);

   factory.close();

   factory = null;

   ActiveMQTestBase.checkWeakReferences(fref, wrs1, wrs2);
}
 
Example 18
Source File: TopologyClusterTestBase.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testReceiveNotificationsWhenOtherNodesAreStartedAndStopped() throws Throwable {
   startServers(0);

   ServerLocator locator = createHAServerLocator();

   locator.getTopology().setOwner("testReceive");

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);
   final CountDownLatch downLatch = new CountDownLatch(4);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, downLatch));

   ClientSessionFactory sf = createSessionFactory(locator);

   startServers(1, 4, 3, 2);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 4, 3, 2}, nodeIDs, nodes);

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   stopServers(2, 3, 1, 4);

   Assert.assertTrue("Was not notified that all servers are DOWN", downLatch.await(10, SECONDS));
   checkContains(new int[]{0}, nodeIDs, nodes);

   sf.close();

   locator.close();

   stopServers(0);

}
 
Example 19
Source File: LargeMessageCompressTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testLargeMessageCompressionRestartAndCheckSize() throws Exception {
   final int messageSize = 1024 * 1024;

   ActiveMQServer server = createServer(true, isNetty());

   server.start();

   ClientSessionFactory sf = createSessionFactory(locator);

   ClientSession session = addClientSession(sf.createSession(false, false, false));

   session.createQueue(new QueueConfiguration(ADDRESS));

   ClientProducer producer = session.createProducer(ADDRESS);

   byte[] msgs = new byte[1024 * 1024];
   for (int i = 0; i < msgs.length; i++) {
      msgs[i] = RandomUtil.randomByte();
   }

   Message clientFile = createLargeClientMessage(session, msgs, true);

   producer.send(clientFile);

   session.commit();

   session.close();

   sf.close();

   locator.close();

   server.stop();

   server = createServer(true, isNetty());

   server.start();

   locator = createFactory(isNetty());

   sf = createSessionFactory(locator);

   session = sf.createSession();

   session.start();

   ClientConsumer consumer = session.createConsumer(ADDRESS);
   ClientMessage msg1 = consumer.receive(1000);
   Assert.assertNotNull(msg1);

   assertEquals(messageSize, msg1.getBodySize());

   String testDir = getTestDir();
   File testFile = new File(testDir, "async_large_message");
   FileOutputStream output = new FileOutputStream(testFile);

   msg1.saveToOutputStream(output);

   msg1.acknowledge();

   session.commit();

   consumer.close();

   session.close();

   //verify
   FileInputStream input = new FileInputStream(testFile);
   for (int i = 0; i < messageSize; i++) {
      byte b = (byte) input.read();
      assertEquals("position = " + i, msgs[i], b);
   }
   input.close();

   testFile.delete();
   validateNoFilesOnLargeDir();
}
 
Example 20
Source File: CoreClientTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
private void testCoreClient(final boolean netty, ServerLocator serverLocator) throws Exception {
   final SimpleString QUEUE = new SimpleString("CoreClientTestQueue");

   ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultConfig(netty), false));

   server.start();

   ServerLocator locator = serverLocator == null ? createNonHALocator(netty) : serverLocator;

   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 = 1000;

   for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);

      message.putStringProperty("foo", "bar");

      // One way around the setting destination problem is as follows -
      // Remove destination as an attribute from client producer.
      // The destination always has to be set explicitly before sending a message

      message.setAddress(QUEUE);

      message.getBodyBuffer().writeString("testINVMCoreClient");

      producer.send(message);
   }

   ClientConsumer consumer = session.createConsumer(QUEUE);

   session.start();

   for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = consumer.receive();

      ActiveMQBuffer buffer = message2.getBodyBuffer();

      Assert.assertEquals("testINVMCoreClient", buffer.readString());

      message2.acknowledge();
   }

   sf.close();
}