cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/3] Redesign repair messages
Date Tue, 25 Jun 2013 16:59:23 GMT
Updated Branches:
  refs/heads/trunk 764620368 -> eb4fa4a62


http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb4fa4a6/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java b/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java
index c930cc3..8905830 100644
--- a/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java
+++ b/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java
@@ -30,27 +30,23 @@ import org.junit.Before;
 import org.junit.Test;
 
 import org.apache.cassandra.SchemaLoader;
-import org.apache.cassandra.Util;
 import org.apache.cassandra.concurrent.Stage;
 import org.apache.cassandra.concurrent.StageManager;
 import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.*;
-import org.apache.cassandra.db.compaction.PrecompactedRow;
-import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.IMutation;
+import org.apache.cassandra.db.Table;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.locator.TokenMetadata;
 import org.apache.cassandra.net.MessagingService;
-import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.repair.RepairJobDesc;
 import org.apache.cassandra.utils.FBUtilities;
-import org.apache.cassandra.utils.MerkleTree;
 
 import static org.apache.cassandra.service.ActiveRepairService.*;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 public abstract class AntiEntropyServiceTestAbstract extends SchemaLoader
 {
@@ -59,7 +55,7 @@ public abstract class AntiEntropyServiceTestAbstract extends SchemaLoader
 
     public String tablename;
     public String cfname;
-    public TreeRequest request;
+    public RepairJobDesc desc;
     public ColumnFamilyStore store;
     public InetAddress LOCAL, REMOTE;
 
@@ -107,11 +103,9 @@ public abstract class AntiEntropyServiceTestAbstract extends SchemaLoader
 
         local_range = StorageService.instance.getPrimaryRangesForEndpoint(tablename, LOCAL).iterator().next();
 
-        // (we use REMOTE instead of LOCAL so that the reponses for the validator.complete()
get lost)
-        int gcBefore = store.gcBefore(System.currentTimeMillis());
-        request = new TreeRequest(UUID.randomUUID().toString(), REMOTE, local_range, gcBefore,
new CFPair(tablename, cfname));
+        desc = new RepairJobDesc(UUID.randomUUID(), tablename, cfname, local_range);
         // Set a fake session corresponding to this fake request
-        ActiveRepairService.instance.submitArtificialRepairSession(request, tablename, cfname);
+        ActiveRepairService.instance.submitArtificialRepairSession(desc);
     }
 
     @After
@@ -121,51 +115,6 @@ public abstract class AntiEntropyServiceTestAbstract extends SchemaLoader
     }
 
     @Test
-    public void testValidatorPrepare() throws Throwable
-    {
-        Validator validator;
-
-        // write
-        Util.writeColumnFamily(getWriteData());
-
-        // sample
-        validator = new Validator(request);
-        validator.prepare(store);
-
-        // and confirm that the tree was split
-        assertTrue(validator.tree.size() > 1);
-    }
-
-    @Test
-    public void testValidatorComplete() throws Throwable
-    {
-        Validator validator = new Validator(request);
-        validator.prepare(store);
-        validator.completeTree();
-
-        // confirm that the tree was validated
-        Token min = validator.tree.partitioner().getMinimumToken();
-        assert validator.tree.hash(new Range<Token>(min, min)) != null;
-    }
-
-    @Test
-    public void testValidatorAdd() throws Throwable
-    {
-        Validator validator = new Validator(request);
-        IPartitioner part = validator.tree.partitioner();
-        Token mid = part.midpoint(local_range.left, local_range.right);
-        validator.prepare(store);
-
-        // add a row
-        validator.add(new PrecompactedRow(new DecoratedKey(mid, ByteBufferUtil.bytes("inconceivable!")),
-                                          TreeMapBackedSortedColumns.factory.create(Schema.instance.getCFMetaData(tablename,
cfname))));
-        validator.completeTree();
-
-        // confirm that the tree was validated
-        assert validator.tree.hash(local_range) != null;
-    }
-
-    @Test
     public void testGetNeighborsPlusOne() throws Throwable
     {
         // generate rf+1 nodes, and ensure that all nodes are returned
@@ -253,44 +202,6 @@ public abstract class AntiEntropyServiceTestAbstract extends SchemaLoader
         assertEquals(expected, neighbors);
     }
 
