mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-02-24 11:30:47 +00:00
This closes #2592
This commit is contained in:
commit
65796c9a6b
@ -18,9 +18,9 @@ package org.apache.activemq.artemis.core.management.impl.view;
|
|||||||
|
|
||||||
import javax.json.JsonObjectBuilder;
|
import javax.json.JsonObjectBuilder;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate;
|
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate;
|
||||||
@ -51,7 +51,7 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
|
|||||||
public JsonObjectBuilder toJson(RemotingConnection connection) {
|
public JsonObjectBuilder toJson(RemotingConnection connection) {
|
||||||
|
|
||||||
List<ServerSession> sessions = server.getSessions(connection.getID().toString());
|
List<ServerSession> sessions = server.getSessions(connection.getID().toString());
|
||||||
Set<String> users = new HashSet<>();
|
Set<String> users = new TreeSet<>();
|
||||||
String jmsSessionClientID = null;
|
String jmsSessionClientID = null;
|
||||||
for (ServerSession session : sessions) {
|
for (ServerSession session : sessions) {
|
||||||
String username = session.getUsername() == null ? "" : session.getUsername();
|
String username = session.getUsername() == null ? "" : session.getUsername();
|
||||||
@ -83,12 +83,12 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
|
|||||||
case "remoteAddress":
|
case "remoteAddress":
|
||||||
return connection.getRemoteAddress();
|
return connection.getRemoteAddress();
|
||||||
case "users":
|
case "users":
|
||||||
Set<String> users = new HashSet<>();
|
Set<String> users = new TreeSet<>();
|
||||||
for (ServerSession session : sessions) {
|
for (ServerSession session : sessions) {
|
||||||
String username = session.getUsername() == null ? "" : session.getUsername();
|
String username = session.getUsername() == null ? "" : session.getUsername();
|
||||||
users.add(username);
|
users.add(username);
|
||||||
}
|
}
|
||||||
return users;
|
return StringUtil.joinStringList(users, ",");
|
||||||
case "creationTime":
|
case "creationTime":
|
||||||
return new Date(connection.getCreationTime());
|
return new Date(connection.getCreationTime());
|
||||||
case "implementation":
|
case "implementation":
|
||||||
|
@ -2455,20 +2455,21 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
csf3 = (ClientSessionFactoryImpl) createSessionFactory(locator);
|
csf3 = (ClientSessionFactoryImpl) createSessionFactory(locator);
|
||||||
|
|
||||||
ClientSession session1_c1 = csf.createSession();
|
ClientSession session1_c1 = csf.createSession("guest", "guest", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session2_c1 = csf.createSession();
|
ClientSession session2_c1 = csf.createSession("guest", "guest", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
|
|
||||||
ClientSession session1_c2 = csf2.createSession();
|
ClientSession session1_c2 = csf2.createSession("myUser", "myPass", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session2_c2 = csf2.createSession();
|
ClientSession session2_c2 = csf2.createSession("myUser", "myPass", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session3_c2 = csf2.createSession();
|
ClientSession session3_c2 = csf2.createSession("myUser", "myPass", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session4_c2 = csf2.createSession();
|
ClientSession session4_c2 = csf2.createSession("myUser", "myPass", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
|
|
||||||
ClientSession session1_c4 = csf3.createSession();
|
ClientSession session1_c4 = csf3.createSession("myUser", "myPass", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session2_c4 = csf3.createSession();
|
ClientSession session2_c4 = csf3.createSession("guest", "guest", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
ClientSession session3_c4 = csf3.createSession();
|
ClientSession session3_c4 = csf3.createSession("guest", "guest", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
|
||||||
|
|
||||||
String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1");
|
String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1");
|
||||||
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
||||||
|
System.err.println(connectionsAsJsonString);
|
||||||
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
|
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
|
||||||
JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
|
JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
|
||||||
|
|
||||||
@ -2478,7 +2479,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||||||
//check all fields
|
//check all fields
|
||||||
Assert.assertNotEquals("connectionID", "", jsonConnection.getString("connectionID"));
|
Assert.assertNotEquals("connectionID", "", jsonConnection.getString("connectionID"));
|
||||||
Assert.assertNotEquals("remoteAddress", "", jsonConnection.getString("remoteAddress"));
|
Assert.assertNotEquals("remoteAddress", "", jsonConnection.getString("remoteAddress"));
|
||||||
Assert.assertEquals("users", "", jsonConnection.getString("users"));
|
Assert.assertEquals("users", "guest", jsonConnection.getString("users"));
|
||||||
Assert.assertNotEquals("creationTime", "", jsonConnection.getString("creationTime"));
|
Assert.assertNotEquals("creationTime", "", jsonConnection.getString("creationTime"));
|
||||||
Assert.assertNotEquals("implementation", "", jsonConnection.getString("implementation"));
|
Assert.assertNotEquals("implementation", "", jsonConnection.getString("implementation"));
|
||||||
Assert.assertNotEquals("protocol", "", jsonConnection.getString("protocol"));
|
Assert.assertNotEquals("protocol", "", jsonConnection.getString("protocol"));
|
||||||
@ -2491,6 +2492,28 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||||||
Assert.assertEquals("connection2 default Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID"));
|
Assert.assertEquals("connection2 default Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID"));
|
||||||
Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(2).getString("connectionID"));
|
Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(2).getString("connectionID"));
|
||||||
|
|
||||||
|
//check order by users asc
|
||||||
|
filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "users", "asc");
|
||||||
|
connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
||||||
|
connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
|
||||||
|
array = (JsonArray) connectionsAsJsonObject.get("data");
|
||||||
|
|
||||||
|
Assert.assertEquals("number of connections returned from query", 3, array.size());
|
||||||
|
Assert.assertEquals("connection1 users Order", "guest", array.getJsonObject(0).getString("users"));
|
||||||
|
Assert.assertEquals("connection3 users Order", "guest,myUser", array.getJsonObject(1).getString("users"));
|
||||||
|
Assert.assertEquals("connection2 users Order", "myUser", array.getJsonObject(2).getString("users"));
|
||||||
|
|
||||||
|
//check order by users desc
|
||||||
|
filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "users", "desc");
|
||||||
|
connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
||||||
|
connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
|
||||||
|
array = (JsonArray) connectionsAsJsonObject.get("data");
|
||||||
|
|
||||||
|
Assert.assertEquals("number of connections returned from query", 3, array.size());
|
||||||
|
Assert.assertEquals("connection2 users Order", "myUser", array.getJsonObject(0).getString("users"));
|
||||||
|
Assert.assertEquals("connection3 users Order", "guest,myUser", array.getJsonObject(1).getString("users"));
|
||||||
|
Assert.assertEquals("connection1 users Order", "guest", array.getJsonObject(2).getString("users"));
|
||||||
|
|
||||||
//check order by session count desc
|
//check order by session count desc
|
||||||
filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "sessionCount", "desc");
|
filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "sessionCount", "desc");
|
||||||
connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user