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


Java ZKDatabase.processTxn方法代码示例

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


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

示例1: testPopulatedLeaderConversation

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
public void testPopulatedLeaderConversation(PopulatedLeaderConversation conversation, int ops) throws Exception {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {              
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);
        
        Assert.assertTrue(ops >= 1);
        long zxid = ZxidUtils.makeZxid(1, 0);            
        for(int i = 1; i <= ops; i++){
            zxid = ZxidUtils.makeZxid(1, i);
            String path = "/foo-"+ i;
            zkDb.processTxn(new TxnHeader(13,1000+i,zxid,30+i,ZooDefs.OpCode.create), 
                                            new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
            Stat stat = new Stat();
            Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));
        }                
        Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0));
        
        // Generate snapshot and close files.
        snapLog.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts());
        snapLog.close();
        
        QuorumPeer peer = createQuorumPeer(tmpDir);
                    
        leader = createLeader(tmpDir, peer);
        peer.leader = leader;
        
        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(1);
        peer.setCurrentEpoch(1);

        
        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }
        
        LearnerHandler lh = new LearnerHandler(leaderSocket, leader);
        lh.start();
        leaderSocket.setSoTimeout(4000);

        InputArchive ia = BinaryInputArchive.getArchive(followerSocket
                .getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket
                .getOutputStream());

        conversation.converseWithLeader(ia, oa, leader, zxid);
    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:69,代码来源:Zab1_0Test.java

示例2: testDirtySnapshot

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
/**
 * verify that a peer with dirty snapshot joining an established cluster
 * does not go into an inconsistent state.
 *
 * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1558}
 */
@Test
public void testDirtySnapshot()
throws IOException,
    InterruptedException,
    KeeperException,
    NoSuchFieldException,
    IllegalAccessException {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir");
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);

        long zxid = ZxidUtils.makeZxid(0, 1);
        String path = "/foo";
        zkDb.processTxn(new TxnHeader(13,1000,zxid,30,ZooDefs.OpCode.create),
                                        new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
        Stat stat = new Stat();
        Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));

        // Close files
        snapLog.close();

        QuorumPeer peer = createQuorumPeer(tmpDir);

        leader = createLeader(tmpDir, peer);
        peer.leader = leader;

        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(0);
        peer.setCurrentEpoch(0);

        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }

        leader.shutdown("Shutting down the leader");

        // Check if there is a valid snapshot (we better not have it)
        File snapDir = new File (tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
        List<File> files = Util.sortDataDir(snapDir.listFiles(),"snapshot", false);

        for (File f : files) {
            try {
                Assert.assertFalse("Found a valid snapshot", Util.isValidSnapshot(f));
            } catch (IOException e) {
                LOG.info("invalid snapshot " + f, e);
            }
        }

    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:78,代码来源:Zab1_0Test.java

示例3: testPopulatedLeaderConversation

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
public void testPopulatedLeaderConversation(PopulatedLeaderConversation conversation, int ops) throws Exception {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {              
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);
        
        Assert.assertTrue(ops >= 1);
        long zxid = ZxidUtils.makeZxid(1, 0);            
        for(int i = 1; i <= ops; i++){
            zxid = ZxidUtils.makeZxid(1, i);
            String path = "/foo-"+ i;
            zkDb.processTxn(new TxnHeader(13,1000+i,zxid,30+i,ZooDefs.OpCode.create), 
                                            new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
            Stat stat = new Stat();
            Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));
        }                
        Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0));
        
        // Generate snapshot and close files.
        snapLog.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts(), false);
        snapLog.close();
        
        QuorumPeer peer = createQuorumPeer(tmpDir);
                    
        leader = createLeader(tmpDir, peer);
        peer.leader = leader;
        
        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(1);
        peer.setCurrentEpoch(1);

        
        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }
        
        LearnerHandler lh = new LearnerHandler(leaderSocket, leader);
        lh.start();
        leaderSocket.setSoTimeout(4000);

        InputArchive ia = BinaryInputArchive.getArchive(followerSocket
                .getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket
                .getOutputStream());

        conversation.converseWithLeader(ia, oa, leader, zxid);
    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        TestUtils.deleteFileRecursively(tmpDir);
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:69,代码来源:Zab1_0Test.java

示例4: testPopulatedLeaderConversation

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
public void testPopulatedLeaderConversation(PopulatedLeaderConversation conversation, int ops) throws Exception {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {              
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);
        
        Assert.assertTrue(ops >= 1);
        long zxid = ZxidUtils.makeZxid(1, 0);            
        for(int i = 1; i <= ops; i++){
            zxid = ZxidUtils.makeZxid(1, i);
            String path = "/foo-"+ i;
            zkDb.processTxn(new TxnHeader(13,1000+i,zxid,30+i,ZooDefs.OpCode.create), 
                                            new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
            Stat stat = new Stat();
            Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));
        }                
        Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0));
        
        // Generate snapshot and close files.
        snapLog.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts());
        snapLog.close();
        
        QuorumPeer peer = createQuorumPeer(tmpDir);
                    
        leader = createLeader(tmpDir, peer);
        peer.leader = leader;
        
        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(1);
        peer.setCurrentEpoch(1);

        
        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }

        LearnerHandler lh = new LearnerHandler(leaderSocket,
                new BufferedInputStream(leaderSocket.getInputStream()),
                leader);
        lh.start();
        leaderSocket.setSoTimeout(4000);

        InputArchive ia = BinaryInputArchive.getArchive(followerSocket
                .getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket
                .getOutputStream());

        conversation.converseWithLeader(ia, oa, leader, zxid);
    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:71,代码来源:Zab1_0Test.java

示例5: testPopulatedLeaderConversation

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
public void testPopulatedLeaderConversation(PopulatedLeaderConversation conversation, int ops) throws Exception {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir");
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {              
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);
        
        Assert.assertTrue(ops >= 1);
        long zxid = ZxidUtils.makeZxid(1, 0);            
        for(int i = 1; i <= ops; i++){
            zxid = ZxidUtils.makeZxid(1, i);
            String path = "/foo-"+ i;
            zkDb.processTxn(new TxnHeader(13,1000+i,zxid,30+i,ZooDefs.OpCode.create), 
                                            new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
            Stat stat = new Stat();
            Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));
        }                
        Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0));
        
        // Generate snapshot and close files.
        snapLog.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts());
        snapLog.close();
        
        QuorumPeer peer = createQuorumPeer(tmpDir);
                    
        leader = createLeader(tmpDir, peer);
        peer.leader = leader;
        
        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(1);
        peer.setCurrentEpoch(1);

        
        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }
        
        LearnerHandler lh = new LearnerHandler(leaderSocket, leader);
        lh.start();
        leaderSocket.setSoTimeout(4000);

        InputArchive ia = BinaryInputArchive.getArchive(followerSocket
                .getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket
                .getOutputStream());

        conversation.converseWithLeader(ia, oa, leader, zxid);
    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:69,代码来源:Zab1_0Test.java


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