This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 11b0de9  ARTEMIS-2285 Sorting by user column in connections view not 
working
     new 65796c9  This closes #2592
11b0de9 is described below

commit 11b0de96b9fd3aace7690e54e7c311c44f6e5470
Author: sebthom <sebt...@users.noreply.github.com>
AuthorDate: Mon Apr 15 16:42:03 2019 +0200

    ARTEMIS-2285 Sorting by user column in connections view not working
---
 .../core/management/impl/view/ConnectionView.java  |  8 ++--
 .../management/ActiveMQServerControlTest.java      | 43 +++++++++++++++++-----
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
index 9f2d0bf..4ed0b49 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java
@@ -18,9 +18,9 @@ package org.apache.activemq.artemis.core.management.impl.view;
 
 import javax.json.JsonObjectBuilder;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.activemq.artemis.api.core.client.ClientSession;
 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) {
 
       List<ServerSession> sessions = 
server.getSessions(connection.getID().toString());
-      Set<String> users = new HashSet<>();
+      Set<String> users = new TreeSet<>();
       String jmsSessionClientID = null;
       for (ServerSession session : sessions) {
          String username = session.getUsername() == null ? "" : 
session.getUsername();
@@ -83,12 +83,12 @@ public class ConnectionView extends 
ActiveMQAbstractView<RemotingConnection> {
          case "remoteAddress":
             return connection.getRemoteAddress();
          case "users":
-            Set<String> users = new HashSet<>();
+            Set<String> users = new TreeSet<>();
             for (ServerSession session : sessions) {
                String username = session.getUsername() == null ? "" : 
session.getUsername();
                users.add(username);
             }
-            return users;
+            return StringUtil.joinStringList(users, ",");
          case "creationTime":
             return new Date(connection.getCreationTime());
          case "implementation":
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
index e2e8607..9d6310a 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java
@@ -2455,20 +2455,21 @@ public class ActiveMQServerControlTest extends 
ManagementTestBase {
          Thread.sleep(500);
          csf3 = (ClientSessionFactoryImpl) createSessionFactory(locator);
 
-         ClientSession session1_c1 = csf.createSession();
-         ClientSession session2_c1 = csf.createSession();
+         ClientSession session1_c1 = csf.createSession("guest", "guest", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session2_c1 = csf.createSession("guest", "guest", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
 
-         ClientSession session1_c2 = csf2.createSession();
-         ClientSession session2_c2 = csf2.createSession();
-         ClientSession session3_c2 = csf2.createSession();
-         ClientSession session4_c2 = csf2.createSession();
+         ClientSession session1_c2 = csf2.createSession("myUser", "myPass", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session2_c2 = csf2.createSession("myUser", "myPass", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session3_c2 = csf2.createSession("myUser", "myPass", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session4_c2 = csf2.createSession("myUser", "myPass", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
 
-         ClientSession session1_c4 = csf3.createSession();
-         ClientSession session2_c4 = csf3.createSession();
-         ClientSession session3_c4 = csf3.createSession();
+         ClientSession session1_c4 = csf3.createSession("myUser", "myPass", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session2_c4 = csf3.createSession("guest", "guest", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
+         ClientSession session3_c4 = csf3.createSession("guest", "guest", 
false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
 
          String filterString = createJsonFilter("SESSION_COUNT", 
"GREATER_THAN", "1");
          String connectionsAsJsonString = 
serverControl.listConnections(filterString, 1, 50);
+         System.err.println(connectionsAsJsonString);
          JsonObject connectionsAsJsonObject = 
JsonUtil.readJsonObject(connectionsAsJsonString);
          JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
 
@@ -2478,7 +2479,7 @@ public class ActiveMQServerControlTest extends 
ManagementTestBase {
          //check all fields
          Assert.assertNotEquals("connectionID", "", 
jsonConnection.getString("connectionID"));
          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("implementation", "", 
jsonConnection.getString("implementation"));
          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("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
          filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", 
"sessionCount", "desc");
          connectionsAsJsonString = serverControl.listConnections(filterString, 
1, 50);

Reply via email to