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


Java WriterAppender.setThreshold方法代码示例

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


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

示例1: setupLoggers

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
 * Setup the main loggers for Novoa benchmarking routine.
 */
public void setupLoggers() {
    LoggerHelper.setupRootLogger(LoggerHelper.LEVEL_WARN, LoggerHelper.LEVEL_WARN, true);

    // Configuring loggers
    Logger.getRootLogger().setLevel(LoggerHelper.LEVEL_WARN);

    // MSA
    MSALogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);

    // CW
    CWLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);

    // VLS
    VLSLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);

    // Heuristics
    HeuristicsLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);

    WriterAppender logAppender = new WriterAppender(DEFAULT_LOGGER_LAYOUT, err);
    logAppender.setThreshold(LoggerHelper.LEVEL_WARN);
    logAppender.setImmediateFlush(true);

    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(logAppender);
}
 
开发者ID:vpillac,项目名称:vroom,代码行数:29,代码来源:NovoaBenchmarking.java

示例2: setUpLoggerStream

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
 * Helper method to set up stream.
 * @return ByteArrayOutputStream for logging
 */
private ByteArrayOutputStream setUpLoggerStream() {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final WriterAppender appender = new WriterAppender(
        new SimpleLayout(),
        baos
    );
    appender.setThreshold(Level.ERROR);
    appender.activateOptions();
    Logger.getRootLogger().addAppender(appender);
    return baos;
}
 
开发者ID:yegor256,项目名称:takes,代码行数:16,代码来源:FbLog4jTest.java

示例3: FoxWebLog

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
 * 
 * @param name
 */
public FoxWebLog(final String name) {
  logger = Logger.getLogger(name);
  // add appender to log
  final WriterAppender appender =
      new WriterAppender(new PatternLayout("%d{HH:mm:ss} - %m%n"), consoleWriter);
  appender.setName("CONSOLE_APPENDER");
  appender.setThreshold(Level.INFO);
  logger.removeAllAppenders();
  logger.addAppender(appender);
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:15,代码来源:FoxWebLog.java

示例4: testBadPeerAddressInQuorum

import org.apache.log4j.WriterAppender; //导入方法依赖的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()
            + "\nserver.2=fee.fii.foo.fum:" + 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);
    }

    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:maoling,项目名称:fuck_zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例5: testValidIpv6AddressInQuorum

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例6: testInvalidIpv6AddressInQuorum

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例7: testQuorumDefaults

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例8: testSeekForRwServer

import org.apache.log4j.WriterAppender; //导入方法依赖的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:maoling,项目名称:fuck_zookeeper,代码行数:61,代码来源:ReadOnlyModeTest.java

示例9: testBadPeerAddressInQuorum

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例10: testQuorumDefaults

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例11: testSeekForRwServer

import org.apache.log4j.WriterAppender; //导入方法依赖的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

