本文整理汇总了Java中org.apache.zookeeper.PortAssignment类的典型用法代码示例。如果您正苦于以下问题:Java PortAssignment类的具体用法?Java PortAssignment怎么用?Java PortAssignment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PortAssignment类属于org.apache.zookeeper包,在下文中一共展示了PortAssignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LaunchServers
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* This is a helper function for launching a set of servers
*
* @param numServers
* @return
* @throws IOException
* @throws InterruptedException
*/
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
int SERVER_COUNT = numServers;
Servers svrs = new Servers();
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
for(int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
for(int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
mt[i].start();
zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
waitForAll(zk, States.CONNECTED);
svrs.mt = mt;
svrs.zk = zk;
return svrs;
}
示例2: setUp
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0",
peerQuorumPort[i],
PortAssignment.unique(), null));
peerTmpdir[i] = ClientBase.createTmpDir();
}
}
示例3: testObserverWithStandlone
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* Ensure that observer only comes up when a proper ensemble is configured.
* (and will not come up with standalone server).
*/
@Test
public void testObserverWithStandlone() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT_QP1 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + (PortAssignment.unique())
+ ":" + (PortAssignment.unique()) + ":observer\n"
+ "server.2=127.0.0.1:" + (PortAssignment.unique())
+ ":" + (PortAssignment.unique()) + "\npeerType=observer\n";
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
q1.join(ClientBase.CONNECTION_TIMEOUT);
Assert.assertFalse(q1.isAlive());
}
示例4: testStandaloneQuorum
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* Ensure that a single standalone server comes up when misconfigured
* with a single server.# line in the configuration. This handles the
* case of HBase, which configures zoo.cfg in this way. Maintain b/w
* compatibility.
* TODO remove in a future version (4.0.0 hopefully)
*/
@Test
public void testStandaloneQuorum() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT_QP1 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + (PortAssignment.unique())
+ ":" + (PortAssignment.unique()) + "\n";
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
try {
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
} finally {
q1.shutdown();
}
}
示例5: LaunchServers
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* This is a helper function for launching a set of servers
*
* @param numServers
* @return
* @throws IOException
* @throws InterruptedException
*/
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
int SERVER_COUNT = numServers;
Servers svrs = new Servers();
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+";"+clientPorts[i]+"\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
for (int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
mt[i].start();
zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
waitForAll(zk, States.CONNECTED);
svrs.mt = mt;
svrs.zk = zk;
return svrs;
}
示例6: testStandalone
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* Starts a standalone server and tests that we can query its AdminServer.
*/
@Test
public void testStandalone() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
ZooKeeperServerMainTest.MainThread main = new ZooKeeperServerMainTest.MainThread(CLIENT_PORT, false, null);
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
queryAdminServer(jettyAdminPort);
main.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
}
示例7: testWithMinSessionTimeoutGreaterThanMaxSessionTimeout
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* Test verifies that the server shouldn't allow minsessiontimeout >
* maxsessiontimeout
*/
@Test
public void testWithMinSessionTimeoutGreaterThanMaxSessionTimeout()
throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
final int tickTime = 2000;
final int minSessionTimeout = 20 * tickTime + 1000; // min is higher
final int maxSessionTimeout = tickTime * 2 - 100; // max is lower
final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n"
+ "minSessionTimeout=" + minSessionTimeout + "\n";
MainThread main = new MainThread(CLIENT_PORT, true, configs);
String args[] = new String[1];
args[0] = main.confFile.toString();
try {
main.main.initializeAndRun(args);
Assert.fail("Must throw exception as "
+ "minsessiontimeout > maxsessiontimeout");
} catch (ConfigException iae) {
// expected
}
}
示例8: setUp
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
peers.put(Long.valueOf(i),
new QuorumServer(i,
new InetSocketAddress(
"127.0.0.1", peerQuorumPort[i]),
new InetSocketAddress(
"127.0.0.1", PortAssignment.unique()),
new InetSocketAddress(
"127.0.0.1", peerClientPort[i])));
peerTmpdir[i] = ClientBase.createTmpDir();
}
}
示例9: setUp
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
String testDataPath = System.getProperty("test.data.dir", "build/test/data");
System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
System.setProperty(ZKConfig.SSL_AUTHPROVIDER, "x509");
System.setProperty(ZKConfig.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testKeyStore.jks");
System.setProperty(ZKConfig.SSL_KEYSTORE_PASSWD, "testpass");
System.setProperty(ZKConfig.SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/testTrustStore.jks");
System.setProperty(ZKConfig.SSL_TRUSTSTORE_PASSWD, "testpass");
System.setProperty("javax.net.debug", "ssl");
System.setProperty("zookeeper.authProvider.x509", "org.apache.zookeeper.server.auth.X509AuthenticationProvider");
String host = "localhost";
int port = PortAssignment.unique();
hostPort = host + ":" + port;
serverFactory = ServerCnxnFactory.createFactory();
serverFactory.configure(new InetSocketAddress(host, port), maxCnxns, true);
super.setUp();
}
示例10: setUp
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerQuorumPort = new int[count];
peerClientPort = new int[count];
authzHosts = new HashSet<String>();
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
QuorumServer qs = new QuorumServer(i, "0.0.0.0",
peerQuorumPort[i], PortAssignment.unique(), null);
peers.put(Long.valueOf(i), qs);
authzHosts.add(qs.hostname);
}
executor = new ThreadPoolExecutor(3, 10,
60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}
示例11: testZeroWeightQuorum
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Test
public void testZeroWeightQuorum() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for(int i = 0; i < le.length; i++) {
QuorumHierarchical hq = new QuorumHierarchical(qp);
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq);
peer.startLeaderElection();
LEThread thread = new LEThread(peer, i);
thread.start();
threads.add(thread);
}
LOG.info("Started threads " + getTestName());
for(int i = 0; i < threads.size(); i++) {
threads.get(i).join(15000);
if (threads.get(i).isAlive()) {
Assert.fail("Threads didn't join");
} else {
if(threads.get(i).fail)
Assert.fail("Elected zero-weight server");
}
}
}
示例12: testAutoCreateDataLogDir
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
/**
* Test verifies the auto creation of data dir and data log dir.
*/
@Test(timeout = 30000)
public void testAutoCreateDataLogDir() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
MainThread main = new MainThread(CLIENT_PORT, false);
String args[] = new String[1];
args[0] = main.confFile.toString();
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT, this);
zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo", null, null)),
"foobar");
zk.close();
main.shutdown();
main.join();
main.deleteDirs();
Assert.assertTrue("waiting for server down", ClientBase
.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
}
示例13: testCnxManagerTimeout
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
@Test
public void testCnxManagerTimeout() throws Exception {
Random rand = new Random();
byte b = (byte) rand.nextInt();
int finalOctet = b & 0xFF;
int deadPort = PortAssignment.unique();
String deadAddress = new String("192.0.2." + finalOctet);
LOG.info("This is the dead address I'm trying: " + deadAddress);
peers.put(Long.valueOf(2),
new QuorumServer(2, deadAddress, deadPort, PortAssignment.unique(), null));
peerTmpdir[2] = ClientBase.createTmpDir();
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
if(listener != null){
listener.start();
} else {
LOG.error("Null listener when initializing cnx manager");
}
long begin = System.currentTimeMillis();
cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
long end = System.currentTimeMillis();
if((end - begin) > 6000) Assert.fail("Waited more than necessary");
}
示例14: populate
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
void populate()
throws Exception {
for (int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0",
PortAssignment.unique(),
PortAssignment.unique(), null));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
}
示例15: prepareLeader
import org.apache.zookeeper.PortAssignment; //导入依赖的package包/类
private LeaderZooKeeperServer prepareLeader(File tmpDir, QuorumPeer peer)
throws IOException, NoSuchFieldException, IllegalAccessException {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
peer.setTxnFactory(logFactory);
Field addrField = peer.getClass().getDeclaredField("myQuorumAddr");
addrField.setAccessible(true);
addrField.set(peer, new InetSocketAddress(PortAssignment.unique()));
ZKDatabase zkDb = new ZKDatabase(logFactory);
LeaderZooKeeperServer zk = new LeaderZooKeeperServer(logFactory, peer, new ZooKeeperServer.BasicDataTreeBuilder(), zkDb);
return zk;
}