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 #5: Abstract the offset from the API
Date Thu, 03 Jan 2019 14:56:04 GMT
cschneider closed pull request #5: Abstract the offset from the API
URL: https://github.com/apache/aries-journaled-events/pull/5
 
 
   

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 08f8f7f..872c1c1 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,17 +21,7 @@
  * 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.
- * TODO How do we provide ordering without being too specific?
  */
-public interface Position {
-    long getOffset();
+public interface Position extends Comparable<Position> {
 
-
-    /**
-     * Serialise the position into a {@code String} string.
-     *
-     * @see {@link Messaging#positionFromString(String)} for the reverse operation.
-     * @return the position as a string
-     */
-    String positionToString();
 }
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 6619ab7..17b19d1 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
@@ -27,7 +27,7 @@
         this.offset = offset;
     }
 
-    public long getOffset() {
+    long getOffset() {
         return offset;
     }
 
@@ -37,7 +37,7 @@ public String positionToString() {
     }
 
     @Override
-    public String toString() {
-        return positionToString();
+    public int compareTo(Position p) {
+        return Long.compare(((MemoryPosition)p).offset, offset);
     }
 }
diff --git a/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/Topic.java
b/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/Topic.java
index 917c989..b6e2348 100644
--- a/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/Topic.java
+++ b/org.apache.aries.events.memory/src/main/java/org/apache/aries/events/memory/Topic.java
@@ -48,12 +48,12 @@ public Position send(Message message) {
     }
 
     public Subscription subscribe(Position position, Seek seek, Consumer<Received>
callback) {
-        long startOffset = getStartOffset(position, seek);
+        long startOffset = getStartOffset((MemoryPosition) position, seek);
         log.debug("Consuming from " + startOffset);
         return new TopicSubscription(startOffset, callback);
     }
 
-    private long getStartOffset(Position position, Seek seek) {
+    private long getStartOffset(MemoryPosition position, Seek seek) {
         if (position != null) {
             return position.getOffset();
         } else {
diff --git a/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MessagingTest.java
b/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MessagingTest.java
index 2a70b6e..b805094 100644
--- a/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MessagingTest.java
+++ b/org.apache.aries.events.memory/src/test/java/org/apache/aries/events/memory/MessagingTest.java
@@ -3,6 +3,7 @@
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.Matchers.contains;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.MockitoAnnotations.initMocks;
@@ -55,7 +56,7 @@ public void after() {
     @Test
     public void testPositionFromString() {
         Position pos = messaging.positionFromString("1");
-        assertThat(pos.getOffset(), equalTo(1l));
+        assertEquals(0, pos.compareTo(new MemoryPosition(1)));
     }
     
     @Test
@@ -66,7 +67,7 @@ public void testSend() {
         verify(callback, timeout(1000)).accept(messageCaptor.capture());
         Received received = messageCaptor.getValue();
         assertThat(received.getMessage().getPayload(), equalTo(toBytes(content)));
-        assertThat(received.getPosition().getOffset(), equalTo(0l));
+        assertEquals(0, received.getPosition().compareTo(new MemoryPosition(0)));
         assertThat(received.getMessage().getProperties().size(), equalTo(1));
         assertThat(received.getMessage().getProperties().get("my"), equalTo("testvalue"));
     }


 

----------------------------------------------------------------
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