-    @Test
-    public void testDifferencer() throws Throwable
-    {
-        // this next part does some housekeeping so that cleanup in the differencer doesn't
error out.
-        ActiveRepairService.RepairFuture sess = ActiveRepairService.instance.submitArtificialRepairSession(request,
tablename, cfname);
-
-        // generate a tree
-        Validator validator = new Validator(request);
-        validator.prepare(store);
-        validator.completeTree();
-        MerkleTree ltree = validator.tree;
-
-        // and a clone
-        validator = new Validator(request);
-        validator.prepare(store);
-        validator.completeTree();
-        MerkleTree rtree = validator.tree;
-
-        // change a range in one of the trees
-        Token ltoken = StorageService.getPartitioner().midpoint(local_range.left, local_range.right);
-        ltree.invalidate(ltoken);
-        MerkleTree.TreeRange changed = ltree.get(ltoken);
-        changed.hash("non-empty hash!".getBytes());
-
-        Set<Range> interesting = new HashSet<Range>();
-        interesting.add(changed);
-
-        // difference the trees
-        // note: we reuse the same endpoint which is bogus in theory but fine here
-        ActiveRepairService.TreeResponse r1 = new ActiveRepairService.TreeResponse(REMOTE,
ltree);
-        ActiveRepairService.TreeResponse r2 = new ActiveRepairService.TreeResponse(REMOTE,
rtree);
-        ActiveRepairService.RepairSession.Differencer diff = sess.session.new Differencer(cfname,
r1, r2);
-        diff.run();
-
-        // ensure that the changed range was recorded
-        assertEquals("Wrong differing ranges", interesting, new HashSet<Range>(diff.differences));
-    }
-
     Set<InetAddress> addTokens(int max) throws Throwable
     {
         TokenMetadata tmd = StorageService.instance.getTokenMetadata();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb4fa4a6/test/unit/org/apache/cassandra/service/SerializationsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/service/SerializationsTest.java b/test/unit/org/apache/cassandra/service/SerializationsTest.java
index 02c2ff7..b47f4d8 100644
--- a/test/unit/org/apache/cassandra/service/SerializationsTest.java
+++ b/test/unit/org/apache/cassandra/service/SerializationsTest.java
@@ -21,6 +21,9 @@ package org.apache.cassandra.service;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.UUID;
 
 import org.junit.Test;
 
@@ -30,6 +33,10 @@ import org.apache.cassandra.dht.RandomPartitioner;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.net.MessageIn;
+import org.apache.cassandra.repair.NodePair;
+import org.apache.cassandra.repair.RepairJobDesc;
+import org.apache.cassandra.repair.Validator;
+import org.apache.cassandra.repair.messages.*;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.MerkleTree;
 
@@ -40,72 +47,183 @@ public class SerializationsTest extends AbstractSerializationsTester
         System.setProperty("cassandra.partitioner", "RandomPartitioner");
     }
 
-    public static Range<Token> FULL_RANGE = new Range<Token>(StorageService.getPartitioner().getMinimumToken(),
StorageService.getPartitioner().getMinimumToken());
+    private static final UUID RANDOM_UUID = UUID.fromString("b5c3d033-75aa-4c2f-a819-947aac7a0c54");
+    private static final Range<Token> FULL_RANGE = new Range<>(StorageService.getPartitioner().getMinimumToken(),
StorageService.getPartitioner().getMinimumToken());
+    private static final RepairJobDesc DESC = new RepairJobDesc(RANDOM_UUID, "Keyspace1",
"Standard1", FULL_RANGE);
 
-    private void testTreeRequestWrite() throws IOException
+    private void testRepairMessageWrite(String fileName, RepairMessage... messages) throws
IOException
     {
-        DataOutputStream out = getOutput("service.TreeRequest.bin");
-        ActiveRepairService.TreeRequest.serializer.serialize(Statics.req, out, getVersion());
-        Statics.req.createMessage().serialize(out, getVersion());
-        out.close();
+        try (DataOutputStream out = getOutput(fileName))
+        {
+            for (RepairMessage message : messages)
+            {
+                testSerializedSize(message, RepairMessage.serializer);
+                RepairMessage.serializer.serialize(message, out, getVersion());
+            }
+            // also serialize MessageOut
+            for (RepairMessage message : messages)
+                message.createMessage().serialize(out,  getVersion());
+        }
+    }
 
