當前位置: 首頁>>代碼示例>>Java>>正文


Java Ids類代碼示例

本文整理匯總了Java中org.apache.zookeeper.ZooDefs.Ids的典型用法代碼示例。如果您正苦於以下問題:Java Ids類的具體用法?Java Ids怎麽用?Java Ids使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ids類屬於org.apache.zookeeper.ZooDefs包,在下文中一共展示了Ids類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testChRootCreateDelete

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testChRootCreateDelete() throws Exception {
    // creating the subtree for chRoot clients.
    String chRoot = createNameSpace();
    // Creating child using chRoot client.
    zk_chroot = createClient(this.hostPort + chRoot);
    Op createChild = Op.create("/myid", new byte[0],
            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    multi(zk_chroot, Arrays.asList(createChild));
    
    Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk
            .exists(chRoot + "/myid", false));
    Assert.assertNotNull("zNode is not created under chroot:" + chRoot,
            zk_chroot.exists("/myid", false));
    Assert.assertNull("zNode is created directly under '/', ignored configured chroot",
            zk.exists("/myid", false));
    
    // Deleting child using chRoot client.
    Op deleteChild = Op.delete("/myid", 0);
    multi(zk_chroot, Arrays.asList(deleteChild));
    Assert.assertNull("zNode exists under chroot:" + chRoot, zk.exists(
            chRoot + "/myid", false));
    Assert.assertNull("zNode exists under chroot:" + chRoot, zk_chroot
            .exists("/myid", false));
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:26,代碼來源:MultiTransactionTest.java

示例2: setUp

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
    String hp = hostPort;
    hostPort = hostPort + "/chrootasynctest";

    super.setUp();

    LOG.info("Creating client " + getTestName());

    ZooKeeper zk = createClient(hp);
    try {
        zk.create("/chrootasynctest", null, Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    } finally {
        zk.close();
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:18,代碼來源:ChrootAsyncTest.java

示例3: testGetPreviousRecoveryMode

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Ignore("DLR is broken by HBASE-12751") @Test(timeout=60000)
public void testGetPreviousRecoveryMode() throws Exception {
  LOG.info("testGetPreviousRecoveryMode");
  SplitLogCounters.resetCounters();
  // Not actually enabling DLR for the cluster, just for the ZkCoordinatedStateManager to use.
  // The test is just manipulating ZK manually anyways.
  conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, true);

  zkw.getRecoverableZooKeeper().create(ZKSplitLog.getEncodedNodeName(zkw, "testRecovery"),
    new SplitLogTask.Unassigned(
      ServerName.valueOf("mgr,1,1"), RecoveryMode.LOG_SPLITTING).toByteArray(),
      Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

  slm = new SplitLogManager(ds, conf, stopper, master, DUMMY_MASTER);
  LOG.info("Mode1=" + slm.getRecoveryMode());
  assertTrue(slm.isLogSplitting());
  zkw.getRecoverableZooKeeper().delete(ZKSplitLog.getEncodedNodeName(zkw, "testRecovery"), -1);
  LOG.info("Mode2=" + slm.getRecoveryMode());
  slm.setRecoveryMode(false);
  LOG.info("Mode3=" + slm.getRecoveryMode());
  assertTrue("Mode4=" + slm.getRecoveryMode(), slm.isLogReplaying());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:TestSplitLogManager.java

示例4: testSaslNotRequiredWithInvalidCredentials

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
/**
 * Test to verify that server is able to start with invalid credentials if
 * the configuration is set to quorum.auth.serverRequireSasl=false.
 * Quorum will talk each other even if the authentication is not succeeded
 */
@Test(timeout = 30000)
public void testSaslNotRequiredWithInvalidCredentials() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearnerInvalid");
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
    String connectStr = startQuorum(3, authConfigs, 3, false);
    CountdownWatcher watcher = new CountdownWatcher();
    zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    for (int i = 0; i < 10; i++) {
        zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:21,代碼來源:QuorumDigestAuthTest.java

示例5: run

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
public void run() {
    byte b[] = new byte[256];
    try {
        for (; current < count; current++) {
            // Simulate a bit of network latency...
            Thread.sleep(HAMMERTHREAD_LATENCY);
            zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } catch (Throwable t) {
        LOG.error("Client create operation Assert.failed", t);
    } finally {
        try {
            zk.close();
        } catch (InterruptedException e) {
            LOG.warn("Unexpected", e);
        }
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:19,代碼來源:ClientHammerTest.java

示例6: testNoWatchesTriggeredForFailedMultiRequest

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testNoWatchesTriggeredForFailedMultiRequest() throws InterruptedException, KeeperException {
    HasTriggeredWatcher watcher = new HasTriggeredWatcher();
    zk.getChildren("/", watcher);
    try {
        multi(zk, Arrays.asList(
                Op.create("/t", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
                Op.delete("/nonexisting", -1)
        ));
        fail("expected previous multi op to fail!");
    } catch (KeeperException.NoNodeException e) {
        // expected
    }
    SyncCallback cb = new SyncCallback();
    zk.sync("/", cb, null);

    // by waiting for the callback we're assured that the event queue is flushed
    cb.done.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
    assertEquals(1, watcher.triggered.getCount());
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:21,代碼來源:MultiTransactionTest.java

示例7: testChRootSetData

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testChRootSetData() throws Exception {
    // creating the subtree for chRoot clients.
    String chRoot = createNameSpace();
    // setData using chRoot client.
    zk_chroot = createClient(this.hostPort + chRoot);
    String[] names = {"/multi0", "/multi1", "/multi2"};
    List<Op> ops = new ArrayList<Op>();

    for (int i = 0; i < names.length; i++) {
        ops.add(Op.create(names[i], new byte[0], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT));
        ops.add(Op.setData(names[i], names[i].getBytes(), 0));
    }

    multi(zk_chroot, ops) ;

    for (int i = 0; i < names.length; i++) {
        Assert.assertArrayEquals("zNode data not matching", names[i]
                .getBytes(), zk_chroot.getData(names[i], false, null));
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:23,代碼來源:MultiTransactionTest.java

示例8: rescan

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
/**
 * signal the workers that a task was resubmitted by creating the RESCAN node.
 */
private void rescan(long retries) {
  // The RESCAN node will be deleted almost immediately by the
  // SplitLogManager as soon as it is created because it is being
  // created in the DONE state. This behavior prevents a buildup
  // of RESCAN nodes. But there is also a chance that a SplitLogWorker
  // might miss the watch-trigger that creation of RESCAN node provides.
  // Since the TimeoutMonitor will keep resubmitting UNASSIGNED tasks
  // therefore this behavior is safe.
  SplitLogTask slt = new SplitLogTask.Done(this.details.getServerName(), getRecoveryMode());
  this.watcher
      .getRecoverableZooKeeper()
      .getZooKeeper()
      .create(ZKSplitLog.getRescanNode(watcher), slt.toByteArray(), Ids.OPEN_ACL_UNSAFE,
        CreateMode.EPHEMERAL_SEQUENTIAL, new CreateRescanAsyncCallback(), Long.valueOf(retries));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:ZKSplitLogManagerCoordination.java

示例9: testMultiRollbackNoLastChange

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
/**
 * ZOOKEEPER-2052:
 * This test checks that if a multi operation aborted, and during the multi there is side effect
 * that changed outstandingChangesForPath, after aborted the side effect should be removed and
 * everything should be restored correctly.
 */
@Test
public void testMultiRollbackNoLastChange() throws Exception {
    zks.getZKDatabase().dataTree.createNode("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0);
    zks.getZKDatabase().dataTree.createNode("/foo/bar", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0);

    Assert.assertNull(zks.outstandingChangesForPath.get("/foo"));

    // multi record:
    //   set "/foo" => succeed, leave a outstanding change
    //   delete "/foo" => fail, roll back change
    process(Arrays.asList(
            Op.setData("/foo", new byte[0], -1),
            Op.delete("/foo", -1)));

    // aborting multi shouldn't leave any record.
    Assert.assertNull(zks.outstandingChangesForPath.get("/foo"));
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:24,代碼來源:PrepRequestProcessorTest.java

示例10: testRemoveNodeDataChangedWatches

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
/**
 * Test verifies deletion of NodeDataChanged watches
 */
@Test(timeout = 30000)
public void testRemoveNodeDataChangedWatches() throws Exception {
    LOG.info("Adding data watcher using getData()");
    List<EventType> expectedEvents = new ArrayList<Watcher.Event.EventType>();
    expectedEvents.add(EventType.DataWatchRemoved);
    MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1);

    zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk.getData("/testnode1", myWatcher, null);

    String cmdstring = "removewatches /testnode1 -d";
    LOG.info("Remove watchers using shell command : {}", cmdstring);
    zkMain.cl.parseCommand(cmdstring);
    Assert.assertTrue("Removewatches cmd fails to remove data watches",
            zkMain.processZKCmd(zkMain.cl));

    LOG.info("Waiting for the DataWatchRemoved event");
    myWatcher.matches();

    // verifying that other path data watches are removed
    Assert.assertEquals(
            "Data watches are not removed : " + zk.getDataWatches(), 0, zk
                    .getDataWatches().size());
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:29,代碼來源:RemoveWatchesCmdTest.java

示例11: testQuitElectionRemovesBreadcrumbNode

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testQuitElectionRemovesBreadcrumbNode() throws Exception {
  mockNoPriorActive();
  elector.joinElection(data);
  elector.processResult(Code.OK.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  // Writes its own active info
  Mockito.verify(mockZK, Mockito.times(1)).create(
      Mockito.eq(ZK_BREADCRUMB_NAME), Mockito.eq(data),
      Mockito.eq(Ids.OPEN_ACL_UNSAFE),
      Mockito.eq(CreateMode.PERSISTENT));
  mockPriorActive(data);
  
  elector.quitElection(false);
  
  // Deletes its own active data
  Mockito.verify(mockZK, Mockito.times(1)).delete(
      Mockito.eq(ZK_BREADCRUMB_NAME), Mockito.eq(0));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestActiveStandbyElector.java

示例12: testLargeNodeData

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testLargeNodeData() throws Exception {
    ZooKeeper zk= null;
    String queue_handle = "/large";
    try {
        zk = createClient();

        zk.create(queue_handle, new byte[500000], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    } finally {
        if (zk != null) {
            zk.close();
        }
    }

}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:17,代碼來源:ClientTest.java

示例13: testNestedCreate

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
@Test
public void testNestedCreate() throws Exception {

    multi(zk, Arrays.asList(
            /* Create */
            Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
            Op.create("/multi/a", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
            Op.create("/multi/a/1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),

            /* Delete */
            Op.delete("/multi/a/1", 0),
            Op.delete("/multi/a", 0),
            Op.delete("/multi", 0)
            ));

    //Verify tree deleted
    Assert.assertNull(zk.exists("/multi/a/1", null));
    Assert.assertNull(zk.exists("/multi/a", null));
    Assert.assertNull(zk.exists("/multi", null));
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:21,代碼來源:MultiTransactionTest.java

示例14: testCreateNodeResultRetryNoNode

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
/**
 * verify that if create znode results in nodeexists and that znode is deleted
 * before exists() watch is set then the return of the exists() method results
 * in attempt to re-create the znode and become active
 */
@Test
public void testCreateNodeResultRetryNoNode() {
  elector.joinElection(data);

  elector.processResult(Code.CONNECTIONLOSS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  elector.processResult(Code.CONNECTIONLOSS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  elector.processResult(Code.NODEEXISTS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  verifyExistCall(1);

  elector.processResult(Code.NONODE.intValue(), ZK_LOCK_NAME, mockZK,
      (Stat) null);
  Mockito.verify(mockApp, Mockito.times(1)).enterNeutralMode();
  Mockito.verify(mockZK, Mockito.times(4)).create(ZK_LOCK_NAME, data,
      Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, elector, mockZK);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestActiveStandbyElector.java

示例15: createNode

import org.apache.zookeeper.ZooDefs.Ids; //導入依賴的package包/類
public boolean createNode(String parent, String nodeName) {
    if (connected) {
        try {
            String[] nodeElements = nodeName.split("/");
            for (String nodeElement : nodeElements) {
                String node = parent + "/" + nodeElement;
                Stat s = zooKeeper.exists(node, false);
                if (s == null) {
                    zooKeeper.create(node, this.encryptionManager
                            .encryptData(null), Ids.OPEN_ACL_UNSAFE,
                            CreateMode.PERSISTENT);
                    parent = node;
                }
            }
            return true;
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occurred creating node: " + parent + "/"
                            + nodeName, e);
        }
    }
    return false;
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:24,代碼來源:ZooInspectorManagerImpl.java


注:本文中的org.apache.zookeeper.ZooDefs.Ids類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。