@Test public void testCnxManagerTimeout() throws Exception { Random rand = new Random(); byte b = (byte) rand.nextInt(); int deadPort = PortAssignment.unique(); String deadAddress = new String("10.1.1." + b); LOG.info("This is the dead address I'm trying: " + deadAddress); peers.put( Long.valueOf(2), new QuorumServer( 2, new InetSocketAddress(deadAddress, deadPort), new InetSocketAddress(deadAddress, PortAssignment.unique()))); 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) fail("Waited more than necessary"); }
protected void setUp() throws Exception { LOG.info("STARTING " + getName()); setupTestEnv(); hostPort = "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184,127.0.0.1:2185"; s1dir = ClientBase.createTmpDir(); s2dir = ClientBase.createTmpDir(); s3dir = ClientBase.createTmpDir(); s4dir = ClientBase.createTmpDir(); s5dir = ClientBase.createTmpDir(); startServers(); LOG.info("Setup finished"); }
@Before public void setUp() throws Exception { if (tmpDir == null) { tmpDir = ClientBase.createTmpDir(); } ClientBase.setupTestEnv(); ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); serverFactory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT)); serverFactory.startup(zs); Assert.assertTrue( "waiting for server up", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); }
public void testLE() throws Exception { int count = 30; HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>(count); ArrayList<LEThread> threads = new ArrayList<LEThread>(count); File tmpdir[] = new File[count]; int port[] = new int[count]; votes = new Vote[count]; for (int i = 0; i < count; i++) { peers.put( Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", PortAssignment.unique()))); tmpdir[i] = ClientBase.createTmpDir(); port[i] = PortAssignment.unique(); } LeaderElection le[] = new LeaderElection[count]; leaderDies = true; boolean allowOneBadLeader = leaderDies; for (int i = 0; i < le.length; i++) { QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 0, i, 1000, 2, 2); peer.startLeaderElection(); le[i] = new LeaderElection(peer); LEThread thread = new LEThread(le[i], peer, i); thread.start(); threads.add(thread); } for (int i = 0; i < threads.size(); i++) { threads.get(i).join(15000); if (threads.get(i).isAlive()) { fail("Threads didn't join"); } } long id = votes[0].id; for (int i = 1; i < votes.length; i++) { if (votes[i] == null) { fail("Thread " + i + " had a null vote"); } if (votes[i].id != id) { if (allowOneBadLeader && votes[i].id == i) { allowOneBadLeader = false; } else { fail("Thread " + i + " got " + votes[i].id + " expected " + id); } } } }
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(peerQuorumPort[i]), new InetSocketAddress(PortAssignment.unique()))); peerTmpdir[i] = ClientBase.createTmpDir(); } }
public MainThread(int clientPort) throws IOException { super("Standalone server with clientPort:" + clientPort); File tmpDir = ClientBase.createTmpDir(); confFile = new File(tmpDir, "zoo.cfg"); FileWriter fwriter = new FileWriter(confFile); fwriter.write("tickTime=2000\n"); fwriter.write("initLimit=10\n"); fwriter.write("syncLimit=5\n"); File dataDir = new File(tmpDir, "data"); if (!dataDir.mkdir()) { throw new IOException("unable to mkdir " + dataDir); } fwriter.write("dataDir=" + dataDir.toString() + "\n"); fwriter.write("clientPort=" + clientPort + "\n"); fwriter.flush(); fwriter.close(); main = new TestZKSMain(); }
@Override protected TestableZooKeeper createClient(String hp) throws IOException, InterruptedException { File tmpDir = ClientBase.createTmpDir(); File saslConfFile = new File(tmpDir, "jaas.conf"); FileWriter fwriter = new FileWriter(saslConfFile); fwriter.write( "" + "Server {\n" + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + " user_super=\"test\";\n" + "};\n" + "Client {\n" + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + " username=\"super\"\n" + " password=\"test\";\n" + "};" + "\n"); fwriter.close(); System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); MyWatcher watcher = new MyWatcher(); return createClient(watcher, hp); }