-        // test serializedSize
-        testSerializedSize(Statics.req, ActiveRepairService.TreeRequest.serializer);
+    private void testValidationRequestWrite() throws IOException
+    {
+        ValidationRequest message = new ValidationRequest(DESC, 1234);
+        testRepairMessageWrite("service.ValidationRequest.bin", message);
     }
 
     @Test
-    public void testTreeRequestRead() throws IOException
+    public void testValidationRequestRead() throws IOException
     {
         if (EXECUTE_WRITES)
-            testTreeRequestWrite();
+            testValidationRequestWrite();
+
+        try (DataInputStream in = getInput("service.ValidationRequest.bin"))
+        {
+            RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.VALIDATION_REQUEST;
+            assert DESC.equals(message.desc);
+            assert ((ValidationRequest) message).gcBefore == 1234;
 
-        DataInputStream in = getInput("service.TreeRequest.bin");
-        assert ActiveRepairService.TreeRequest.serializer.deserialize(in, getVersion()) !=
null;
-        assert MessageIn.read(in, getVersion(), -1) != null;
-        in.close();
+            assert MessageIn.read(in, getVersion(), -1) != null;
+        }
     }
 
-    private void testTreeResponseWrite() throws IOException
+    private void testValidationCompleteWrite() throws IOException
     {
         // empty validation
-        ActiveRepairService.Validator v0 = new ActiveRepairService.Validator(Statics.req);
+        Validator v0 = new Validator(DESC, FBUtilities.getBroadcastAddress(),  -1);
+        ValidationComplete c0 = new ValidationComplete(DESC, v0.tree);
 
         // validation with a tree
         IPartitioner p = new RandomPartitioner();
         MerkleTree mt = new MerkleTree(p, FULL_RANGE, MerkleTree.RECOMMENDED_DEPTH, Integer.MAX_VALUE);
         for (int i = 0; i < 10; i++)
             mt.split(p.getRandomToken());
-        ActiveRepairService.Validator v1 = new ActiveRepairService.Validator(Statics.req,
mt);
-
-        DataOutputStream out = getOutput("service.TreeResponse.bin");
-        ActiveRepairService.Validator.serializer.serialize(v0, out, getVersion());
-        ActiveRepairService.Validator.serializer.serialize(v1, out, getVersion());
-        v0.createMessage().serialize(out, getVersion());
-        v1.createMessage().serialize(out, getVersion());
-        out.close();
-
-        // test serializedSize
-        testSerializedSize(v0, ActiveRepairService.Validator.serializer);
-        testSerializedSize(v1, ActiveRepairService.Validator.serializer);
+        Validator v1 = new Validator(DESC, FBUtilities.getBroadcastAddress(), mt, -1);
+        ValidationComplete c1 = new ValidationComplete(DESC, v1.tree);
+
+        // validation failed
+        ValidationComplete c3 = new ValidationComplete(DESC);
+
+        testRepairMessageWrite("service.ValidationComplete.bin", c0, c1, c3);
     }
 
     @Test
-    public void testTreeResponseRead() throws IOException
+    public void testValidationCompleteRead() throws IOException
     {
         if (EXECUTE_WRITES)
-            testTreeResponseWrite();
-
-        DataInputStream in = getInput("service.TreeResponse.bin");
-        assert ActiveRepairService.Validator.serializer.deserialize(in, getVersion()) !=
null;
-        assert ActiveRepairService.Validator.serializer.deserialize(in, getVersion()) !=
null;
-        assert MessageIn.read(in, getVersion(), -1) != null;
-        assert MessageIn.read(in, getVersion(), -1) != null;
-        in.close();
+            testValidationCompleteWrite();
+
+        try (DataInputStream in = getInput("service.ValidationComplete.bin"))
+        {
+            // empty validation
+            RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
+            assert DESC.equals(message.desc);
+
+            assert ((ValidationComplete) message).success;
+            assert ((ValidationComplete) message).tree != null;
+
+            // validation with a tree
+            message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
+            assert DESC.equals(message.desc);
+
+            assert ((ValidationComplete) message).success;
+            assert ((ValidationComplete) message).tree != null;
+
+            // failed validation
+            message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
+            assert DESC.equals(message.desc);
+
+            assert !((ValidationComplete) message).success;
+            assert ((ValidationComplete) message).tree == null;
+
+            // MessageOuts
+            for (int i = 0; i < 3; i++)
+                assert MessageIn.read(in, getVersion(), -1) != null;
+        }
     }
 