示例12: testJobMonitorAndPrint

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
@Test
public void testJobMonitorAndPrint() throws Exception {
  JobStatus jobStatus_1 = new JobStatus(new JobID("job_000", 1), 1f, 0.1f,
      0.1f, 0f, State.RUNNING, JobPriority.HIGH, "tmp-user", "tmp-jobname",
      "tmp-queue", "tmp-jobfile", "tmp-url", true);
  JobStatus jobStatus_2 = new JobStatus(new JobID("job_000", 1), 1f, 1f,
      1f, 1f, State.SUCCEEDED, JobPriority.HIGH, "tmp-user", "tmp-jobname",
      "tmp-queue", "tmp-jobfile", "tmp-url", true);

  doAnswer(
      new Answer<TaskCompletionEvent[]>() {
        @Override
        public TaskCompletionEvent[] answer(InvocationOnMock invocation)
            throws Throwable {
          return new TaskCompletionEvent[0];
        }
      }
      ).when(job).getTaskCompletionEvents(anyInt(), anyInt());

  doReturn(new TaskReport[5]).when(job).getTaskReports(isA(TaskType.class));
  when(clientProtocol.getJobStatus(any(JobID.class))).thenReturn(jobStatus_1, jobStatus_2);
  // setup the logger to capture all logs
  Layout layout =
      Logger.getRootLogger().getAppender("stdout").getLayout();
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  WriterAppender appender = new WriterAppender(layout, os);
  appender.setThreshold(Level.ALL);
  Logger qlogger = Logger.getLogger(Job.class);
  qlogger.addAppender(appender);

  job.monitorAndPrintJob();

  qlogger.removeAppender(appender);
  LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
  String line;
  boolean foundHundred = false;
  boolean foundComplete = false;
  boolean foundUber = false;
  String uberModeMatch = "uber mode : true";
  String progressMatch = "map 100% reduce 100%";
  String completionMatch = "completed successfully";
  while ((line = r.readLine()) != null) {
    if (line.contains(uberModeMatch)) {
      foundUber = true;
    }
    foundHundred = line.contains(progressMatch);      
    if (foundHundred)
      break;
  }
  line = r.readLine();
  foundComplete = line.contains(completionMatch);
  assertTrue(foundUber);
  assertTrue(foundHundred);
  assertTrue(foundComplete);

  System.out.println("The output of job.toString() is : \n" + job.toString());
  assertTrue(job.toString().contains("Number of maps: 5\n"));
  assertTrue(job.toString().contains("Number of reduces: 5\n"));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:60,代码来源:TestJobMonitorAndPrint.java

示例13: testNegotiation

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
    PrimaryVertex pv = new PrimaryVertex();
    GDHVertex[] verticles = new GDHVertex[amount];
    Configuration[] confs = new Configuration[amount];
    Writer writer = new StringWriter();
    for (int i = 0; i < amount; i++) {
        verticles[i] = new GDHVertex();
        confs[i] = new Configuration();
        WriterAppender app = new WriterAppender(new PatternLayout(), writer);
        app.setThreshold(Level.DEBUG);
        app.activateOptions();
        confs[i].setAppender(app);
        String port = amount + "08" + i;
        confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
        verticles[i].setConfiguration(confs[i]);
    }
    List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));

    Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
    verticles[0].addGroup(g);

    Async async1 = context.async(amount);
    for (int i = 0; i < amount; i++)
        pv.run(verticles[i], res -> {
            if (res.succeeded()) {
                async1.countDown();
            } else {
                res.cause().printStackTrace();
                return;
            }
        });
    async1.awaitSuccess();

    BigInteger[] keys = new BigInteger[2];
    try {
        keys[0] = verticles[0].exchange(g.getGroupId()).get();
        Assert.assertFalse(!writer.toString().isEmpty() && writer.toString().contains(keys[0].toString()));
    } catch (InterruptedException | ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Async async2 = context.async(amount);
    for (int i = 0; i < amount; i++)
        pv.kill(verticles[i], res -> {
            if (res.succeeded()) {
                async2.countDown();
            } else {
                res.cause().printStackTrace();
            }
        });
    async2.awaitSuccess();
}
 
开发者ID:maxamel,项目名称:GDH,代码行数:53,代码来源:NoKeyOnWireTest.java

示例14: testNegotiation

import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
    PrimaryVertex pv = new PrimaryVertex();
    GDHVertex[] verticles = new GDHVertex[amount];
    Configuration[] confs = new Configuration[amount];
    Writer writer = new StringWriter();
    for (int i = 0; i < amount; i++) {
        verticles[i] = new GDHVertex();
        confs[i] = new Configuration();
        WriterAppender app = new WriterAppender(new PatternLayout(), writer);
        app.setThreshold(Level.DEBUG);
        app.activateOptions();
        confs[i].setAppender(app);
        String port = amount + "08" + i;
        confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
        verticles[i].setConfiguration(confs[i]);
    }
    List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));

    Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
    verticles[0].addGroup(g);

    Async async1 = context.async(amount);
    for (int i = 0; i < amount; i++)
        pv.run(verticles[i], res -> {
            if (res.succeeded()) {
                async1.countDown();
            } else {
                res.cause().printStackTrace();
                return;
            }
        });
    async1.awaitSuccess();

    BigInteger[] keys = new BigInteger[1];
    try {
        keys[0] = verticles[0].exchange(g.getGroupId()).get();
        for (int j = 0; j < verticles.length; j++) {
            Assert.assertEquals(verticles[j].getKey(g.getGroupId()).get(), keys[0]);
        }
        //System.out.println(StringUtils.countMatches(writer.toString(), Constants.LOG_IN));
        //System.out.println(StringUtils.countMatches(writer.toString(), Constants.LOG_OUT));
        Assert.assertTrue(StringUtils.countMatches(writer.toString(), Constants.LOG_IN) >= amount*amount-1);
        Assert.assertTrue(StringUtils.countMatches(writer.toString(), Constants.LOG_OUT) >= amount*amount-1);
    } catch (InterruptedException | ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Async async2 = context.async(amount);
    for (int i = 0; i < amount; i++)
        pv.kill(verticles[i], res -> {
            if (res.succeeded()) {
                async2.countDown();
            } else {
                res.cause().printStackTrace();
            }
        });
    async2.awaitSuccess();
}
 
开发者ID:maxamel,项目名称:GDH,代码行数:59,代码来源:LoggerTest.java

示例15: testBadPeerAddressInQuorum

import org.apache.log4j.WriterAppender; //导入方法依赖的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()
            + "\nserver.2=fee.fii.foo.fum:" + 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,
                    5000);

        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:gerritjvv,项目名称:bigstreams,代码行数:59,代码来源:QuorumPeerMainTest.java


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