You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2018/02/01 10:57:26 UTC

qpid-broker-j git commit: QPID-8067: [Broker-J] Fix an evaluation of start time for queue default arrival time filter

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 6adeac949 -> 5e1ae2dd6


QPID-8067: [Broker-J] Fix an evaluation of start time for queue default arrival time filter


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/5e1ae2dd
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/5e1ae2dd
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/5e1ae2dd

Branch: refs/heads/master
Commit: 5e1ae2dd6e059cf464cb7e7fa3373d656102bd37
Parents: 6adeac9
Author: Alex Rudyy <or...@apache.org>
Authored: Thu Feb 1 10:56:00 2018 +0000
Committer: Alex Rudyy <or...@apache.org>
Committed: Thu Feb 1 10:56:00 2018 +0000

----------------------------------------------------------------------
 .../server/filter/ArrivalTimeFilterFactory.java |  6 +--
 .../filter/ArrivalTimeFilterFactoryTest.java    | 50 ++++++++++++++++++++
 2 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/5e1ae2dd/broker-core/src/main/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactory.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactory.java b/broker-core/src/main/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactory.java
index 382a3ac..fc965db 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactory.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactory.java
@@ -36,10 +36,8 @@ public final class ArrivalTimeFilterFactory implements MessageFilterFactory
         {
             throw new IllegalArgumentException("Cannot create a filter from these arguments: " + arguments);
         }
-        String arg = arguments.get(0);
-        long startingFrom= Long.parseLong(arg);
-
-        return new ArrivalTimeFilter(System.currentTimeMillis() + startingFrom, startingFrom==0l);
+        long periodInSeconds = Long.parseLong(arguments.get(0));
+        return new ArrivalTimeFilter(System.currentTimeMillis() - periodInSeconds * 1000L, periodInSeconds == 0L);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/5e1ae2dd/broker-core/src/test/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactoryTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactoryTest.java b/broker-core/src/test/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactoryTest.java
new file mode 100644
index 0000000..7c3cee0
--- /dev/null
+++ b/broker-core/src/test/java/org/apache/qpid/server/filter/ArrivalTimeFilterFactoryTest.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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.qpid.server.filter;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ArrivalTimeFilterFactoryTest extends QpidTestCase
+{
+    public void testNewInstance() throws Exception
+    {
+        long currentTime = System.currentTimeMillis();
+        int periodInSeconds = 60;
+        MessageFilter filter =
+                new ArrivalTimeFilterFactory().newInstance(Collections.singletonList(String.valueOf(periodInSeconds)));
+
+        Filterable message = mock(Filterable.class);
+        when(message.getArrivalTime()).thenReturn(currentTime - periodInSeconds * 1000 - 1);
+
+        assertFalse("Message arrived before '1 minute before filter creation' should not be accepted",
+                    filter.matches(message));
+        when(message.getArrivalTime()).thenReturn(currentTime - periodInSeconds  * 1000 / 2);
+        assertTrue("Message arrived after '1 minute before filter creation' should be accepted",
+                   filter.matches(message));
+        when(message.getArrivalTime()).thenReturn(System.currentTimeMillis());
+        assertTrue("Message arrived after filter creation should be accepted", filter.matches(message));
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org