@Test public void testValidateFactoryGC3() throws Exception { 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 = null; ActiveMQTestBase.checkWeakReferences(fref, wrs1, wrs2); }
@Test public void testValidateFactoryGC4() throws Exception { ClientSessionFactory factory = locator.createSessionFactory(); ClientSession s1 = factory.createSession(); ClientSession s2 = factory.createSession(); 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 = null; ActiveMQTestBase.checkWeakReferences(fref, wrs1, wrs2); }
@Override public void run() { ServerLocator locator = null; ClientSession session = null; try { locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); session = sf.createSession(false, true, true); final SimpleString QUEUE = new SimpleString(queueName); session.createQueue(QUEUE, QUEUE, null, true); queuesCreated.incrementAndGet(); } catch (ActiveMQQueueExistsException qne) { failedAttempts.incrementAndGet(); } catch (Exception e) { e.printStackTrace(); } finally { if (locator != null) { locator.close(); } if (session != null) { try { session.close(); } catch (ActiveMQException e) { e.printStackTrace(); } } } } }
ClientSessionFactory factory = createSessionFactory(locator); session = (ClientSessionInternal) factory.createSession(); locator.close(); } finally { try {
void stop() { stopClient(); if (session != null) { try { session.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientSession - ignoring", amqEx); } finally { session = null; } } if (sessionFactory != null) { sessionFactory.close(); sessionFactory = null; } if (serverLocator != null) { serverLocator.close(); serverLocator = null; } }
/** * Make sure Sessions are not leaking after closed.. * Also... we want to make sure the SessionFactory will close itself when there are not references into it */ @Test public void testValidateFactoryGC1() throws Exception { 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); }
session.createQueue(myAddress.toString(), RoutingType.MULTICAST, "myQueue2", true); locator.close(); server.stop(); locator = createInVMNonHALocator(); factory = locator.createSessionFactory(); session = factory.createSession(false, false, true); ClientSession managementSession = factory.createSession(false, true, true);
void stop() { stopClient(); if (session != null) { try { session.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientSession - ignoring", amqEx); } finally { session = null; } } if (sessionFactory != null) { sessionFactory.close(); sessionFactory = null; } if (serverLocator != null) { serverLocator.close(); serverLocator = null; } }
@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); }
private void restartServer() throws Exception { server.stop(); server = null; server = createServer(true, configuration); server.getAddressSettingsRepository().addMatch(address.toString(), qs); // start the server server.start(); server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings().setDefaultLastValueQueue(true)); // then we create a client as normal locator.close(); locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0); ClientSessionFactory sessionFactory = createSessionFactory(locator); clientSession = sessionFactory.createSession(false, true, true); clientSessionXa = sessionFactory.createSession(true, false, false); } }
void stop() { if (producer != null) { try { producer.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientProducer - ignoring", amqEx); } finally { producer = null; } } if (session != null) { try { session.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientSession - ignoring", amqEx); } finally { session = null; } } if (sessionFactory != null) { sessionFactory.close(); sessionFactory = null; } if (serverLocator != null) { serverLocator.close(); serverLocator = null; } }
@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(); } }
ServerLocator locator = SpawnedServerSupport.createLocator(PORT2).setInitialConnectAttempts(100).setRetryInterval(100); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(); cons.close(); session.deleteQueue("new-queue"); locator.close();
void stop() { if (producer != null) { try { producer.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientProducer - ignoring", amqEx); } finally { producer = null; } } if (session != null) { try { session.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientSession - ignoring", amqEx); } finally { session = null; } } if (sessionFactory != null) { sessionFactory.close(); sessionFactory = null; } if (serverLocator != null) { serverLocator.close(); serverLocator = null; } }
@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(); }
ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession clientSession = csf.createSession(true, false, false); clientSession.createQueue(recQueue, recQueue, null, true); clientSession.createQueue(sendQueue, sendQueue, null, true); ClientProducer clientProducer = clientSession.createProducer(recQueue); clientProducer.send(m1); locator.close(); ClientSession receiveClientSession = receiveCsf.createSession(true, false, false); ClientConsumer consumer = receiveClientSession.createConsumer(recQueue); ClientSession sendClientSession = sendCsf.createSession(true, false, false); ClientProducer producer = sendClientSession.createProducer(sendQueue); sendLocator.close(); receiveLocator.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 testNoCheckFailoverMessage() throws Exception { final int pingPeriod = 1000; ActiveMQServer server = createServer(false, true); server.start(); ClientSessionInternal session = null; try { ServerLocator locator = createFactory(true).setClientFailureCheckPeriod(pingPeriod).setRetryInterval(500).setRetryIntervalMultiplier(1d).setReconnectAttempts(-1).setConfirmationWindowSize(1024 * 1024); locator.setProtocolManagerFactory(new HornetQClientProtocolManagerFactory()); ClientSessionFactory factory = createSessionFactory(locator); session = (ClientSessionInternal) factory.createSession(); server.stop(); Thread.sleep((pingPeriod * 2)); List<String> incomings = server.getConfiguration().getIncomingInterceptorClassNames(); incomings.add(UnsupportedPacketInterceptor.class.getName()); server.start(); //issue a query to make sure session is reconnected. ClientSession.QueueQuery query = session.queueQuery(new SimpleString("anyvalue")); assertFalse(query.isExists()); locator.close(); UnsupportedPacketInterceptor.checkReceivedTypes(); } finally { try { session.close(); } catch (Throwable e) { } server.stop(); } }