james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/2] james-project git commit: JAMES-2544 The slice identifier should not incorporate duration
Date Thu, 27 Sep 2018 09:21:39 GMT
Repository: james-project
Updated Branches:
  refs/heads/master b70ca1a7c -> e3bdf9b6a


JAMES-2544 The slice identifier should not incorporate duration

Because we use only start timestamp qs an ID in cassandra, using duration
as part of slice is really confusing


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8a5677fe
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8a5677fe
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8a5677fe

Branch: refs/heads/master
Commit: 8a5677fed21860ba845fb5f062b044080fdc3a91
Parents: b70ca1a
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Sep 26 08:27:45 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Sep 26 09:27:41 2018 +0700

----------------------------------------------------------------------
 .../cassandra/CassandraMailQueueBrowser.java    |  4 +--
 .../view/cassandra/model/BucketedSlices.java    | 29 ++++++++------------
 .../view/cassandra/EnqueuedMailsDaoTest.java    |  3 +-
 .../cassandra/model/BucketedSlicesTest.java     | 24 ++++++++--------
 4 files changed, 26 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8a5677fe/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueBrowser.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueBrowser.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueBrowser.java
index 21dedb8..176d2b7 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueBrowser.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueBrowser.java
@@ -115,8 +115,8 @@ class CassandraMailQueueBrowser {
 
     private Stream<Slice> allSlicesStartingAt(Optional<Instant> maybeBrowseStart)
{
         return maybeBrowseStart
-            .map(browseStart -> Slice.of(browseStart, configuration.getSliceWindow()))
-            .map(startSlice -> allSlicesTill(startSlice, clock.instant()))
+            .map(Slice::of)
+            .map(startSlice -> allSlicesTill(startSlice, clock.instant(), configuration.getSliceWindow()))
             .orElse(Stream.empty());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8a5677fe/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlices.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlices.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlices.java
index 1f5d3d5..d35b6d7 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlices.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlices.java
@@ -65,22 +65,22 @@ public class BucketedSlices {
 
     public static class Slice {
 
-        public static Slice of(Instant sliceStartInstant, Duration sliceWindowSize) {
-            return new Slice(sliceStartInstant, sliceWindowSize);
+        public static Slice of(Instant sliceStartInstant) {
+            return new Slice(sliceStartInstant);
         }
 
-        public static Stream<Slice> allSlicesTill(Slice firstSlice, Instant endAt)
{
-            long sliceCount = calculateSliceCount(firstSlice, endAt);
+        public static Stream<Slice> allSlicesTill(Slice firstSlice, Instant endAt,
Duration windowSize) {
+            long sliceCount = calculateSliceCount(firstSlice, endAt, windowSize);
             long startAtSeconds =  firstSlice.getStartSliceInstant().getEpochSecond();
-            long sliceWindowSizeInSecond = firstSlice.getSliceWindowSize().getSeconds();
+            long sliceWindowSizeInSecond = windowSize.getSeconds();
 
             return LongStream.range(0, sliceCount)
                 .map(slicePosition -> startAtSeconds + sliceWindowSizeInSecond * slicePosition)
                 .mapToObj(Instant::ofEpochSecond)
-                .map(sliceStartInstant -> Slice.of(sliceStartInstant, firstSlice.getSliceWindowSize()));
+                .map(Slice::of);
         }
 
-        private static long calculateSliceCount(Slice firstSlice, Instant endAt) {
+        private static long calculateSliceCount(Slice firstSlice, Instant endAt, Duration
windowSize) {
             long startAtSeconds =  firstSlice.getStartSliceInstant().getEpochSecond();
             long endAtSeconds = endAt.getEpochSecond();
             long timeDiffInSecond = endAtSeconds - startAtSeconds;
@@ -88,43 +88,36 @@ public class BucketedSlices {
             if (timeDiffInSecond < 0) {
                 return 0;
             } else {
-                return (timeDiffInSecond / firstSlice.getSliceWindowSize().getSeconds())
+ 1;
+                return (timeDiffInSecond / windowSize.getSeconds()) + 1;
             }
         }
 
         private final Instant startSliceInstant;
-        private final Duration sliceWindowSize;
 
-        private Slice(Instant startSliceInstant, Duration sliceWindowSize) {
+        private Slice(Instant startSliceInstant) {
             Preconditions.checkNotNull(startSliceInstant);
-            Preconditions.checkNotNull(sliceWindowSize);
 
             this.startSliceInstant = startSliceInstant;
-            this.sliceWindowSize = sliceWindowSize;
         }
 
         public Instant getStartSliceInstant() {
             return startSliceInstant;
         }
 
-        public Duration getSliceWindowSize() {
-            return sliceWindowSize;
-        }
 
         @Override
         public final boolean equals(Object o) {
             if (o instanceof Slice) {
                 Slice slice = (Slice) o;
 
-                return Objects.equals(this.sliceWindowSize, slice.sliceWindowSize)
-                    && Objects.equals(this.startSliceInstant, slice.startSliceInstant);
+                return Objects.equals(this.startSliceInstant, slice.startSliceInstant);
             }
             return false;
         }
 
         @Override
         public final int hashCode() {
-            return Objects.hash(startSliceInstant, sliceWindowSize);
+            return Objects.hash(startSliceInstant);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8a5677fe/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/EnqueuedMailsDaoTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/EnqueuedMailsDaoTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/EnqueuedMailsDaoTest.java
index 94a80a3..f649a48 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/EnqueuedMailsDaoTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/EnqueuedMailsDaoTest.java
@@ -23,7 +23,6 @@ import static org.apache.james.queue.rabbitmq.view.cassandra.model.BucketedSlice
 import static org.apache.james.queue.rabbitmq.view.cassandra.model.BucketedSlices.Slice;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.time.Duration;
 import java.time.Instant;
 import java.util.stream.Stream;
 
@@ -46,7 +45,7 @@ class EnqueuedMailsDaoTest {
     private static int BUCKET_ID_VALUE = 10;
     private static final BucketId BUCKET_ID = BucketId.of(BUCKET_ID_VALUE);
     private static final Instant NOW = Instant.now();
-    private static final Slice SLICE_OF_NOW = Slice.of(NOW, Duration.ofSeconds(100));
+    private static final Slice SLICE_OF_NOW = Slice.of(NOW);
 
     @RegisterExtension
     static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraMailQueueViewModule.MODULE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/8a5677fe/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlicesTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlicesTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlicesTest.java
index 5386050..842216c 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlicesTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/BucketedSlicesTest.java
@@ -41,8 +41,8 @@ class BucketedSlicesTest {
     private static final Instant FIRST_SLICE_INSTANT_NEXT_TWO_HOUR = FIRST_SLICE_INSTANT.plusSeconds(ONE_HOUR_IN_SECONDS
* 2);
 
     private static final Duration ONE_HOUR_SLICE_WINDOW = Duration.ofSeconds(ONE_HOUR_IN_SECONDS);
-    private static final Slice FIRST_SLICE = Slice.of(FIRST_SLICE_INSTANT, ONE_HOUR_SLICE_WINDOW);
-    private static final Slice FIRST_SLICE_NEXT_TWO_HOUR = Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR,
Duration.ofSeconds(ONE_HOUR_IN_SECONDS));
+    private static final Slice FIRST_SLICE = Slice.of(FIRST_SLICE_INSTANT);
+    private static final Slice FIRST_SLICE_NEXT_TWO_HOUR = Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR);
 
     @Test
     void bucketIdShouldMatchBeanContract() {
@@ -64,31 +64,31 @@ class BucketedSlicesTest {
 
     @Test
     void allSlicesTillShouldReturnOnlyFirstSliceWhenEndAtInTheSameInterval() {
-        assertThat(Slice.allSlicesTill(FIRST_SLICE, FIRST_SLICE_INSTANT.plusSeconds(ONE_HOUR_IN_SECONDS
- 1)))
+        assertThat(Slice.allSlicesTill(FIRST_SLICE, FIRST_SLICE_INSTANT.plusSeconds(ONE_HOUR_IN_SECONDS
- 1), ONE_HOUR_SLICE_WINDOW))
             .containsOnly(FIRST_SLICE);
     }
 
     @Test
     void allSlicesTillShouldReturnAllSlicesBetweenStartAndEndAt() {
-        Stream<Slice> allSlices = Slice.allSlicesTill(FIRST_SLICE, FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(ONE_HOUR_IN_SECONDS
- 1));
+        Stream<Slice> allSlices = Slice.allSlicesTill(FIRST_SLICE, FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(ONE_HOUR_IN_SECONDS
- 1), ONE_HOUR_SLICE_WINDOW);
 
         assertThat(allSlices)
             .containsExactly(
                 FIRST_SLICE,
-                Slice.of(FIRST_SLICE_INSTANT_NEXT_HOUR, ONE_HOUR_SLICE_WINDOW),
-                Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR, ONE_HOUR_SLICE_WINDOW));
+                Slice.of(FIRST_SLICE_INSTANT_NEXT_HOUR),
+                Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR));
     }
 
     @Test
     void allSlicesTillShouldReturnSameSlicesWhenEndAtsAreInTheSameInterval() {
-        Stream<Slice> allSlicesEndAtTheStartOfWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR);
-        Stream<Slice> allSlicesEndAtTheMiddleOfWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(1000));
-        Stream<Slice> allSlicesEndAtTheEndWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(ONE_HOUR_IN_SECONDS - 1));
+        Stream<Slice> allSlicesEndAtTheStartOfWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR, ONE_HOUR_SLICE_WINDOW);
+        Stream<Slice> allSlicesEndAtTheMiddleOfWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(1000), ONE_HOUR_SLICE_WINDOW);
+        Stream<Slice> allSlicesEndAtTheEndWindow = Slice.allSlicesTill(FIRST_SLICE,
FIRST_SLICE_INSTANT_NEXT_TWO_HOUR.plusSeconds(ONE_HOUR_IN_SECONDS - 1), ONE_HOUR_SLICE_WINDOW);
 
         Slice [] allSlicesInThreeHours = {
             FIRST_SLICE,
-            Slice.of(FIRST_SLICE_INSTANT_NEXT_HOUR, ONE_HOUR_SLICE_WINDOW),
-            Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR, ONE_HOUR_SLICE_WINDOW)};
+            Slice.of(FIRST_SLICE_INSTANT_NEXT_HOUR),
+            Slice.of(FIRST_SLICE_INSTANT_NEXT_TWO_HOUR)};
 
         assertThat(allSlicesEndAtTheStartOfWindow)
             .containsExactly(allSlicesInThreeHours);
@@ -102,7 +102,7 @@ class BucketedSlicesTest {
 
     @Test
     void allSlicesTillShouldReturnEmptyIfEndAtBeforeStartSlice() {
-        Stream<Slice> allSlices = Slice.allSlicesTill(FIRST_SLICE_NEXT_TWO_HOUR, FIRST_SLICE_INSTANT);
+        Stream<Slice> allSlices = Slice.allSlicesTill(FIRST_SLICE_NEXT_TWO_HOUR, FIRST_SLICE_INSTANT,
ONE_HOUR_SLICE_WINDOW);
 
         assertThat(allSlices).isEmpty();
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message