当前位置: 首页>>代码示例>>Java>>正文


Java Logger.removeAppender方法代码示例

本文整理汇总了Java中org.apache.log4j.Logger.removeAppender方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.removeAppender方法的具体用法?Java Logger.removeAppender怎么用?Java Logger.removeAppender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.Logger的用法示例。


在下文中一共展示了Logger.removeAppender方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.apache.log4j.Logger; //导入方法依赖的package包/类
void run() {
  Logger rootLogger = Logger.getRootLogger();

  List<LoggingEvent> events = new ArrayList<>();
  Appender appender = new MockUp<Appender>() {
    @Mock
    public void doAppend(LoggingEvent event) {
      events.add(event);
    }
  }.getMockInstance();
  rootLogger.addAppender(appender);

  doRun(events);

  rootLogger.removeAppender(appender);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:TestServiceRegistryClientImpl.java

示例2: enableAsyncAuditLog

import org.apache.log4j.Logger; //导入方法依赖的package包/类
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:FSNamesystem.java

示例3: testNeedsApplyWithAppenderExpectTrue

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testNeedsApplyWithAppenderExpectTrue() {

    ActiveDbAppender appender = new ActiveDbAppender();
    appender.setHost( "test" );
    appender.setDatabase( "test" );
    appender.setUser( "test" );
    appender.setPassword( "test" );

    Logger log = Logger.getRootLogger();
    log.addAppender( appender );

    //construct the configurator - an appender is present
    RemoteLoggingConfigurator remoteLoggingConfig = new RemoteLoggingConfigurator( "127.0.0.1" );

    //remove the appender, so the configurator will need to apply it
    log.removeAppender( appender );

    assertTrue( remoteLoggingConfig.needsApplying() );
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:21,代码来源:Test_RemoteLoggingConfigurator.java

示例4: testRevertPositive

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testRevertPositive() {

    ActiveDbAppender appender = new ActiveDbAppender();
    appender.setHost( "test" );
    appender.setDatabase( "test" );
    appender.setUser( "test" );
    appender.setPassword( "test" );

    Logger log = Logger.getLogger( loggerName );
    log.addAppender( appender );

    //construct the configurator - an appender is present
    RemoteLoggingConfigurator remoteLoggingConfig = new RemoteLoggingConfigurator( "127.0.0.1" );

    //remove the appender, so the configurator will need to apply it
    log.removeAppender( appender );

    //apply the appender
    remoteLoggingConfig.apply();
    remoteLoggingConfig.revert();

    assertFalse( log.getAllAppenders().hasMoreElements() );
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:25,代码来源:Test_RemoteLoggingConfigurator.java

示例5: stop

import org.apache.log4j.Logger; //导入方法依赖的package包/类
public String stop() {
    if (!_Active) {
        return null;
    }

    System.out.flush();           
    String output = _CatcherStream.toString();
    
    System.setOut(_SystemOut);
    _SystemOut = null;
    Logger logger = getLogger();
    logger.removeAppender(_Appender);
    _Appender = null;
    
    
    try {
        _CatcherStream.close();
    }
    catch (IOException e) {
    } 
    
    _CatcherStream = null;
    
    _Active = false;

    return output;
}
 
开发者ID:baloise,项目名称:eZooKeeper,代码行数:28,代码来源:ZooKeeperServer.java

示例6: destroy

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Override
public void destroy() {
	for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements(); ) {
		Logger logger = (Logger)e.nextElement();
		logger.removeAppender("mlog");
	}
	LogManager.getRootLogger().removeAppender("mlog");
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:9,代码来源:MessageLogFilter.java

示例7: testSeekForRwServer

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Ensures that client seeks for r/w servers while it's connected to r/o
 * server.
 */
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {

    // setup the logger to capture all logs
    Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
            .getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);

    try {
        qu.shutdown(2);
        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(qu.getConnString(),
                CONNECTION_TIMEOUT, watcher, true);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        // if we don't suspend a peer it will rejoin a quorum
        qu.getPeer(1).peer.suspend();

        // start two servers to form a quorum; client should detect this and
        // connect to one of them
        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);

        // resume poor fellow
        qu.getPeer(1).peer.resume();
    } finally {
        zlogger.removeAppender(appender);
    }

    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);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:61,代码来源:ReadOnlyModeTest.java

示例8: testValidIpv6AddressInQuorum

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testValidIpv6AddressInQuorum() throws Exception {
    assumeIPv6Available();

    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
                "server.1=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique()
                + "\nserver.2=[0:0:0:0:0:0:0:1]:" + PortAssignment.unique()
                + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);

        q1.start();
        q2.start();

        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        Assert.assertTrue("waiting for server 2 being up",
                ClientBase.waitForServerUp("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        q1.shutdown();
        q2.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        Assert.assertTrue("waiting for server 2 down",
                ClientBase.waitForServerDown("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*Resolved hostname: 0:0:0:0:0:0:0:1.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("IPv6 address resolved", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:70,代码来源:QuorumPeerMainTest.java

示例9: testInvalidIpv6AddressInQuorum

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testInvalidIpv6AddressInQuorum() throws Exception {
    assumeIPv6Available();

    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();

        String quorumCfgSection =
                "server.1=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique()
                + "\nserver.2=[0:0:0:0:0:0:0:1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*QuorumPeerConfig\\$ConfigException.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about configuration", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例10: testQuorumDefaults

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Verify handling of quorum defaults
 * * default electionAlg is fast leader election
 */
@Test
public void testQuorumDefaults() throws Exception {
    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
        Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
            "server.1=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique()
            + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
        q1.start();
        q2.start();

        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                        CONNECTION_TIMEOUT));

        q1.shutdown();
        q2.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        zlogger.removeAppender(appender);
    }
    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
        Pattern.compile(".*FastLeaderElection.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("fastleaderelection used", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:68,代码来源:QuorumPeerMainTest.java

示例11: testApplyPositiveRootLogger

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Testing {@link RemoteLoggingConfigurator#needsApplying()} functionality ( must return true, after appender is removed form log4j )
 * and 
 * */
@Test
public void testApplyPositiveRootLogger() {

    ActiveDbAppender appender = new ActiveDbAppender();
    appender.setHost( "test" );
    appender.setDatabase( "test" );
    appender.setUser( "test" );
    appender.setPassword( "test" );

    Logger log = Logger.getRootLogger();
    log.addAppender( appender );

    //construct the configurator - an appender is present
    RemoteLoggingConfigurator remoteLoggingConfig = new RemoteLoggingConfigurator( "127.0.0.1" );

    //remove the appender, so the configurator will need to apply it
    log.removeAppender( appender );

    // check if needs to be applied - this sets the internal flags
    // so the next "apply" method will work as expected
    assertTrue( remoteLoggingConfig.needsApplying() );

    
    boolean hasDbCheckError = false;
    
    try {
        //apply the appender
        //this statement will fail, due to missing PostgreSQL or MSSQL server at localhost
        remoteLoggingConfig.apply();
    } catch (Exception e) {
        if (!e.getCause()
             .getMessage()
              .contains( "Neither MSSQL, nor PostgreSQL server at 'test' contains ATS log database with name 'test'." )) {
            // an exception was caught, but its cause is not the expected one
            // re-throw the exception
            throw e;
        }
        else {
            // expected exception was caught
            hasDbCheckError = true;
        }
    }
    
    assertTrue( hasDbCheckError );
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:50,代码来源:Test_RemoteLoggingConfigurator.java

示例12: testApplyPositive

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testApplyPositive() {

    ActiveDbAppender appender = new ActiveDbAppender();
    appender.setHost( "test" );
    appender.setDatabase( "test" );
    appender.setUser( "test" );
    appender.setPassword( "test" );

    Logger log = Logger.getLogger( loggerName );
    log.addAppender( appender );

    //construct the configurator - an appender is present
    RemoteLoggingConfigurator remoteLoggingConfig = new RemoteLoggingConfigurator( "127.0.0.1" );

    //remove the appender, so the configurator will need to apply it
    log.removeAppender( appender );

    // check if needs to be applied - this sets the internal flags
    // so the next "apply" method will work as expected
    assertTrue( remoteLoggingConfig.needsApplying() );

    boolean hasDbCheckError = false;
    
    try {
        //apply the appender
        //this statement will fail, due to missing PostgreSQL or MSSQL server at localhost
        remoteLoggingConfig.apply();
    } catch (Exception e) {
        if (!e.getCause()
             .getMessage()
              .contains( "Neither MSSQL, nor PostgreSQL server at 'test' contains ATS log database with name 'test'." )) {
            // an exception was caught, but its cause is not the expected one
            // re-throw the exception
            throw e;
        }
        else {
            // expected exception was caught
            hasDbCheckError = true;
        }
    }
    
    assertTrue( hasDbCheckError );
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:45,代码来源:Test_RemoteLoggingConfigurator.java

示例13: testBadPeerAddressInQuorum

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Verify handling of bad quorum address
 */
@Test
public void testBadPeerAddressInQuorum() throws Exception {
    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setThreshold(Level.WARN);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
            "server.1=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1
            + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*Cannot open channel to .* at election address .*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about host", found);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例14: testQuorumDefaults

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Verify handling of quorum defaults
 * * default electionAlg is fast leader election
 */
@Test
public void testQuorumDefaults() throws Exception {
    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
            "server.1=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1
            + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
        q1.start();
        q2.start();

        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                        CONNECTION_TIMEOUT));

        q1.shutdown();
        q2.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        zlogger.removeAppender(appender);
    }
    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*FastLeaderElection.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("fastleaderelection used", found);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:68,代码来源:QuorumPeerMainTest.java

示例15: testSeekForRwServer

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Ensures that client seeks for r/w servers while it's connected to r/o
 * server.
 */
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {
    // setup the logger to capture all logs
    Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
            .getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);

    try {
        qu.shutdown(2);
        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(qu.getConnString(),
                CONNECTION_TIMEOUT, watcher, true);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        // if we don't suspend a peer it will rejoin a quorum
        qu.getPeer(1).peer.suspend();

        // start two servers to form a quorum; client should detect this and
        // connect to one of them
        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);

        // resume poor fellow
        qu.getPeer(1).peer.resume();
    } finally {
        zlogger.removeAppender(appender);
    }

    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);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:60,代码来源:ReadOnlyModeTest.java


注:本文中的org.apache.log4j.Logger.removeAppender方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。