当前位置: 首页>>代码示例>>Java>>正文


Java CreateTxn.serialize方法代码示例

本文整理汇总了Java中org.apache.zookeeper.txn.CreateTxn.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java CreateTxn.serialize方法的具体用法?Java CreateTxn.serialize怎么用?Java CreateTxn.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.txn.CreateTxn的用法示例。


在下文中一共展示了CreateTxn.serialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: syncTest

import org.apache.zookeeper.txn.CreateTxn; //导入方法依赖的package包/类
@Test
public void syncTest() throws Exception {
	File tmpFile = File.createTempFile("test", ".dir", testData);
	tmpFile.delete();
	try {
		FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
		SimpleLearner sl = new SimpleLearner(ftsl);
		long startZxid = sl.zk.getLastProcessedZxid();
		
		// Set up bogus streams
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
		sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
		
		// make streams and socket do something innocuous
		sl.bufferedOutput = new BufferedOutputStream(System.out);
		sl.sock = new Socket();
		
		// fake messages from the server
		QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
		oa.writeRecord(qp, null);
		sl.zk.getZKDatabase().serializeSnapshot(oa);
		oa.writeString("BenWasHere", "signature");
		TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
		CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
        ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
        hdr.serialize(boa, "hdr");
        txn.serialize(boa, "txn");
        tbaos.close();
		qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
		oa.writeRecord(qp, null);

		// setup the messages to be streamed to follower
		sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
		
		try {
			sl.syncWithLeader(3);
		} catch(EOFException e) {}
		
		sl.zk.shutdown();
		sl = new SimpleLearner(ftsl);
		Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
	} finally {
		recursiveDelete(tmpFile);
	}
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:48,代码来源:LearnerTest.java

示例2: syncTest

import org.apache.zookeeper.txn.CreateTxn; //导入方法依赖的package包/类
@Test
public void syncTest() throws Exception {
    File tmpFile = File.createTempFile("test", ".dir", testData);
    tmpFile.delete();
    try {
        FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
        SimpleLearner sl = new SimpleLearner(ftsl);
        long startZxid = sl.zk.getLastProcessedZxid();

        // Set up bogus streams
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
        sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());

        // make streams and socket do something innocuous
        sl.bufferedOutput = new BufferedOutputStream(System.out);
        sl.sock = new Socket();

        // fake messages from the server
        QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
        oa.writeRecord(qp, null);
        sl.zk.getZKDatabase().serializeSnapshot(oa);
        oa.writeString("BenWasHere", "signature");
        TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
        CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
        ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
        hdr.serialize(boa, "hdr");
        txn.serialize(boa, "txn");
        tbaos.close();
        qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
        oa.writeRecord(qp, null);

        // setup the messages to be streamed to follower
        sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));

        try {
            sl.syncWithLeader(3);
        } catch (EOFException e) {}

        sl.zk.shutdown();
        sl = new SimpleLearner(ftsl);
        Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
    } finally {
        TestUtils.deleteFileRecursively(tmpFile);
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:48,代码来源:LearnerTest.java

示例3: syncTest

import org.apache.zookeeper.txn.CreateTxn; //导入方法依赖的package包/类
@Test
public void syncTest() throws Exception {
	File tmpFile = File.createTempFile("test", ".dir");
	tmpFile.delete();
	try {
		FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
		SimpleLearner sl = new SimpleLearner(ftsl);
		long startZxid = sl.zk.getLastProcessedZxid();
		
		// Set up bogus streams
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
		sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
		
		// make streams and socket do something innocuous
		sl.bufferedOutput = new BufferedOutputStream(System.out);
		sl.sock = new Socket();
		
		// fake messages from the server
		QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
		oa.writeRecord(qp, null);
		sl.zk.getZKDatabase().serializeSnapshot(oa);
		oa.writeString("BenWasHere", "signature");
		TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
		CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
        ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
        hdr.serialize(boa, "hdr");
        txn.serialize(boa, "txn");
        tbaos.close();
		qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
		oa.writeRecord(qp, null);

		// setup the messages to be streamed to follower
		sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
		
		try {
			sl.syncWithLeader(3);
		} catch(EOFException e) {}
		
		sl.zk.shutdown();
		sl = new SimpleLearner(ftsl);
		Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
	} finally {
		recursiveDelete(tmpFile);
	}
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:48,代码来源:LearnerTest.java

示例4: syncTest

import org.apache.zookeeper.txn.CreateTxn; //导入方法依赖的package包/类
@Test
public void syncTest() throws Exception {
    File tmpFile = File.createTempFile("test", ".dir", testData);
    tmpFile.delete();
    try {
        FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
        SimpleLearner sl = new SimpleLearner(ftsl);
        long startZxid = sl.zk.getLastProcessedZxid();

        // Set up bogus streams
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
        sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());

        // make streams and socket do something innocuous
        sl.bufferedOutput = new BufferedOutputStream(System.out);
        sl.sock = new Socket();

        // fake messages from the server
        QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
        oa.writeRecord(qp, null);
        sl.zk.getZKDatabase().serializeSnapshot(oa);
        oa.writeString("BenWasHere", "signature");
        TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
        CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
        ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
        hdr.serialize(boa, "hdr");
        txn.serialize(boa, "txn");
        tbaos.close();
        qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
        oa.writeRecord(qp, null);

        // setup the messages to be streamed to follower
        sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));

        try {
            sl.syncWithLeader(3);
        } catch (EOFException e) {}

        sl.zk.shutdown();
        sl = new SimpleLearner(ftsl);
        Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
    } finally {
        recursiveDelete(tmpFile);
    }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:48,代码来源:LearnerTest.java


注:本文中的org.apache.zookeeper.txn.CreateTxn.serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。