Skip to content

Commit d055f97

Browse files
committed
ARTEMIS-5854 consumer mngmnt API not working
This commit does the following: - Allows `lastDeliveredTime` and `lastAcknowledgedTime` to be filtered via the management API. - Adds unit tests for all such attributes to verify they are filterable. - Looks up the correct value on the server when filtering on `messagesDelivered`. - Breaks up `ViewTest` into corresponding classes so all attributes can be unit tested eventually.
1 parent e83b0fe commit d055f97

9 files changed

Lines changed: 610 additions & 138 deletions

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,11 @@ public Object getField(ServerConsumer consumer, String fieldName) {
121121
}
122122

123123
public static String checkConsumerStatus(ServerConsumer consumer, ActiveMQServer server) {
124-
if (server.getRemotingService().getConnection((consumer).getConnectionID()) == null) {
124+
if (server.getRemotingService() != null && server.getRemotingService().getConnection((consumer).getConnectionID()) == null) {
125125
return CONSUMER_STATUS_ORPHANED;
126126
} else {
127127
return CONSUMER_STATUS_OK;
128128
}
129-
130129
}
131130

132131
@Override

artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/predicate/ConsumerFilterPredicate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ public boolean test(ServerConsumer consumer) {
5454
matches(server.getSessionByID(consumer.getSessionID()).getRemotingConnection().getTransportConnection().getRemoteAddress());
5555
case MESSAGES_IN_TRANSIT -> matches(consumer.getMessagesInTransit());
5656
case MESSAGES_IN_TRANSIT_SIZE -> matches(consumer.getMessagesInTransitSize());
57-
case MESSAGES_DELIVERED -> matches(consumer.getDeliveringMessages());
57+
case MESSAGES_DELIVERED -> matches(consumer.getMessagesDelivered());
5858
case MESSAGES_DELIVERED_SIZE -> matches(consumer.getMessagesDeliveredSize());
5959
case MESSAGES_ACKNOWLEDGED -> matches(consumer.getMessagesAcknowledged());
6060
case MESSAGES_ACKNOWLEDGED_AWAITING_COMMIT -> matches(consumer.getMessagesAcknowledgedAwaitingCommit());
61+
case LAST_ACKNOWLEDGED_TIME -> matches(consumer.getLastAcknowledgedTime());
62+
case LAST_DELIVERED_TIME -> matches(consumer.getLastDeliveredTime());
6163
default -> true;
6264
};
6365
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.artemis.core.management.impl.view;
18+
19+
import org.apache.activemq.artemis.core.server.ActiveMQServer;
20+
import org.junit.jupiter.api.Test;
21+
import org.mockito.Mockito;
22+
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
25+
26+
public class AddressViewTest extends ViewTest {
27+
28+
@Test
29+
public void testDefaultViewNullOptions() {
30+
AddressView addressView = new AddressView(Mockito.mock(ActiveMQServer.class));
31+
// sanity check to ensure this doesn't just blow up
32+
addressView.setOptions(null);
33+
}
34+
35+
@Test
36+
public void testDefaultViewEmptyOptions() {
37+
AddressView addressView = new AddressView(Mockito.mock(ActiveMQServer.class));
38+
// sanity check to ensure this doesn't just blow up
39+
addressView.setOptions("");
40+
}
41+
42+
@Test
43+
public void testViewLegacySort() {
44+
AddressView view = new AddressView(Mockito.mock(ActiveMQServer.class));
45+
assertNotEquals("name", view.getDefaultOrderColumn());
46+
view.setOptions(createLegacyJsonFilter("name", "EQUALS", "123", "name", "asc"));
47+
assertEquals("name", view.getSortField());
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.artemis.core.management.impl.view;
18+
19+
import org.apache.activemq.artemis.core.server.ActiveMQServer;
20+
import org.junit.jupiter.api.Test;
21+
import org.mockito.Mockito;
22+
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
25+
26+
public class ConnectionViewTest extends ViewTest {
27+
28+
@Test
29+
public void testDefaultViewNullOptions() {
30+
ConnectionView connectionView = new ConnectionView(Mockito.mock(ActiveMQServer.class));
31+
// sanity check to ensure this doesn't just blow up
32+
connectionView.setOptions(null);
33+
}
34+
35+
@Test
36+
public void testDefaultViewEmptyOptions() {
37+
ConnectionView connectionView = new ConnectionView(Mockito.mock(ActiveMQServer.class));
38+
// sanity check to ensure this doesn't just blow up
39+
connectionView.setOptions("");
40+
}
41+
42+
@Test
43+
public void testViewLegacySort() {
44+
ConnectionView view = new ConnectionView(Mockito.mock(ActiveMQServer.class));
45+
assertNotEquals("protocol", view.getDefaultOrderColumn());
46+
view.setOptions(createLegacyJsonFilter("protocol", "EQUALS", "123", "protocol", "asc"));
47+
assertEquals("protocol", view.getSortField());
48+
}
49+
}

0 commit comments

Comments
 (0)