[ 
https://issues.apache.org/jira/browse/ARTEMIS-2919?focusedWorklogId=518380&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-518380
 ]

ASF GitHub Bot logged work on ARTEMIS-2919:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Dec/20 11:12
            Start Date: 01/Dec/20 11:12
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on a change in pull request #3279:
URL: https://github.com/apache/activemq-artemis/pull/3279#discussion_r533327562



##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
##########
@@ -709,6 +709,24 @@ public void testSubscribeWithAutoAck() throws Exception {
 
    }
 
+   @Test
+   public void testIngressTimestamp() throws Exception {
+      server.getAddressSettingsRepository().addMatch("#", new 
AddressSettings().setEnableIngressTimestamp(true));
+      conn.connect(defUser, defPass);
+
+      subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
+
+      sendJmsMessage(getName());
+
+      ClientStompFrame frame = conn.receiveFrame(10000);
+      Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
+      Assert.assertEquals(getQueuePrefix() + getQueueName(), 
frame.getHeader(Stomp.Headers.Send.DESTINATION));
+      
Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.INGRESS_TIMESTAMP));

Review comment:
       Same as other protocols, validating the value is as actually set as 
expected would be good.

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSendReceiveTest.java
##########
@@ -1260,5 +1262,60 @@ public void testReceiveRejecting() throws Exception {
       connection.close();
    }
 
