public static void crashAndWaitForFailure(ActiveMQServer server, ServerLocator locator) throws Exception { ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); try { crashAndWaitForFailure(server, session); } finally { try { session.close(); sf.close(); } catch (Exception ignored) { } } }
@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(); }
/** * 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); }
ClientSession session = null; if (user == null) { session = sf.createSession(false, true, true); } else { session = sf.createSession(user, password, false, true, true, false, 1); sf.close();
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; }
ClientSession session = factory.createSession(); factory.close();
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; } }
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; }
checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes); ClientSession session = sf.createSession(); checkContains(new int[]{}, nodeIDs, nodes); sf.close();
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); }
ClientSessionFactory cf = locator.createSessionFactory(); String queue = "queue1"; ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0); ClientSession session2 = cf.createSession("second", "secret", false, true, true, false, 0); session.createQueue(SimpleString.toSimpleString(queue), SimpleString.toSimpleString(queue)); ClientConsumer consumer = session.createConsumer(queue); cf.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; } }
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; }
@Test public void testSendServerMessageWithValidatedUser() throws Exception { ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin"); ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false)); server.getConfiguration().setPopulateValidatedUser(true); Role role = new Role("programmers", true, true, true, true, true, true, true, true, true, true); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch("#", roles); server.start(); ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); try { ClientSession session = sf.createSession("first", "secret", false, true, true, false, 0); ClientMessage clientMessage = session.createMessage(false); clientMessage.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE)); session.createQueue("A", RoutingType.ANYCAST, "A"); ClientProducer prod = session.createProducer("A"); prod.send(clientMessage); session.commit(); session.start(); ClientConsumer cons = session.createConsumer("A"); ClientMessage msg = cons.receive(5000); assertEquals("first", msg.getValidatedUserID()); } finally { sf.close(); locator.close(); server.stop(); } }
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 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(); }
ClientSessionFactory cf = locator.createSessionFactory(); String name = "queue1"; ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0); ClientSession session2 = cf.createSession("second", "secret", false, true, true, false, 0); session.createQueue(SimpleString.toSimpleString(name), SimpleString.toSimpleString(name)); ClientProducer producer = session.createProducer(); cf.close();