Source:
<code>public void testSeekForRwServer() throws Exception { LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); Configuration logConfig = loggerContext.getConfiguration(); Layout layout = logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); String appenderName = "zkAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); <START> WriterAppender appender = WriterAppender.createAppender((StringLayout)layout, null, new OutputStreamWriter(os), appenderName, false, true); <END> appender.start(); LoggerConfig zloggerConfig = logConfig.getLoggerConfig("org.apache.zookeeper"); zloggerConfig.addAppender(appender, Level.INFO, null); logConfig.getRootLogger().addAppender(appender, null, null); try { qu.shutdown(2); CountdownWatcher watcher = new CountdownWatcher(); ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true); watcher.waitForConnected(CONNECTION_TIMEOUT); qu.getPeer(1).peer.suspend(); watcher.reset(); qu.start(2); qu.start(3); ClientBase.waitForServerUp(qu.getConnString(), 2000); watcher.waitForConnected(CONNECTION_TIMEOUT); zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); qu.getPeer(1).peer.resume(); } finally { zloggerConfig.removeAppender(appenderName); logConfig.getRootLogger().removeAppender(appenderName); } os.close(); LineNumberReader r = new LineNumberReader(new StringReader(os .toString())); String line; Pattern p = Pattern.compile(".*Majority server found.*"); boolean found = false; while ((line = r.readLine()) != null) { if (p.matcher(line).matches()) { found = true; break; } } Assert.assertTrue( "Majority server wasn't found while connected to r/o server", found); }</code><technical_language>a good idea builder create appender (see above)</technical_language>

Target:
public void testSeekForRwServer() throws Exception { LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); Configuration logConfig = loggerContext.getConfiguration(); Layout layout = logConfig.getRootLogger().getAppenders().get("STDOUT").getLayout(); String appenderName = "zkAppender"; ByteArrayOutputStream os = new ByteArrayOutputStream(); WriterAppender appender = WriterAppender.newBuilder().setLayout((StringLayout)layout).setTarget(new OutputStreamWriter(os)).setName(appenderName).build(); appender.start(); LoggerConfig zloggerConfig = logConfig.getLoggerConfig("org.apache.zookeeper"); zloggerConfig.addAppender(appender, Level.INFO, null); logConfig.getRootLogger().addAppender(appender, null, null); try { qu.shutdown(2); CountdownWatcher watcher = new CountdownWatcher(); ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true); watcher.waitForConnected(CONNECTION_TIMEOUT); qu.getPeer(1).peer.suspend(); watcher.reset(); qu.start(2); qu.start(3); ClientBase.waitForServerUp(qu.getConnString(), 2000); watcher.waitForConnected(CONNECTION_TIMEOUT); zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); qu.getPeer(1).peer.resume(); } finally { zloggerConfig.removeAppender(appenderName); logConfig.getRootLogger().removeAppender(appenderName); } os.close(); LineNumberReader r = new LineNumberReader(new StringReader(os .toString())); String line; Pattern p = Pattern.compile(".*Majority server found.*"); boolean found = false; while ((line = r.readLine()) != null) { if (p.matcher(line).matches()) { found = true; break; } } Assert.assertTrue( "Majority server wasn't found while connected to r/o server", found); }