-    private static class Statics
+    private void testSyncRequestWrite() throws IOException
+    {
+        InetAddress local = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
+        InetAddress src = InetAddress.getByAddress(new byte[]{127, 0, 0, 2});
+        InetAddress dest = InetAddress.getByAddress(new byte[]{127, 0, 0, 3});
+        SyncRequest message = new SyncRequest(DESC, local, src, dest, Collections.singleton(FULL_RANGE));
+
+        testRepairMessageWrite("service.SyncRequest.bin", message);
+    }
+
+    @Test
+    public void testSyncRequestRead() throws IOException
     {
-        private static final ActiveRepairService.CFPair pair = new ActiveRepairService.CFPair("Keyspace1",
"Standard1");
-        private static final ActiveRepairService.TreeRequest req = new ActiveRepairService.TreeRequest("sessionId",
FBUtilities.getBroadcastAddress(), FULL_RANGE, 1234, pair);
+        if (EXECUTE_WRITES)
+            testSyncRequestWrite();
+
+        InetAddress local = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
+        InetAddress src = InetAddress.getByAddress(new byte[]{127, 0, 0, 2});
+        InetAddress dest = InetAddress.getByAddress(new byte[]{127, 0, 0, 3});
+
+        try (DataInputStream in = getInput("service.SyncRequest.bin"))
+        {
+            RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.SYNC_REQUEST;
+            assert DESC.equals(message.desc);
+            assert local.equals(((SyncRequest) message).initiator);
+            assert src.equals(((SyncRequest) message).src);
+            assert dest.equals(((SyncRequest) message).dst);
+            assert ((SyncRequest) message).ranges.size() == 1 && ((SyncRequest) message).ranges.contains(FULL_RANGE);
+
+            assert MessageIn.read(in, getVersion(), -1) != null;
+        }
+    }
+
+    private void testSyncCompleteWrite() throws IOException
+    {
+        InetAddress src = InetAddress.getByAddress(new byte[]{127, 0, 0, 2});
+        InetAddress dest = InetAddress.getByAddress(new byte[]{127, 0, 0, 3});
+        // sync success
+        SyncComplete success = new SyncComplete(DESC, src, dest, true);
+        // sync fail
+        SyncComplete fail = new SyncComplete(DESC, src, dest, false);
+
+        testRepairMessageWrite("service.SyncComplete.bin", success, fail);
+    }
+
+    @Test
+    public void testSyncCompleteRead() throws IOException
+    {
+        if (EXECUTE_WRITES)
+            testSyncCompleteWrite();
+
+        InetAddress src = InetAddress.getByAddress(new byte[]{127, 0, 0, 2});
+        InetAddress dest = InetAddress.getByAddress(new byte[]{127, 0, 0, 3});
+        NodePair nodes = new NodePair(src, dest);
+
+        try (DataInputStream in = getInput("service.SyncComplete.bin"))
+        {
+            // success
+            RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.SYNC_COMPLETE;
+            assert DESC.equals(message.desc);
+
+            assert nodes.equals(((SyncComplete) message).nodes);
+            assert ((SyncComplete) message).success;
+
+            // fail
+            message = RepairMessage.serializer.deserialize(in, getVersion());
+            assert message.messageType == RepairMessage.Type.SYNC_COMPLETE;
+            assert DESC.equals(message.desc);
+
+            assert nodes.equals(((SyncComplete) message).nodes);
+            assert !((SyncComplete) message).success;
+
+            // MessageOuts
+            for (int i = 0; i < 2; i++)
+                assert MessageIn.read(in, getVersion(), -1) != null;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb4fa4a6/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java b/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
index d117426..68a2d76 100644
--- a/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
+++ b/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
@@ -18,38 +18,28 @@
 */
 package org.apache.cassandra.utils;
 
-import static org.apache.cassandra.utils.MerkleTree.RECOMMENDED_DEPTH;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.math.BigInteger;
-import java.util.ArrayDeque;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-
-import org.apache.cassandra.dht.BigIntegerToken;
-import org.apache.cassandra.dht.IPartitioner;
-import org.apache.cassandra.dht.RandomPartitioner;
-import org.apache.cassandra.dht.Range;
-import org.apache.cassandra.dht.Token;
+import java.util.*;
+
+import com.google.common.collect.AbstractIterator;
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import org.apache.hadoop.hdfs.server.common.Storage;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.dht.*;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.MerkleTree.Hashable;
 import org.apache.cassandra.utils.MerkleTree.RowHash;
 import org.apache.cassandra.utils.MerkleTree.TreeRange;
 import org.apache.cassandra.utils.MerkleTree.TreeRangeIterator;
-import org.junit.Before;
-import org.junit.Test;
 
-import com.google.common.collect.AbstractIterator;
+import static org.apache.cassandra.utils.MerkleTree.RECOMMENDED_DEPTH;
+import static org.junit.Assert.*;
 
 public class MerkleTreeTest
 {
@@ -64,9 +54,9 @@ public class MerkleTreeTest
     protected IPartitioner partitioner;
     protected MerkleTree mt;
 
-    private Range fullRange()
+    private Range<Token> fullRange()
     {
-        return new Range(partitioner.getMinimumToken(), partitioner.getMinimumToken());
+        return new Range<>(partitioner.getMinimumToken(), partitioner.getMinimumToken());
     }
 
     @Before
@@ -74,6 +64,8 @@ public class MerkleTreeTest
     {
         TOKEN_SCALE = new BigInteger("8");
         partitioner = new RandomPartitioner();
+        // TODO need to trickle TokenSerializer
+        DatabaseDescriptor.setPartitioner(partitioner);
         mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, Integer.MAX_VALUE);
     }
 
@@ -94,7 +86,7 @@ public class MerkleTreeTest
      * to 8 means that passing -1 through 8 for this method will return values mapped
      * between -1 and Token.MAX_VALUE.
      */
-    public static BigIntegerToken tok(int i)
+    public static Token tok(int i)
     {
         if (i == -1)
             return new BigIntegerToken(new BigInteger("-1"));
@@ -112,11 +104,11 @@ public class MerkleTreeTest
         mt.split(tok(7));
 
         assertEquals(4, mt.size());
-        assertEquals(new Range(tok(7), tok(-1)), mt.get(tok(-1)));
-        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(3)));
-        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(4)));
-        assertEquals(new Range(tok(4), tok(6)), mt.get(tok(6)));
-        assertEquals(new Range(tok(6), tok(7)), mt.get(tok(7)));
+        assertEquals(new Range<>(tok(7), tok(-1)), mt.get(tok(-1)));
+        assertEquals(new Range<>(tok(-1), tok(4)), mt.get(tok(3)));
+        assertEquals(new Range<>(tok(-1), tok(4)), mt.get(tok(4)));
+        assertEquals(new Range<>(tok(4), tok(6)), mt.get(tok(6)));
+        assertEquals(new Range<>(tok(6), tok(7)), mt.get(tok(7)));
 
         // check depths
         assertEquals((byte)1, mt.get(tok(4)).depth);