+   @Test(timeout = 60000)
+   public void testIngressTimestampSendCore() throws Exception {
+      internalTestIngressTimestamp(Protocol.CORE);
+   }
+
+   @Test(timeout = 60000)
+   public void testIngressTimestampSendAMQP() throws Exception {
+      internalTestIngressTimestamp(Protocol.AMQP);
+   }
+
+   @Test(timeout = 60000)
+   public void testIngressTimestampSendOpenWire() throws Exception {
+      internalTestIngressTimestamp(Protocol.OPENWIRE);
+   }
+
+   private void internalTestIngressTimestamp(Protocol protocol) throws 
Exception {
+      server.getAddressSettingsRepository().addMatch(getQueueName(), new 
AddressSettings().setEnableIngressTimestamp(true));
+      long beforeSend = System.currentTimeMillis();
+      if (protocol == Protocol.CORE) {
+         sendMessagesCore(getQueueName(), 1, true);
+      } else if (protocol == Protocol.OPENWIRE) {
+         sendMessagesOpenWire(getQueueName(), 1, true);
+      } else {
+         sendMessages(getQueueName(), 1, true);
+      }
+      long afterSend = System.currentTimeMillis();
+      AmqpClient client = createAmqpClient();
+      AmqpConnection connection = addConnection(client.connect());
+      AmqpSession session = connection.createSession();
+
+      AmqpReceiver receiver = session.createReceiver(getQueueName());
+
+      Queue queueView = getProxyToQueue(getQueueName());
+      assertEquals(1, queueView.getMessageCount());
+
+      receiver.flow(1);
+      AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
+      assertNotNull(receive);
+      instanceLog.info(receive);
+      Object ingressTimestamp = 
receive.getMessageAnnotation(AMQPMessageSupport.INGRESS_TIMESTAMP.toString());
+      assertNotNull(ingressTimestamp);
+      assertTrue(ingressTimestamp instanceof Long);
+      long ingressTs = (Long) ingressTimestamp;
+      assertTrue(beforeSend <= ingressTs && afterSend >= ingressTs);

Review comment:
       Getting a more useful error should it ever fail would be probably be 
good. E.g a Hamcrest based assertion might be something like:
   
   ```
   Matcher<Long> inRange = 
both(greaterThanOrEqualTo(beforeSend)).and(lessThanOrEqualTo(afterSend));
   MatcherAssert.assertThat("Ingress time should be set in expected range", 
ingressTs, inRange);
   ```

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IngressTimestampTest.java
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.client;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.artemis.api.core.Message;
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class IngressTimestampTest extends ActiveMQTestBase {
+   private ActiveMQServer server;
+
+   private final SimpleString QUEUE = new SimpleString("ConsumerTestQueue");
+
+   @Before
+   @Override
+   public void setUp() throws Exception {
+      super.setUp();
+      server = createServer(true, true);
+      server.start();
+      server.getAddressSettingsRepository().addMatch("#", new 
AddressSettings().setEnableIngressTimestamp(true));
+      server.createQueue(new 
QueueConfiguration(QUEUE).setRoutingType(RoutingType.ANYCAST));
+   }
+
+   @Test
+   public void testSendCoreReceiveCore() throws Throwable {
+      internalSend(Protocol.CORE, Protocol.CORE);
+   }
+
+   @Test
+   public void testSendAMQPReceiveCore() throws Throwable {
+      internalSend(Protocol.AMQP, Protocol.CORE);
+   }
+
+   @Test
+   public void testSendOpenWireReceiveCore() throws Throwable {
+      internalSend(Protocol.OPENWIRE, Protocol.CORE);
+   }
+
+   @Test
+   public void testSendCoreReceiveOpenwire() throws Throwable {
+      internalSend(Protocol.CORE, Protocol.OPENWIRE);
+   }
+
+   @Test
+   public void testSendAMQPReceiveOpenWire() throws Throwable {
+      internalSend(Protocol.AMQP, Protocol.OPENWIRE);
+   }
+
+   @Test
+   public void testSendOpenWireReceiveOpenWire() throws Throwable {
+      internalSend(Protocol.OPENWIRE, Protocol.OPENWIRE);
+   }
+
+   /**
+    *  we don't test AMQP here because there's no way to access the message 
annotations from the Qpid JMS client
+    *
+   @Test
+   public void testSendCoreReceiveAMQP() throws Throwable {
+      internalSend(Protocol.CORE, Protocol.AMQP);
+   }
+
+   @Test
+   public void testSendAMQPReceiveAMQP() throws Throwable {
+      internalSend(Protocol.AMQP, Protocol.AMQP);
+   }
+
+   @Test
+   public void testSendOpenWireReceiveAMQP() throws Throwable {
+      internalSend(Protocol.OPENWIRE, Protocol.AMQP);
+   }
+   */
+
+   private void internalSend(Protocol protocolSender, Protocol 
protocolConsumer) throws Throwable {
+      ConnectionFactory factorySend = createFactory(protocolSender);
+      ConnectionFactory factoryConsume = protocolConsumer == protocolSender ? 
factorySend : createFactory(protocolConsumer);
+
+      try (Connection connection = factorySend.createConnection()) {
+         try (Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE)) {
+            javax.jms.Queue queue = session.createQueue(QUEUE.toString());
+            try (MessageProducer producer = session.createProducer(queue)) {
+               producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+               TextMessage msg = session.createTextMessage("hello");
+               msg.setIntProperty("mycount", 0);
+               producer.send(msg);
+            }
+         }
+
+      }
+      try (Connection connection = factoryConsume.createConnection()) {
+         connection.start();
+         try (Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE)) {
+            javax.jms.Queue queue = session.createQueue(QUEUE.toString());
+            try (MessageConsumer consumer = session.createConsumer(queue)) {
+               TextMessage message = (TextMessage) consumer.receive(1000);
+               Assert.assertNotNull(message);
+               Assert.assertEquals(0, message.getIntProperty("mycount"));
+               Assert.assertEquals("hello", message.getText());
+               
assertNotNull(message.getObjectProperty(Message.HDR_INGRESS_TIMESTAMP.toString()));

Review comment:
       Validating the value is as actually expected for the different 
protocols, i.e is set within the send period and not just non-null, would be 
good. 0 is non-null after all.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 518380)
    Time Spent: 2h 50m  (was: 2h 40m)

> Support timestamping incoming messages
> --------------------------------------
>
>                 Key: ARTEMIS-2919
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2919
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to