gpt4 book ai didi

com.spotify.helios.ZooKeeperTestingClusterManager类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 02:05:31 26 4
gpt4 key购买 nike

本文整理了Java中com.spotify.helios.ZooKeeperTestingClusterManager类的一些代码示例,展示了ZooKeeperTestingClusterManager类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperTestingClusterManager类的具体详情如下:
包路径:com.spotify.helios.ZooKeeperTestingClusterManager
类名称:ZooKeeperTestingClusterManager

ZooKeeperTestingClusterManager介绍

[英]A ZooKeeperTestManager that uses the org.apache.curator.test.TestingServerto run an in-process ZooKeeper cluster.
[中]使用组织的ZooKeeperTestManager。阿帕奇。馆长测验正在测试服务器以运行进程内ZooKeeper群集。

代码示例

代码示例来源:origin: spotify/helios

@Override
public void start() {
 try {
  start0();
 } catch (Exception e) {
  Throwables.throwIfUnchecked(e);
  throw new RuntimeException(e);
 }
 curator = createCurator(connectString(zkAddresses));
 try {
  awaitUp(2, TimeUnit.MINUTES);
 } catch (TimeoutException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: spotify/helios

private void start0() {
 zkPeers = createPeers(3);
 zkAddresses = allocateAddresses(zkPeers);
 peerCurators = createCurators(zkAddresses);
 System.setProperty("zookeeper.jmx.log4j.disable", "true");
 cluster = new TestingCluster(zkPeers);
 zkServers = cluster.getServers();
 try {
  cluster.start();
 } catch (Exception e) {
  stop();
  Throwables.throwIfUnchecked(e);
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: spotify/helios

@Test
public void verifyZooKeeperRecoversWithTwoPeersAlive() throws Exception {
 zk.stopPeer(0);
 zk.stopPeer(1);
 zk.awaitDown(5, MINUTES);
 zk.resetPeer(0);
 zk.startPeer(0);
 zk.awaitUp(5, MINUTES);
 try {
  zk.curatorWithSuperAuth().create().forPath(FOO, FOO_DATA);
  assertArrayEquals(FOO_DATA, zk.curatorWithSuperAuth().getData().forPath(FOO));
 } catch (KeeperException.NodeExistsException ignore) {
  // ignored
 }
}

代码示例来源:origin: spotify/helios

private List<CuratorFramework> createCurators(final List<InetSocketAddress> addresses) {
 final ImmutableList.Builder<CuratorFramework> curators = ImmutableList.builder();
 for (final InetSocketAddress address : addresses) {
  curators.add(createCurator(connectString(address)));
 }
 return curators.build();
}

代码示例来源:origin: spotify/helios

@Test
public void verifyZooKeeperToleratesOneNodeDataLoss() throws Exception {
 try {
  zk.curatorWithSuperAuth().create().forPath(FOO, FOO_DATA);
  assertArrayEquals(FOO_DATA, zk.curatorWithSuperAuth().getData().forPath(FOO));
 } catch (KeeperException.NodeExistsException ignore) {
  // ignored
 }
 zk.stopPeer(0);
 zk.resetPeer(0);
 zk.startPeer(0);
 zk.stopPeer(1);
 assertArrayEquals(FOO_DATA, zk.curatorWithSuperAuth().getData().forPath(FOO));
}

代码示例来源:origin: spotify/helios

@Override
 public String connectString() {
  return super.connectString() + ",node-that-doesnt-exist:1738";
 }
};

代码示例来源:origin: spotify/helios

@Test
public void verifyCanNotCreateNodesWithTwoPeersDead() throws Exception {
 zk.stopPeer(0);
 zk.stopPeer(1);
 zk.awaitDown(5, MINUTES);
 expectedException.expect(KeeperException.ConnectionLossException.class);
 zk.curatorWithSuperAuth().create().forPath(FOO, FOO_DATA);
}

代码示例来源:origin: spotify/helios

public void resetPeer(final int id) {
 if (zkServers.get(id).getQuorumPeer().isRunning()) {
  throw new IllegalStateException("peer is still running: " + id);
 }
 final Path peerDir = peerDir(id);
 try {
  // Wipe and recreate the data directory
  FileUtils.deleteDirectory(peerDir.toFile());
  Files.createDirectory(peerDir);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: spotify/helios

@Override
 public Object call() throws Exception {
  try {
   return curatorWithSuperAuth().getChildren().forPath("/");
  } catch (Exception e) {
   return null;
  }
 }
});

代码示例来源:origin: spotify/helios

public ZooKeeperTestingClusterManager() {
 try {
  tempDir = Files.createTempDirectory("helios-zk");
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 start();
}

代码示例来源:origin: spotify/helios

private String connectString(final Iterable<InetSocketAddress> addresses) {
 return Joiner.on(',').join(endpoints(addresses));
}

代码示例来源:origin: at.molindo/helios-testing-common

private List<CuratorFramework> createCurators(final List<InetSocketAddress> addresses) {
 final ImmutableList.Builder<CuratorFramework> curators = ImmutableList.builder();
 for (InetSocketAddress address : addresses) {
  curators.add(createCurator(connectString(address)));
 }
 return curators.build();
}

代码示例来源:origin: spotify/helios

@Test
public void verifyCanDeployWithOneNodeDeadAfterOneNodeDataLoss() throws Exception {
 // First deploy a job
 deploy(fooJob);
 // Create a node that we know is written after the job
 try {
  zkc.curatorWithSuperAuth().create().forPath("/barrier");
 } catch (NodeExistsException ignore) {
  // ignored
 }
 // Wipe one zk peer
 zkc.stopPeer(0);
 zkc.resetPeer(0);
 zkc.startPeer(0);
 // Wait for the zk peer to recover
 Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() {
  @Override
  public Object call() throws Exception {
   return zkc.peerCurator(0).checkExists().forPath("/barrier");
  }
 });
 // Then take down another peer
 zkc.stopPeer(1);
 // Now verify that we can still undeploy and deploy jobs
 undeploy(fooJob.getId());
 deploy(barJob);
}

代码示例来源:origin: spotify/helios

@Override
public String connectString() {
 return connectString(zkAddresses);
}

代码示例来源:origin: spotify/helios

private List<InstanceSpec> createPeers(final int numPeers) {
 final ImmutableList.Builder<InstanceSpec> peers = ImmutableList.builder();
 for (int i = 0; i < numPeers; i++) {
  final int port = temporaryPorts.localPort("zk-client" + i);
  final int electionPort = temporaryPorts.localPort("zk-elect" + i);
  final int quorumPort = temporaryPorts.localPort("zk-quorum" + i);
  final Path peerDir = peerDir(i);
  try {
   Files.createDirectory(peerDir);
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
  final InstanceSpec spec = new InstanceSpec(
    peerDir.toFile(),
    port,
    electionPort,
    quorumPort,
    true,
    i);
  peers.add(spec);
 }
 return peers.build();
}

代码示例来源:origin: spotify/helios

@Override
 public Object call() throws Exception {
  try {
   curatorWithSuperAuth().getChildren().forPath("/");
   return null;
  } catch (KeeperException.ConnectionLossException e) {
   return true;
  } catch (Exception e) {
   return null;
  }
 }
});

代码示例来源:origin: at.molindo/helios-testing-common

public ZooKeeperTestingClusterManager() {
 try {
  tempDir = Files.createTempDirectory("helios-zk");
 } catch (IOException e) {
  throw Throwables.propagate(e);
 }
 start();
}

代码示例来源:origin: at.molindo/helios-testing-common

private String connectString(final Iterable<InetSocketAddress> addresses) {
 return Joiner.on(',').join(endpoints(addresses));
}

代码示例来源:origin: at.molindo/helios-testing-common

@Override
public void start() {
 try {
  start0();
 } catch (Exception e) {
  throw Throwables.propagate(e);
 }
 curator = createCurator(connectString(zkAddresses));
 try {
  awaitUp(2, TimeUnit.MINUTES);
 } catch (TimeoutException e) {
  throw Throwables.propagate(e);
 }
}

代码示例来源:origin: spotify/helios

@Test
public void verifyCanCreateNodesWithOnePeerDead() throws Exception {
 // Kill two peers and bring one up to ensure that only two out of three peers are alive
 zk.stopPeer(0);
 zk.stopPeer(1);
 zk.awaitDown(5, MINUTES);
 zk.startPeer(1);
 zk.awaitUp(5, MINUTES);
 try {
  zk.curatorWithSuperAuth().create().forPath(FOO, FOO_DATA);
  assertArrayEquals(FOO_DATA, zk.curatorWithSuperAuth().getData().forPath(FOO));
 } catch (KeeperException.NodeExistsException ignore) {
  // ignored
 }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com