@@ -147,9 +139,9 @@ public class MerkleTreeTest
         // should fail to split below hashdepth
         assertFalse(mt.split(tok(1)));
         assertEquals(3, mt.size());
-        assertEquals(new Range(tok(4), tok(-1)), mt.get(tok(-1)));
-        assertEquals(new Range(tok(-1), tok(2)), mt.get(tok(2)));
-        assertEquals(new Range(tok(2), tok(4)), mt.get(tok(4)));
+        assertEquals(new Range<>(tok(4), tok(-1)), mt.get(tok(-1)));
+        assertEquals(new Range<>(tok(-1), tok(2)), mt.get(tok(2)));
+        assertEquals(new Range<>(tok(2), tok(4)), mt.get(tok(4)));
     }
 
     @Test
@@ -163,8 +155,8 @@ public class MerkleTreeTest
         // should fail to split above maxsize
         assertFalse(mt.split(tok(2)));
         assertEquals(2, mt.size());
-        assertEquals(new Range(tok(4), tok(-1)), mt.get(tok(-1)));
-        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(4)));
+        assertEquals(new Range<>(tok(4), tok(-1)), mt.get(tok(-1)));
+        assertEquals(new Range<>(tok(-1), tok(4)), mt.get(tok(4)));
     }
 
     @Test
