aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] cschneider closed pull request #9: Document the Position comparison order
Date Thu, 03 Jan 2019 16:35:20 GMT
cschneider closed pull request #9: Document the Position comparison order
URL: https://github.com/apache/aries-journaled-events/pull/9
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/org.apache.aries.events.api/src/main/java/org/apache/aries/events/api/Position.java
b/org.apache.aries.events.api/src/main/java/org/apache/aries/events/api/Position.java
index b26ddee..e211638 100644
--- a/org.apache.aries.events.api/src/main/java/org/apache/aries/events/api/Position.java
+++ b/org.apache.aries.events.api/src/main/java/org/apache/aries/events/api/Position.java
@@ -21,6 +21,12 @@
  * Position in a the topic.
  * E.g. For a kafka implementation this would be a list of (partition, offset) as we do not
support partitions 
  * this could simply be like an offset.
+ *
+ * The {@code Position} positions are ordered. The relative order between
+ * two positions can be computed by invoking {@code Comparable#compareTo}.
+ * Comparing this position with a specified position will return a negative
+ * integer, zero, or a positive integer as this position happened before,
+ * happened concurrently, or happened after the specified position.
  */
 public interface Position extends Comparable<Position> {
 
diff --git a/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/MemoryPosition.java
b/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/MemoryPosition.java
index 17b19d1..fab1bea 100644
--- a/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/MemoryPosition.java
+++ b/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/MemoryPosition.java
@@ -38,6 +38,6 @@ public String positionToString() {
 
     @Override
     public int compareTo(Position p) {
-        return Long.compare(((MemoryPosition)p).offset, offset);
+        return Long.compare(offset, ((MemoryPosition)p).offset);
     }
 }
diff --git a/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MemoryPositionTest.java
b/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MemoryPositionTest.java
new file mode 100644
index 0000000..7613d2c
--- /dev/null
+++ b/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MemoryPositionTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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 SF 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.aries.events.memory;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MemoryPositionTest {
+
+    @Test
+    public void testCompareTo() throws Exception {
+        assertEquals(0, comparePositions(position(5),  position(5)));
+        assertEquals(1, comparePositions(position(10), position(5)));
+        assertEquals(-1, comparePositions(position(2), position(5)));
+    }
+
+    private int comparePositions(MemoryPosition position1, MemoryPosition position2) {
+        return position1.compareTo(position2);
+    }
+
+    private MemoryPosition position(long offset) {
+        return new MemoryPosition(offset);
+    }
+
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message