本文整理汇总了Java中org.apache.zookeeper.server.ByteBufferOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferOutputStream类的具体用法?Java ByteBufferOutputStream怎么用?Java ByteBufferOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteBufferOutputStream类属于org.apache.zookeeper.server包,在下文中一共展示了ByteBufferOutputStream类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testAbandonBeforeACKEpoch
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
/**
* Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which is sent
* by the leader upon receipt of LearnerInfo from a quorum), the leader does not start using this epoch
* as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192
* @throws Exception
*/
@Test
public void testAbandonBeforeACKEpoch() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[12];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
// The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced
Assert.assertEquals(0, l.self.getCurrentEpoch());
}
});
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:32,代码来源:Zab1_0Test.java
示例2: testAbandonBeforeACKEpoch
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
/**
* Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which is sent
* by the leader upon receipt of LearnerInfo from a quorum), the leader does not start using this epoch
* as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192
* @throws Exception
*/
@Test
public void testAbandonBeforeACKEpoch() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
// The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced
Assert.assertEquals(0, l.self.getCurrentEpoch());
}
});
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:32,代码来源:Zab1_0Test.java
示例3: testUnnecessarySnap
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testUnnecessarySnap() throws Exception {
testPopulatedLeaderConversation(new PopulatedLeaderConversation() {
@Override
public void converseWithLeader(InputArchive ia, OutputArchive oa,
Leader l, long zxid) throws Exception {
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[12];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 1,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(2, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(2, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
byte epochBytes[] = new byte[4];
final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes);
wrappedEpochBytes.putInt(1);
qp = new QuorumPacket(Leader.ACKEPOCH, zxid, epochBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
}
}, 2);
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:40,代码来源:Zab1_0Test.java
示例4: testLeaderBehind
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testLeaderBehind() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[12];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
/* we are going to say we last acked epoch 20 */
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, ZxidUtils.makeZxid(20, 0),
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
}
});
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:36,代码来源:Zab1_0Test.java
示例5: testUnnecessarySnap
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testUnnecessarySnap() throws Exception {
testPopulatedLeaderConversation(new PopulatedLeaderConversation() {
@Override
public void converseWithLeader(InputArchive ia, OutputArchive oa,
Leader l, long zxid) throws Exception {
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 1,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(2, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(2, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
byte epochBytes[] = new byte[4];
final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes);
wrappedEpochBytes.putInt(1);
qp = new QuorumPacket(Leader.ACKEPOCH, zxid, epochBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
}
}, 2);
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:40,代码来源:Zab1_0Test.java
示例6: testLeaderBehind
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testLeaderBehind() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
/* we are going to say we last acked epoch 20 */
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, ZxidUtils.makeZxid(20, 0),
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
}
});
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:36,代码来源:Zab1_0Test.java
示例7: testNormalRun
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testNormalRun() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException {
Assert.assertEquals(0, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[12];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
}
});
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:46,代码来源:Zab1_0Test.java
示例8: testTxnTimeout
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testTxnTimeout() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException, org.apache.zookeeper.server.quorum.Leader.XidRolloverException {
Assert.assertEquals(0, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
l.propose(createNodeRequest(l.zk.getZxid()));
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.PROPOSAL, qp.getType());
LOG.info("Proposal sent.");
for (int i = 0; i < (2 * SYNC_LIMIT) + 2; i++) {
try {
ia.readRecord(qp, null);
LOG.info("Ping received: " + i);
qp = new QuorumPacket(Leader.PING, qp.getZxid(), "".getBytes(), null);
oa.writeRecord(qp, null);
} catch (EOFException e) {
return;
}
}
Assert.fail("Connection hasn't been closed by leader after transaction times out.");
}
private Request createNodeRequest(long zxid) throws IOException {
TxnHeader hdr = new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.create);
CreateTxn ct = new CreateTxn("/foo", "data".getBytes(), null, true, 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputArchive boa = BinaryOutputArchive.getArchive(baos);
boa.writeRecord(hdr, "header");
boa.writeRecord(ct, "txn");
baos.close();
Request rq = new Request(null, 1, 1, ZooDefs.OpCode.create, ByteBuffer.wrap(baos.toByteArray()), null);
rq.zxid = zxid;
rq.hdr = hdr;
rq.txn = ct;
return rq;
}
});
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:80,代码来源:Zab1_0Test.java
示例9: testNormalRun
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testNormalRun() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException {
Assert.assertEquals(0, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
}
});
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:46,代码来源:Zab1_0Test.java
示例10: testTxnTimeout
import org.apache.zookeeper.server.ByteBufferOutputStream; //导入依赖的package包/类
@Test
public void testTxnTimeout() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException, org.apache.zookeeper.server.quorum.Leader.XidRolloverException {
Assert.assertEquals(0, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(0, l.self.getCurrentEpoch());
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
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());
long zxid = l.zk.getZxid();
l.propose(new Request(1, 1, ZooDefs.OpCode.create,
new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.create),
new CreateTxn("/test", "hola".getBytes(), null, true, 0), zxid));
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.PROPOSAL, qp.getType());
LOG.info("Proposal sent.");
for (int i = 0; i < (2 * SYNC_LIMIT) + 2; i++) {
try {
ia.readRecord(qp, null);
LOG.info("Ping received: " + i);
qp = new QuorumPacket(Leader.PING, qp.getZxid(), "".getBytes(), null);
oa.writeRecord(qp, null);
} catch (EOFException e) {
return;
}
}
Assert.fail("Connection hasn't been closed by leader after transaction times out.");
}
});
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:67,代码来源:Zab1_0Test.java
注:本文中的org.apache.zookeeper.server.ByteBufferOutputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论