Refine search
@Override public void initialize(File configurationFile, StatsLogger statsLogger) throws IOException { this.config = readConfig(configurationFile); log.info("ActiveMQ Artemis driver configuration: {}", writer.writeValueAsString(config)); try { ServerLocator serverLocator = ActiveMQClient.createServerLocator(config.brokerAddress); serverLocator.setConfirmationWindowSize(1000); sessionFactory = serverLocator.createSessionFactory(); session = sessionFactory.createSession(); } catch (Exception e) { throw new IOException(e); } }
@Test public void testValidateFactoryGC5() throws Exception { ClientSessionFactory factory = locator.createSessionFactory(); WeakReference<ClientSessionFactory> fref = new WeakReference<>(factory); factory = null; locator.close(); locator = null; ActiveMQTestBase.checkWeakReferences(fref); } }
@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); }
@Test public void testJAASSecurityManagerAuthenticationBadPassword() throws Exception { server.start(); ClientSessionFactory cf = locator.createSessionFactory(); try { cf.createSession("first", "badpassword", false, true, true, false, 0); Assert.fail("should throw exception here"); } catch (Exception e) { // ignore } cf.close(); }
@Test public void testInVMConnectionLimit() throws Exception { ServerLocator locator = addServerLocator(createNonHALocator(false)); ClientSessionFactory clientSessionFactory = locator.createSessionFactory(); try { ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory(); fail("creating a session factory here should fail"); } catch (Exception e) { assertTrue(e instanceof ActiveMQNotConnectedException); } }
public void process(InputStream inputStream, String host, int port, boolean transactional) throws Exception { HashMap<String, Object> connectionParams = new HashMap<>(); connectionParams.put(TransportConstants.HOST_PROP_NAME, host); connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.toString(port)); ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams)); ClientSessionFactory sf = serverLocator.createSessionFactory(); ClientSession session; ClientSession managementSession; if (user != null || password != null) { session = sf.createSession(user, password, false, !transactional, true, false, 0); managementSession = sf.createSession(user, password, false, true, true, false, 0); } else { session = sf.createSession(false, !transactional, true); managementSession = sf.createSession(false, true, true); } localSession = true; process(inputStream, session, managementSession); }
@Test public void testNettyConnectionLimit() throws Exception { ServerLocator locator = createNonHALocator(true).setCallTimeout(3000); ClientSessionFactory clientSessionFactory = locator.createSessionFactory(); ClientSession clientSession = addClientSession(clientSessionFactory.createSession()); try { ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory(); ClientSession extraClientSession = addClientSession(extraClientSessionFactory.createSession()); fail("creating a session here should fail"); } catch (Exception e) { assertTrue(e instanceof ActiveMQConnectionTimedOutException); } } }
@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(); } }
public void process(InputStream inputStream, String host, int port, boolean transactional) throws Exception { HashMap<String, Object> connectionParams = new HashMap<>(); connectionParams.put(TransportConstants.HOST_PROP_NAME, host); connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.toString(port)); ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams)); ClientSessionFactory sf = serverLocator.createSessionFactory(); ClientSession session; ClientSession managementSession; if (user != null || password != null) { session = sf.createSession(user, password, false, !transactional, true, false, 0); managementSession = sf.createSession(user, password, false, true, true, false, 0); } else { session = sf.createSession(false, !transactional, true); managementSession = sf.createSession(false, true, true); } localSession = true; process(inputStream, session, managementSession); }
@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 testMultipleClientSessionFactories() throws Throwable { startServers(0, 1, 2, 3, 4); ClientSessionFactory[] sfs = new ClientSessionFactory[]{locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory()}; Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS)); checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes);
void start() { log.info("Starting {}", this.getClass().getSimpleName()); try { sessionFactory = serverLocator.createSessionFactory(); session = sessionFactory.createSession(); } catch (RuntimeException runtimeEx) { throw runtimeEx; } catch (Exception ex) { throw new ActiveMQClientResourceException(String.format("%s initialisation failure", this.getClass().getSimpleName()), ex); } createClient(); try { session.start(); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("%s startup failure", this.getClass().getSimpleName()), amqEx); } }
@Test public void testSessionLimitForUser() throws Exception { ServerLocator locator = addServerLocator(createNonHALocator(false)); ClientSessionFactory clientSessionFactory = locator.createSessionFactory(); ClientSession clientSession = clientSessionFactory.createSession("myUser", "password", false, true, true, false, 0); try { ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory(); ClientSession extraClientSession = extraClientSessionFactory.createSession("myUser", "password", false, true, true, false, 0); fail("creating a session factory here should fail"); } catch (Exception e) { assertTrue(e instanceof ActiveMQSessionCreationException); } clientSession.close(); clientSession = clientSessionFactory.createSession("myUser", "password", false, true, true, false, 0); try { ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory(); ClientSession extraClientSession = extraClientSessionFactory.createSession("myUser", "password", false, true, true, false, 0); fail("creating a session factory here should fail"); } catch (Exception e) { assertTrue(e instanceof ActiveMQSessionCreationException); } }
@Test public void testCloseSessionFactory() throws Exception { ServerLocator locator = createInVMNonHALocator().setReconnectAttempts(-1).setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000); ClientSessionFactory sf = locator.createSessionFactory(); final CountDownLatch latch = new CountDownLatch(1); sf.addFailoverListener(eventType -> { if (eventType == FailoverEventType.FAILURE_DETECTED) { try { /** * We close client session factory during this period and * expect reconnection stopped without exception which notifies * FAILOVER_FAILED event. See ARTEMIS-1949. */ Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } } else if (eventType == FailoverEventType.FAILOVER_FAILED) { latch.countDown(); } }); server.stop(); Thread.sleep(600); sf.close(); assertTrue(latch.await(1000, TimeUnit.MILLISECONDS)); } }
/** * In a cluster of replicated live/backup pairs if a backup crashes and then its live crashes the cluster will * retain the topology information of the live such that when the live server restarts it will check the * cluster to see if its nodeID is present (which it will be) and then it will activate as a backup rather than * a live. To prevent this situation an additional check is necessary to see if the server with the matching * nodeID is actually active or not which is done by attempting to make a connection to it. * * @param transportConfiguration * @return */ private boolean isActive(TransportConfiguration transportConfiguration) { boolean result = false; try (ServerLocator serverLocator = ActiveMQClient.createServerLocator(false, transportConfiguration); ClientSessionFactory clientSessionFactory = serverLocator.createSessionFactory(); ClientSession clientSession = clientSessionFactory.createSession(user, password, false, false, false, false, 0)) { result = true; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("isActive check failed", e); } } return result; }
/** * 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); }
@Test public void testConnectionTimeoutConfig() throws Exception { final int timeout = 23456; TransportConfiguration transport = new TransportConfiguration(NETTY_CONNECTOR_FACTORY); transport.getParams().put(TransportConstants.NETTY_CONNECT_TIMEOUT, timeout); ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(transport); ClientSessionFactoryImpl factory = (ClientSessionFactoryImpl) locator.createSessionFactory(); NettyConnector connector = (NettyConnector) factory.getConnector(); Bootstrap bootstrap = connector.getBootStrap(); assertEquals(timeout, bootstrap.register().channel().config().getConnectTimeoutMillis()); factory.close(); locator.close(); } }
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName())); ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(false, true, true); session.start(); ClientRequestor requestor = new ClientRequestor(session, "jms.queue.hornetq.management"); ClientMessage message = session.createMessage(false); ManagementHelper.putAttribute(message, ResourceNames.CORE_SERVER, "queueNames"); ClientMessage reply = requestor.request(message); Object queueNames = ManagementHelper.getResult(reply);
@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(); }
@Test(timeout = 60000) public void testFailBothRestartLive() throws Exception { ServerLocator locator = getServerLocator(); locator.setReconnectAttempts(-1).setRetryInterval(10); sf = (ClientSessionFactoryInternal)locator.createSessionFactory(); ClientSession session = createSession(sf, true, true); session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true); ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS); sendMessagesSomeDurable(session, producer); crash(session); ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS); session.start(); receiveDurableMessages(consumer); backupServer.getServer().fail(true); liveServer.start(); consumer.close(); producer.close(); producer = session.createProducer(FailoverTestBase.ADDRESS); sendMessagesSomeDurable(session, producer); sf.close(); Assert.assertEquals(0, sf.numSessions()); Assert.assertEquals(0, sf.numConnections()); }