@@ -174,7 +166,7 @@ public class MerkleTreeTest
 
         // (zero, zero]
         ranges = mt.invalids();
-        assertEquals(new Range(tok(-1), tok(-1)), ranges.next());
+        assertEquals(new Range<>(tok(-1), tok(-1)), ranges.next());
         assertFalse(ranges.hasNext());
 
         // all invalid
@@ -184,13 +176,13 @@ public class MerkleTreeTest
         mt.split(tok(3));
         mt.split(tok(5));
         ranges = mt.invalids();
-        assertEquals(new Range(tok(6), tok(-1)), ranges.next());
-        assertEquals(new Range(tok(-1), tok(2)), ranges.next());
-        assertEquals(new Range(tok(2), tok(3)), ranges.next());
-        assertEquals(new Range(tok(3), tok(4)), ranges.next());
-        assertEquals(new Range(tok(4), tok(5)), ranges.next());
-        assertEquals(new Range(tok(5), tok(6)), ranges.next());
-        assertEquals(new Range(tok(6), tok(-1)), ranges.next());
+        assertEquals(new Range<>(tok(6), tok(-1)), ranges.next());
+        assertEquals(new Range<>(tok(-1), tok(2)), ranges.next());
+        assertEquals(new Range<>(tok(2), tok(3)), ranges.next());
+        assertEquals(new Range<>(tok(3), tok(4)), ranges.next());
+        assertEquals(new Range<>(tok(4), tok(5)), ranges.next());
+        assertEquals(new Range<>(tok(5), tok(6)), ranges.next());
+        assertEquals(new Range<>(tok(6), tok(-1)), ranges.next());
         assertFalse(ranges.hasNext());
     }
 
@@ -199,7 +191,7 @@ public class MerkleTreeTest
     public void testHashFull()
     {
         byte[] val = DUMMY;
-        Range range = new Range(tok(-1), tok(-1));
+        Range<Token> range = new Range<>(tok(-1), tok(-1));
 
         // (zero, zero]
         assertNull(mt.hash(range));
@@ -216,11 +208,11 @@ public class MerkleTreeTest
         byte[] val = DUMMY;
         byte[] leftval = hashed(val, 1, 1);
         byte[] partialval = hashed(val, 1);
-        Range left = new Range(tok(-1), tok(4));
-        Range partial = new Range(tok(2), tok(4));
-        Range right = new Range(tok(4), tok(-1));
-        Range linvalid = new Range(tok(1), tok(4));
-        Range rinvalid = new Range(tok(4), tok(6));
+        Range<Token> left = new Range<>(tok(-1), tok(4));
+        Range<Token> partial = new Range<>(tok(2), tok(4));
+        Range<Token> right = new Range<>(tok(4), tok(-1));
+        Range<Token> linvalid = new Range<>(tok(1), tok(4));
+        Range<Token> rinvalid = new Range<>(tok(4), tok(6));
 
         // (zero,two] (two,four] (four, zero]
         mt.split(tok(4));
@@ -250,10 +242,10 @@ public class MerkleTreeTest
         byte[] lchildval = hashed(val, 3, 3, 2);
         byte[] rchildval = hashed(val, 2, 2);
         byte[] fullval = hashed(val, 3, 3, 2, 2, 2);
-        Range full = new Range(tok(-1), tok(-1));
-        Range lchild = new Range(tok(-1), tok(4));
-        Range rchild = new Range(tok(4), tok(-1));
-        Range invalid = new Range(tok(1), tok(-1));
+        Range<Token> full = new Range<>(tok(-1), tok(-1));
+        Range<Token> lchild = new Range<>(tok(-1), tok(4));
+        Range<Token> rchild = new Range<>(tok(4), tok(-1));
+        Range<Token> invalid = new Range<>(tok(1), tok(-1));
 
         // (zero,one] (one, two] (two,four] (four, six] (six, zero]
         mt.split(tok(4));
@@ -286,9 +278,9 @@ public class MerkleTreeTest
         byte[] val = DUMMY;
         byte[] childfullval = hashed(val, 5, 5, 4);
         byte[] fullval = hashed(val, 5, 5, 4, 3, 2, 1);
-        Range childfull = new Range(tok(-1), tok(4));
-        Range full = new Range(tok(-1), tok(-1));
-        Range invalid = new Range(tok(4), tok(-1));
+        Range<Token> childfull = new Range<>(tok(-1), tok(4));
+        Range<Token> full = new Range<>(tok(-1), tok(-1));
+        Range<Token> invalid = new Range<>(tok(4), tok(-1));
 
         mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, Integer.MAX_VALUE);
         mt.split(tok(16));
