|
@@ -18,6 +18,8 @@
|
|
|
|
|
|
package org.apache.zookeeper.server.quorum;
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
@@ -36,8 +38,8 @@ import org.apache.jute.InputArchive;
|
|
|
import org.apache.jute.OutputArchive;
|
|
|
import org.apache.zookeeper.WatchedEvent;
|
|
|
import org.apache.zookeeper.Watcher;
|
|
|
-import org.apache.zookeeper.ZooDefs;
|
|
|
import org.apache.zookeeper.Watcher.Event.EventType;
|
|
|
+import org.apache.zookeeper.ZooDefs;
|
|
|
import org.apache.zookeeper.data.Stat;
|
|
|
import org.apache.zookeeper.server.ByteBufferInputStream;
|
|
|
import org.apache.zookeeper.server.ByteBufferOutputStream;
|
|
@@ -506,7 +508,8 @@ public class Zab1_0Test {
|
|
|
oa.writeRecord(qp, null);
|
|
|
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
- Assert.assertEquals(Leader.DIFF, qp.getType());
|
|
|
+ Assert.assertEquals(Leader.SNAP, qp.getType());
|
|
|
+ deserializeSnapshot(ia);
|
|
|
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
Assert.assertEquals(Leader.NEWLEADER, qp.getType());
|
|
@@ -517,12 +520,29 @@ public class Zab1_0Test {
|
|
|
qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null);
|
|
|
oa.writeRecord(qp, null);
|
|
|
|
|
|
+ readPacketSkippingPing(ia, qp);
|
|
|
+ Assert.assertEquals(Leader.NEWLEADER, qp.getType());
|
|
|
+ Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
|
|
|
+ Assert.assertEquals(1, l.self.getAcceptedEpoch());
|
|
|
+ Assert.assertEquals(1, l.self.getCurrentEpoch());
|
|
|
+
|
|
|
+ qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null);
|
|
|
+ oa.writeRecord(qp, null);
|
|
|
+
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
Assert.assertEquals(Leader.UPTODATE, qp.getType());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private void deserializeSnapshot(InputArchive ia)
|
|
|
+ throws IOException {
|
|
|
+ ZKDatabase zkdb = new ZKDatabase(null);
|
|
|
+ zkdb.deserializeSnapshot(ia);
|
|
|
+ String signature = ia.readString("signature");
|
|
|
+ assertEquals("BenWasHere", signature);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testLeaderBehind() throws Exception {
|
|
|
testLeaderConversation(new LeaderConversation() {
|
|
@@ -545,12 +565,23 @@ public class Zab1_0Test {
|
|
|
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
|
|
|
oa.writeRecord(qp, null);
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
- Assert.assertEquals(Leader.DIFF, qp.getType());
|
|
|
+ Assert.assertEquals(Leader.SNAP, qp.getType());
|
|
|
+ deserializeSnapshot(ia);
|
|
|
+
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
Assert.assertEquals(Leader.NEWLEADER, qp.getType());
|
|
|
Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
|
|
|
+
|
|
|
qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null);
|
|
|
oa.writeRecord(qp, null);
|
|
|
+
|
|
|
+ readPacketSkippingPing(ia, qp);
|
|
|
+ Assert.assertEquals(Leader.NEWLEADER, qp.getType());
|
|
|
+ Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
|
|
|
+
|
|
|
+ qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null);
|
|
|
+ oa.writeRecord(qp, null);
|
|
|
+
|
|
|
readPacketSkippingPing(ia, qp);
|
|
|
Assert.assertEquals(Leader.UPTODATE, qp.getType());
|
|
|
}
|