use of org.apache.activemq.artemis.core.client.impl.ClientSessionImpl in project activemq-artemis by apache.
the class JmsProducerTest method multipleSendsUsingSetters.
@Test
public void multipleSendsUsingSetters() throws Exception {
server.createQueue(SimpleString.toSimpleString("q1"), RoutingType.ANYCAST, SimpleString.toSimpleString("q1"), null, true, false);
Queue q1 = context.createQueue("q1");
context.createProducer().setProperty("prop1", 1).setProperty("prop2", 2).send(q1, "Text1");
context.createProducer().setProperty("prop1", 3).setProperty("prop2", 4).send(q1, "Text2");
for (int i = 0; i < 100; i++) {
context.createProducer().send(q1, "Text" + i);
}
ActiveMQSession sessionUsed = (ActiveMQSession) (((ActiveMQJMSContext) context).getUsedSession());
ClientSessionImpl coreSession = (ClientSessionImpl) sessionUsed.getCoreSession();
// JMSConsumer is supposed to cache the producer, each call to createProducer is supposed to always return the same producer
assertEquals(1, coreSession.cloneProducers().size());
JMSConsumer consumer = context.createConsumer(q1);
TextMessage text = (TextMessage) consumer.receive(5000);
assertNotNull(text);
assertEquals("Text1", text.getText());
assertEquals(1, text.getIntProperty("prop1"));
assertEquals(2, text.getIntProperty("prop2"));
text = (TextMessage) consumer.receive(5000);
assertNotNull(text);
assertEquals("Text2", text.getText());
assertEquals(3, text.getIntProperty("prop1"));
assertEquals(4, text.getIntProperty("prop2"));
for (int i = 0; i < 100; i++) {
assertEquals("Text" + i, consumer.receiveBody(String.class, 1000));
}
consumer.close();
context.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionImpl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCloseJMSclient.
@Test
public void testCloseJMSclient() throws Exception {
ActiveMQServerControl serverControl = createManagementControl();
ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
Connection conn = cf.createConnection();
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Topic topic = ActiveMQJMSClient.createTopic("ConsumerTestTopic");
MessageConsumer JMSclient = session.createConsumer(topic, "test1");
long clientID = -1;
String sessionID = ((ClientSessionImpl) (((ActiveMQSession) session).getCoreSession())).getName();
Set<ServerSession> sessions = server.getSessions();
for (ServerSession sess : sessions) {
if (sess.getName().equals(sessionID.toString())) {
Set<ServerConsumer> serverConsumers = sess.getServerConsumers();
for (ServerConsumer serverConsumer : serverConsumers) {
clientID = serverConsumer.sequentialID();
}
}
}
Assert.assertFalse(((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
serverControl.closeConsumerWithID(sessionID, Long.toString(clientID));
Wait.waitFor(() -> ((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
Assert.assertTrue(((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionImpl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method lookupSession.
private JsonObject lookupSession(JsonArray jsonArray, ClientSession session) throws Exception {
String name = ((ClientSessionImpl) session).getName();
for (int i = 0; i < jsonArray.size(); i++) {
JsonObject obj = jsonArray.getJsonObject(i);
String sessionID = obj.getString("sessionID");
Assert.assertNotNull(sessionID);
if (sessionID.equals(name)) {
return obj;
}
}
Assert.fail("Sesison not found for session id " + name);
// not going to happen, fail will throw an exception but it won't compile without this
return null;
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionImpl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testListSessions.
@Test
public void testListSessions() throws Exception {
SimpleString queueName1 = new SimpleString("my_queue_one");
SimpleString addressName1 = new SimpleString("my_address_one");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
// create some consumers
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSessionImpl session1 = (ClientSessionImpl) csf.createSession();
Thread.sleep(500);
ClientSessionImpl session2 = (ClientSessionImpl) csf.createSession();
Thread.sleep(500);
ClientSessionImpl session3 = (ClientSessionImpl) csf.createSession();
ClientConsumer consumer1_s1 = session1.createConsumer(queueName1);
ClientConsumer consumer2_s1 = session1.createConsumer(queueName1);
ClientConsumer consumer1_s2 = session2.createConsumer(queueName1);
ClientConsumer consumer2_s2 = session2.createConsumer(queueName1);
ClientConsumer consumer3_s2 = session2.createConsumer(queueName1);
ClientConsumer consumer4_s2 = session2.createConsumer(queueName1);
ClientConsumer consumer1_s3 = session3.createConsumer(queueName1);
ClientConsumer consumer2_s3 = session3.createConsumer(queueName1);
ClientConsumer consumer3_s3 = session3.createConsumer(queueName1);
String filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "1");
String sessionsAsJsonString = serverControl.listSessions(filterString, 1, 50);
JsonObject sessionsAsJsonObject = JsonUtil.readJsonObject(sessionsAsJsonString);
JsonArray array = (JsonArray) sessionsAsJsonObject.get("data");
Assert.assertEquals("number of sessions returned from query", 3, array.size());
JsonObject jsonSession = array.getJsonObject(0);
// check all fields
Assert.assertNotEquals("id", "", jsonSession.getString("id"));
Assert.assertEquals("user", "", jsonSession.getString("user"));
Assert.assertNotEquals("creationTime", "", jsonSession.getString("creationTime"));
Assert.assertEquals("consumerCount", 2, jsonSession.getInt("consumerCount"));
Assert.assertTrue("producerCount", 0 <= jsonSession.getInt("producerCount"));
Assert.assertNotEquals("connectionID", "", jsonSession.getString("connectionID"));
// check default order
Assert.assertEquals("session1 location", session1.getName(), array.getJsonObject(0).getString("id"));
Assert.assertEquals("session2 location", session2.getName(), array.getJsonObject(1).getString("id"));
Assert.assertEquals("session3 location", session3.getName(), array.getJsonObject(2).getString("id"));
// bring back session ordered by consumer count
filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "1", "consumerCount", "asc");
sessionsAsJsonString = serverControl.listSessions(filterString, 1, 50);
sessionsAsJsonObject = JsonUtil.readJsonObject(sessionsAsJsonString);
array = (JsonArray) sessionsAsJsonObject.get("data");
Assert.assertTrue("number of sessions returned from query", 3 == array.size());
Assert.assertEquals("session1 ordered by consumer", session1.getName(), array.getJsonObject(0).getString("id"));
Assert.assertEquals("session3 ordered by consumer", session3.getName(), array.getJsonObject(1).getString("id"));
Assert.assertEquals("session2 ordered by consumer", session2.getName(), array.getJsonObject(2).getString("id"));
// bring back session ordered by consumer Count
filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "1", "consumerCount", "asc");
sessionsAsJsonString = serverControl.listSessions(filterString, 1, 50);
sessionsAsJsonObject = JsonUtil.readJsonObject(sessionsAsJsonString);
array = (JsonArray) sessionsAsJsonObject.get("data");
Assert.assertTrue("number of sessions returned from query", 3 == array.size());
Assert.assertEquals("session1 ordered by consumer", session1.getName(), array.getJsonObject(0).getString("id"));
Assert.assertEquals("session3 ordered by consumer", session3.getName(), array.getJsonObject(1).getString("id"));
Assert.assertEquals("session2 ordered by consumer", session2.getName(), array.getJsonObject(2).getString("id"));
// bring back session ordered by creation time (desc)
filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "1", "creationTime", "desc");
sessionsAsJsonString = serverControl.listSessions(filterString, 1, 50);
sessionsAsJsonObject = JsonUtil.readJsonObject(sessionsAsJsonString);
array = (JsonArray) sessionsAsJsonObject.get("data");
Assert.assertTrue("number of sessions returned from query", 3 == array.size());
Assert.assertEquals("session3 ordered by creationTime", session3.getName(), array.getJsonObject(0).getString("id"));
Assert.assertEquals("session2 ordered by creationTime", session2.getName(), array.getJsonObject(1).getString("id"));
Assert.assertEquals("session1 ordered by creationTime", session1.getName(), array.getJsonObject(2).getString("id"));
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionImpl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testListConsumersOrder.
@Test
public void testListConsumersOrder() throws Exception {
SimpleString queueName1 = new SimpleString("my_queue_one");
SimpleString addressName1 = new SimpleString("my_address_one");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSessionImpl session1 = (ClientSessionImpl) csf.createSession();
ClientSessionImpl session2 = (ClientSessionImpl) csf.createSession();
ClientSessionImpl session3 = (ClientSessionImpl) csf.createSession();
// sleep - test compares creationTimes
ClientConsumer consumer_s1 = session1.createConsumer(queueName1);
Thread.sleep(500);
ClientConsumer consumer_s2 = session2.createConsumer(queueName1);
Thread.sleep(500);
ClientConsumer consumer_s3 = session3.createConsumer(queueName1);
// test default Order
String filterString = createJsonFilter("queue", "EQUALS", queueName1.toString());
String consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
JsonObject consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
JsonArray array = (JsonArray) consumersAsJsonObject.get("data");
Assert.assertEquals("number of consumers returned from query", 3, array.size());
Assert.assertEquals("Consumer1 default order", session1.getName(), array.getJsonObject(0).getString("session"));
Assert.assertEquals("Consumer2 default order", session2.getName(), array.getJsonObject(1).getString("session"));
Assert.assertEquals("Consumer3 default order", session3.getName(), array.getJsonObject(2).getString("session"));
// test ordered by creationTime
filterString = createJsonFilter("queue", "EQUALS", queueName1.toString(), "creationTime", "desc");
consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
array = (JsonArray) consumersAsJsonObject.get("data");
Assert.assertEquals("number of consumers returned from query", 3, array.size());
Assert.assertEquals("Consumer3 creation time", session3.getName(), array.getJsonObject(0).getString("session"));
Assert.assertEquals("Consumer2 creation time", session2.getName(), array.getJsonObject(1).getString("session"));
Assert.assertEquals("Consumer1 creation time", session1.getName(), array.getJsonObject(2).getString("session"));
}
}
Aggregations