ARTEMIS-2681 timestamp not set on notif msgs

This commit is contained in:
Justin Bertram 2020-03-25 10:22:21 -05:00 committed by Clebert Suconic
parent 2cfd25f3cc
commit 59e07c9780
5 changed files with 85 additions and 2 deletions

View File

@ -1687,7 +1687,10 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
message.setAddress(queueName);
message.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(type.toString()));
message.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
long timestamp = System.currentTimeMillis();
message.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, timestamp);
message.setTimestamp(timestamp);
return message;
}

View File

@ -691,7 +691,9 @@ public class ManagementServiceImpl implements ManagementService {
notificationMessage.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(notification.getType().toString()));
notificationMessage.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
long timestamp = System.currentTimeMillis();
notificationMessage.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, timestamp);
notificationMessage.setTimestamp(timestamp);
postOffice.route(notificationMessage, false);
}

View File

@ -79,6 +79,7 @@ public class NotificationTest extends ActiveMQTestBase {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
session.createQueue(address, queue, durable);
//the first message received will be for the address creation
@ -86,6 +87,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(BINDING_ADDED.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertEquals(queue.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
Assert.assertEquals(address.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertTrue(notifications[1].getTimestamp() > start);
Assert.assertTrue((long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[1].getTimestamp(), (long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
session.deleteQueue(queue);
}
@ -103,12 +107,16 @@ public class NotificationTest extends ActiveMQTestBase {
"'");
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
session.createQueue(address, queue, durable);
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
Assert.assertEquals(BINDING_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
session.deleteQueue(queue);
}
@ -142,6 +150,7 @@ public class NotificationTest extends ActiveMQTestBase {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
session.deleteQueue(queue);
//There will be 2 notifications, first is for binding removal, second is for address removal
@ -149,6 +158,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(BINDING_REMOVED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@Test
@ -166,6 +178,7 @@ public class NotificationTest extends ActiveMQTestBase {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
ClientConsumer consumer = mySession.createConsumer(queue);
SimpleString consumerName = SimpleString.toSimpleString(((ClientSessionInternal) mySession).getName());
@ -179,6 +192,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(SimpleString.toSimpleString("invm:0"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS));
Assert.assertEquals(consumerName, notifications[0].getSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME));
Assert.assertEquals(SimpleString.toSimpleString("unavailable"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_CERT_SUBJECT_DN));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
consumer.close();
session.deleteQueue(queue);
@ -201,6 +217,7 @@ public class NotificationTest extends ActiveMQTestBase {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
consumer.close();
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
@ -211,6 +228,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_USER));
Assert.assertEquals(SimpleString.toSimpleString("invm:0"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS));
Assert.assertEquals(sessionName, notifications[0].getSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
session.deleteQueue(queue);
}
@ -221,12 +241,16 @@ public class NotificationTest extends ActiveMQTestBase {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
session.createAddress(address, RoutingType.ANYCAST, true);
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
Assert.assertEquals(ADDRESS_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertEquals(RoutingType.ANYCAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE));
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@ -236,18 +260,23 @@ public class NotificationTest extends ActiveMQTestBase {
session.createAddress(address, RoutingType.ANYCAST, true);
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
server.getPostOffice().removeAddressInfo(address);
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
Assert.assertEquals(ADDRESS_REMOVED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertEquals(RoutingType.ANYCAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE));
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@Test
public void testConnectionCreatedAndDestroyed() throws Exception {
NotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
mySession.start();
@ -261,8 +290,13 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME));
Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_SESSION_NAME));
Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[1].getObjectProperty(ManagementHelper.HDR_USER));
Assert.assertTrue(notifications[1].getTimestamp() > start);
Assert.assertTrue((long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[1].getTimestamp(), (long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
NotificationTest.flush(notifConsumer);
start = System.currentTimeMillis();
mySession.close();
sf.close();
@ -272,10 +306,17 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME));
Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_SESSION_NAME));
Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[0].getObjectProperty(ManagementHelper.HDR_USER));
System.out.println(notifications[0].getTimestamp());
System.out.println(start);
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((Long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(CONNECTION_DESTROYED.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME));
Assert.assertEquals(connectionId, notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME).toString());
Assert.assertTrue(notifications[1].getTimestamp() > start);
Assert.assertTrue((long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[1].getTimestamp(), (long) notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@Test
@ -299,6 +340,8 @@ public class NotificationTest extends ActiveMQTestBase {
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
producer.send(msg);
long start = System.currentTimeMillis();
consumer.receive(1000);
ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
@ -308,6 +351,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(address, notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS));
Assert.assertEquals(queue, notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME));
Assert.assertEquals(RoutingType.MULTICAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
consumer.close();
session.deleteQueue(queue);
@ -334,6 +380,8 @@ public class NotificationTest extends ActiveMQTestBase {
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
msg.setExpiration(1);
long start = System.currentTimeMillis();
producer.send(msg);
Thread.sleep(500);
consumer.receive(500);
@ -344,6 +392,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(address, notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS));
Assert.assertEquals(queue, notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME));
Assert.assertEquals(RoutingType.MULTICAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
consumer.close();
session.deleteQueue(queue);
@ -368,6 +419,8 @@ public class NotificationTest extends ActiveMQTestBase {
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
msg.setExpiration(1);
long start = System.currentTimeMillis();
producer.send(msg);
Thread.sleep(500);
@ -377,6 +430,9 @@ public class NotificationTest extends ActiveMQTestBase {
Assert.assertEquals(address, notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS));
Assert.assertEquals(queue, notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME));
Assert.assertEquals(RoutingType.MULTICAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
session.deleteQueue(queue);
}

View File

@ -85,6 +85,7 @@ public class SSLSecurityNotificationTest extends ActiveMQTestBase {
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
long start = System.currentTimeMillis();
try {
sf.createSession();
Assert.fail("authentication must fail and a notification of security violation must be sent");
@ -96,6 +97,9 @@ public class SSLSecurityNotificationTest extends ActiveMQTestBase {
Assert.assertEquals(null, notifications[0].getObjectProperty(ManagementHelper.HDR_USER));
Assert.assertEquals("CN=Bad Client, OU=Artemis, O=ActiveMQ, L=AMQ, ST=AMQ, C=AMQ", notifications[0].getObjectProperty(ManagementHelper.HDR_CERT_SUBJECT_DN).toString());
Assert.assertTrue(notifications[0].getObjectProperty(ManagementHelper.HDR_REMOTE_ADDRESS).toString().startsWith("/127.0.0.1"));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@Test
@ -123,6 +127,8 @@ public class SSLSecurityNotificationTest extends ActiveMQTestBase {
guestSession.createQueue(address, RoutingType.ANYCAST, queue, true);
SSLSecurityNotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
guestSession.createConsumer(queue);
ClientMessage[] notifications = SecurityNotificationTest.consumeMessages(1, notifConsumer);
@ -131,6 +137,9 @@ public class SSLSecurityNotificationTest extends ActiveMQTestBase {
Assert.assertEquals("first", notifications[0].getObjectProperty(ManagementHelper.HDR_VALIDATED_USER).toString());
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertEquals("CN=ActiveMQ Artemis Client, OU=Artemis, O=ActiveMQ, L=AMQ, ST=AMQ, C=AMQ", notifications[0].getObjectProperty(ManagementHelper.HDR_CERT_SUBJECT_DN).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
guestSession.close();
}

View File

@ -74,6 +74,7 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
long start = System.currentTimeMillis();
try {
sf.createSession(unknownUser, RandomUtil.randomString(), false, true, true, false, 1);
Assert.fail("authentication must fail and a notification of security violation must be sent");
@ -85,6 +86,9 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
Assert.assertEquals(unknownUser, notifications[0].getObjectProperty(ManagementHelper.HDR_USER).toString());
Assert.assertEquals("unavailable", notifications[0].getObjectProperty(ManagementHelper.HDR_CERT_SUBJECT_DN).toString());
Assert.assertEquals("invm:0", notifications[0].getObjectProperty(ManagementHelper.HDR_REMOTE_ADDRESS).toString());
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
}
@Test
@ -106,6 +110,7 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession guestSession = sf.createSession("guest", "guest", false, true, true, false, 1);
long start = System.currentTimeMillis();
try {
guestSession.createQueue(address, queue, true);
Assert.fail("session creation must fail and a notification of security violation must be sent");
@ -125,6 +130,9 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
Assert.assertEquals("guest", notifications[i].getObjectProperty(ManagementHelper.HDR_USER).toString());
Assert.assertEquals(address.toString(), notifications[i].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.toString(), notifications[i].getObjectProperty(ManagementHelper.HDR_CHECK_TYPE).toString());
Assert.assertTrue(notifications[i].getTimestamp() >= start);
Assert.assertTrue((long) notifications[i].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[i].getTimestamp(), (long) notifications[i].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
guestSession.close();
}
@ -147,6 +155,8 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
guestSession.createQueue(address, RoutingType.ANYCAST, queue, true);
SecurityNotificationTest.flush(notifConsumer);
long start = System.currentTimeMillis();
guestSession.createConsumer(queue);
ClientMessage[] notifications = SecurityNotificationTest.consumeMessages(1, notifConsumer);
@ -155,6 +165,9 @@ public class SecurityNotificationTest extends ActiveMQTestBase {
Assert.assertEquals("guest", notifications[0].getObjectProperty(ManagementHelper.HDR_VALIDATED_USER).toString());
Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
Assert.assertEquals(SimpleString.toSimpleString("unavailable"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_CERT_SUBJECT_DN));
Assert.assertTrue(notifications[0].getTimestamp() >= start);
Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start);
Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP));
guestSession.close();
}