You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by wi...@apache.org on 2018/08/22 16:34:39 UTC
[geode] branch develop updated: GEODE-5612: Fix
RVVExceptionB.writeReceived() (#2354)
This is an automated email from the ASF dual-hosted git repository.
wirebaron pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 7fe2f18 GEODE-5612: Fix RVVExceptionB.writeReceived() (#2354)
7fe2f18 is described below
commit 7fe2f1876a1067a33b6488c8350fbd14ed129885
Author: Brian Rowe <br...@pivotal.io>
AuthorDate: Wed Aug 22 09:34:34 2018 -0700
GEODE-5612: Fix RVVExceptionB.writeReceived() (#2354)
---
.../internal/cache/versions/RVVExceptionB.java | 17 +++++-----
.../cache/versions/RVVExceptionJUnitTest.java | 39 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RVVExceptionB.java b/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RVVExceptionB.java
index 9825af6..78d33c8 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RVVExceptionB.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RVVExceptionB.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.cache.versions;
import java.io.DataOutput;
import java.io.IOException;
import java.util.BitSet;
+import java.util.LinkedList;
import java.util.NoSuchElementException;
import org.apache.geode.internal.InternalDataSerializer;
@@ -126,22 +127,20 @@ public class RVVExceptionB extends RVVException {
}
protected void writeReceived(DataOutput out) throws IOException {
- final int size = received == null ? 1 : received.length() + 1;
-
- int deltaIndex = size - 1;
- long[] deltas = new long[size];
+ LinkedList<Long> deltas = new LinkedList<>();
long last = this.nextVersion;
// TODO - it would be better just to serialize the longs[] in the BitSet
// as is, rather than go through this delta encoding.
for (ReceivedVersionsReverseIterator it = receivedVersionsReverseIterator(); it.hasNext();) {
Long version = it.next();
- long delta = last - version.longValue();
- deltas[--deltaIndex] = delta;
- last = version.longValue();
+ deltas.addFirst(last - version);
+ last = version;
}
- deltas[0] = last - this.previousVersion;
- InternalDataSerializer.writeUnsignedVL(size - 1, out);
+ InternalDataSerializer.writeUnsignedVL(deltas.size(), out); // Number of received versions
+
+ // Last version is the oldest received version, still need the delta from there to previous
+ deltas.addFirst(last - previousVersion);
for (long value : deltas) {
InternalDataSerializer.writeUnsignedVL(value, out);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RVVExceptionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RVVExceptionJUnitTest.java
index 88a7a19..d83172f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RVVExceptionJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RVVExceptionJUnitTest.java
@@ -15,8 +15,14 @@
package org.apache.geode.internal.cache.versions;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+
+import java.io.DataOutput;
import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
public class RVVExceptionJUnitTest {
@@ -32,10 +38,43 @@ public class RVVExceptionJUnitTest {
}
@Test
+ public void testRVVExceptionBOutput() throws Exception {
+ testExceptionOutput(new RVVExceptionB(50, 100));
+ }
+
+ @Test
public void testRVVExceptionT() {
RVVExceptionT ex = new RVVExceptionT(5, 10);
ex.add(8);
ex.add(6);
assertEquals(8, ex.getHighestReceivedVersion());
}
+
+ @Test
+ public void testRVVExceptionTOutput() throws Exception {
+ testExceptionOutput(new RVVExceptionT(50, 100));
+ }
+
+ // Exception is expected to be initialized with (50, 100)
+ private void testExceptionOutput(RVVException ex) throws Exception {
+ ex.add(60);
+ ex.add(85);
+ ex.add(70);
+ ex.add(72);
+ ex.add(74);
+ ex.add(73);
+
+ DataOutput mockOutput = mock(DataOutput.class);
+ InOrder inOrder = Mockito.inOrder(mockOutput);
+ ex.toData(mockOutput);
+
+ inOrder.verify(mockOutput).writeByte(50); // prev = 50
+ inOrder.verify(mockOutput).writeByte(6); // 6 received versions
+ inOrder.verify(mockOutput, times(2)).writeByte(10); // 60, 70
+ inOrder.verify(mockOutput).writeByte(2); // 72
+ inOrder.verify(mockOutput, times(2)).writeByte(1); // 73, 74
+ inOrder.verify(mockOutput).writeByte(11); // 85
+ inOrder.verify(mockOutput).writeByte(15); // 100
+ inOrder.verifyNoMoreInteractions();
+ }
}