Java 类java.util.logging.SocketHandler 实例源码

项目:cn1    文件:SocketHandlerTest.java   
public void testConstructor_InvalidPort() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.level", "FINE");
    p.put("java.util.logging.SocketHandler.filter", className
            + "$MockFilter");
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.encoding", "iso-8859-1");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666i");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    try {
        h = new SocketHandler();
        fail("Should throw IllegalArgumentException!");
    } catch (IllegalArgumentException e) {

    }
}
项目:cn1    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.publish(new LogRecord(Level.SEVERE,
            "testClose_SufficientPrivilege_NormalClose msg"));
    h.close();
    assertEquals("MockFormatter_Head"
            + "testClose_SufficientPrivilege_NormalClose msg"
            + "MockFormatter_Tail", thread.getReadString());
    h.close();
}
项目:cn1    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_WithFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    h.setFilter(new MockFilter());

    System.setErr(new PrintStream(new ByteArrayOutputStream()));

    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_Null() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    try {
        h.publish(null);
    } finally {
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_EmptyMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, "");
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_NullMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, null);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testConstructor_InvalidPort() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.level", "FINE");
    p.put("java.util.logging.SocketHandler.filter", className
            + "$MockFilter");
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.encoding", "iso-8859-1");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666i");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    try {
        h = new SocketHandler();
        fail("Should throw IllegalArgumentException!");
    } catch (IllegalArgumentException e) {

    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.publish(new LogRecord(Level.SEVERE,
            "testClose_SufficientPrivilege_NormalClose msg"));
    h.close();
    assertEquals("MockFormatter_Head"
            + "testClose_SufficientPrivilege_NormalClose msg"
            + "MockFormatter_Tail", thread.getReadString());
    h.close();
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_WithFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    h.setFilter(new MockFilter());

    System.setErr(new PrintStream(new ByteArrayOutputStream()));

    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_Null() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    try {
        h.publish(null);
    } finally {
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_EmptyMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, "");
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_NullMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, null);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testConstructor_InvalidPort() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.level", "FINE");
    p.put("java.util.logging.SocketHandler.filter", className
            + "$MockFilter");
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.encoding", "iso-8859-1");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666i");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    try {
        h = new SocketHandler();
        fail("Should throw IllegalArgumentException!");
    } catch (IllegalArgumentException e) {

    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.publish(new LogRecord(Level.SEVERE,
            "testClose_SufficientPrivilege_NormalClose msg"));
    h.close();
    assertEquals("MockFormatter_Head"
            + "testClose_SufficientPrivilege_NormalClose msg"
            + "MockFormatter_Tail", thread.getReadString());
    h.close();
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_WithFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    h.setFilter(new MockFilter());

    System.setErr(new PrintStream(new ByteArrayOutputStream()));

    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_Null() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    try {
        h.publish(null);
    } finally {
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_EmptyMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, "");
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_NullMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.INFO);
    LogRecord r = new LogRecord(Level.INFO, null);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:openjdk-jdk10    文件:HandlersConfigTest.java   
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
项目:openjdk-jdk10    文件:HandlersConfigTest.java   
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        ConfiguredHandler.class, 123, Level.FINE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.FINE, "ASCII", ConfiguredFilter.class, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class);
    } catch (Exception e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
项目:openjdk9    文件:HandlersConfigTest.java   
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
项目:openjdk9    文件:HandlersConfigTest.java   
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        ConfiguredHandler.class, 123, Level.FINE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.FINE, "ASCII", ConfiguredFilter.class, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class);
    } catch (Exception e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
项目:windup-rulesets    文件:Logging.java   
public static void main(String argv[]) {
    FileAppender fa = new FileAppender();
    RollingFileAppender rfa = new RollingFileAppender();
    DailyRollingFileAppender drfa = new DailyRollingFileAppender();
    FileHandler fh = new FileHandler();
    SocketHandler sh = new SocketHandler("host", 1);
}
项目:cn1    文件:SocketHandlerTest.java   
public void testClose_InsufficientPrivilege() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    SecurityManager oldMan = System.getSecurityManager();
    System.setSecurityManager(new MockSecurityManager());
    try {
        h.close();
        fail("Should throw SecurityException!");
    } catch (SecurityException e) {
    } finally {
        System.setSecurityManager(oldMan);
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_NoFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
    h.setLevel(Level.INFO);
    h.publish(r);

    h.setLevel(Level.WARNING);
    h.publish(r);

    h.setLevel(Level.CONFIG);
    h.publish(r);

    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
            + "testPublish_NoFilter" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:cn1    文件:SocketHandlerTest.java   
public void testPublish_AfterClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.FINE);

    assertSame(h.getLevel(), Level.FINE);
    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFormatter");
    assertTrue(h.isLoggable(r));
    h.close();
    // ensure the thread exits and the port becomes available again
    thread.getReadString();
    // assertFalse(h.isLoggable(r));
    h.publish(r);
    h.flush();
    // assertEquals("MockFormatter_Head",
    // this.errSubstituteStream.toString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_InsufficientPrivilege() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    SecurityManager oldMan = System.getSecurityManager();
    System.setSecurityManager(new MockSecurityManager());
    try {
        h.close();
        fail("Should throw SecurityException!");
    } catch (SecurityException e) {
    } finally {
        System.setSecurityManager(oldMan);
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_NoFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
    h.setLevel(Level.INFO);
    h.publish(r);

    h.setLevel(Level.WARNING);
    h.publish(r);

    h.setLevel(Level.CONFIG);
    h.publish(r);

    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
            + "testPublish_NoFilter" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_AfterClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.FINE);

    assertSame(h.getLevel(), Level.FINE);
    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFormatter");
    assertTrue(h.isLoggable(r));
    h.close();
    // ensure the thread exits and the port becomes available again
    thread.getReadString();
    // assertFalse(h.isLoggable(r));
    h.publish(r);
    h.flush();
    // assertEquals("MockFormatter_Head",
    // this.errSubstituteStream.toString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testClose_InsufficientPrivilege() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    SecurityManager oldMan = System.getSecurityManager();
    System.setSecurityManager(new MockSecurityManager());
    try {
        h.close();
        fail("Should throw SecurityException!");
    } catch (SecurityException e) {
    } finally {
        System.setSecurityManager(oldMan);
        h.close();
        // ensure the thread exits and the port becomes available again
        thread.getReadString();
    }
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_NoFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);

    h = new SocketHandler();
    h.setLevel(Level.INFO);

    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
    h.setLevel(Level.INFO);
    h.publish(r);

    h.setLevel(Level.WARNING);
    h.publish(r);

    h.setLevel(Level.CONFIG);
    h.publish(r);

    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    h.close();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
            + "testPublish_NoFilter" + "MockFormatter_Tail", thread
            .getReadString());
}
项目:freeVM    文件:SocketHandlerTest.java   
public void testPublish_AfterClose() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.SocketHandler.formatter", className
            + "$MockFormatter");
    p.put("java.util.logging.SocketHandler.host", "127.0.0.1");
    p.put("java.util.logging.SocketHandler.port", "6666");
    LOG_MANAGER.readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    // start the server to be ready to accept log messages
    ServerThread thread = new ServerThread();
    thread.start();
    Thread.sleep(2000);
    h = new SocketHandler();
    h.setLevel(Level.FINE);

    assertSame(h.getLevel(), Level.FINE);
    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFormatter");
    assertTrue(h.isLoggable(r));
    h.close();
    // ensure the thread exits and the port becomes available again
    thread.getReadString();
    // assertFalse(h.isLoggable(r));
    h.publish(r);
    h.flush();
    // assertEquals("MockFormatter_Head",
    // this.errSubstituteStream.toString());
}