@@ -332,7 +324,7 @@ public class MerkleTreeTest
         for (TreeRange range : ranges)
             range.addHash(new RowHash(range.right, new byte[0]));
 
-        assert mt.hash(new Range(tok(-1), tok(-1))) != null :
+        assert mt.hash(new Range<>(tok(-1), tok(-1))) != null :
             "Could not hash tree " + mt;
     }
 
@@ -347,7 +339,7 @@ public class MerkleTreeTest
     {
         TOKEN_SCALE = new BigInteger("16"); // this test needs slightly more resolution
 
-        Range full = new Range(tok(-1), tok(-1));
+        Range<Token> full = new Range<>(tok(-1), tok(-1));
         Iterator<TreeRange> ranges;
         MerkleTree mt2 = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, Integer.MAX_VALUE);
 
@@ -392,9 +384,7 @@ public class MerkleTreeTest
     @Test
     public void testSerialization() throws Exception
     {
-        Range full = new Range(tok(-1), tok(-1));
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        ObjectOutputStream oout = new ObjectOutputStream(bout);
+        Range<Token> full = new Range<>(tok(-1), tok(-1));
 
         // populate and validate the tree
         mt.maxsize(256);
@@ -403,16 +393,13 @@ public class MerkleTreeTest
             range.addAll(new HIterator(range.right));
 
         byte[] initialhash = mt.hash(full);
-        oout.writeObject(mt);
-        oout.close();
 
-        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
-        ObjectInputStream oin = new ObjectInputStream(bin);
-        MerkleTree restored = (MerkleTree)oin.readObject();
+        ByteArrayDataOutput out = ByteStreams.newDataOutput();
+        MerkleTree.serializer.serialize(mt, out, MessagingService.current_version);
+        byte[] serialized = out.toByteArray();
 
-        // restore partitioner after serialization
-        restored.partitioner(partitioner);
-        restored.fullRange = fullRange();
+        ByteArrayDataInput in = ByteStreams.newDataInput(serialized);
+        MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version);
 
         assertHashEquals(initialhash, restored.hash(full));
     }
@@ -420,7 +407,6 @@ public class MerkleTreeTest
     @Test
     public void testDifference()
     {
-        Range full = new Range(tok(-1), tok(-1));
         int maxsize = 16;
         mt.maxsize(maxsize);
         MerkleTree mt2 = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, maxsize);
@@ -451,7 +437,7 @@ public class MerkleTreeTest
         // trees should disagree for (leftmost.left, middle.right]
         List<TreeRange> diffs = MerkleTree.difference(mt, mt2);
         assertEquals(diffs + " contains wrong number of differences:", 1, diffs.size());
-        assertTrue(diffs.contains(new Range(leftmost.left, middle.right)));
+        assertTrue(diffs.contains(new Range<>(leftmost.left, middle.right)));
     }
 
     /**


Mime
View raw message