Java 类org.apache.log4j.util.SerializationTestHelper 实例源码

项目:cacheonix-core    文件:LoggingEventTest.java   
/**
   * Serialize a simple logging event and check it against
   * a witness.
   * @throws Exception if exception during test.
   */
  public void testSerializationSimple() throws Exception {
    Logger root = Logger.getRootLogger();
    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/simple.bin", event, skip, 237);
  }
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
   * Serialize a logging event with an exception and check it against
   * a witness.
   * @throws Exception if exception during test.
   *
   */
  public void testSerializationWithException() throws Exception {
    Logger root = Logger.getRootLogger();
    Exception ex = new Exception("Don't panic");
    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", ex);
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/exception.bin", event, skip, 237);
  }
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
   * Serialize a logging event with an exception and check it against
   * a witness.
   * @throws Exception if exception during test.
   *
   */
  public void testSerializationWithLocation() throws Exception {
    Logger root = Logger.getRootLogger();
    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
    LocationInfo info = event.getLocationInformation();
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/location.bin", event, skip, 237);
  }
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
   * Serialize a logging event with ndc.
   * @throws Exception if exception during test.
   *
   */
  public void testSerializationNDC() throws Exception {
    Logger root = Logger.getRootLogger();
    NDC.push("ndc test");

    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/ndc.bin", event, skip, 237);
    }
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
   * Serialize a logging event with mdc.
   * @throws Exception if exception during test.
   *
   */
  public void testSerializationMDC() throws Exception {
    Logger root = Logger.getRootLogger();
    MDC.put("mdckey", "mdcvalue");

    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/mdc.bin", event, skip, 237);
  }
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
 * Deserialize a simple logging event.
 * @throws Exception if exception during test.
 *
 */
public void testDeserializationSimple() throws Exception {
  Object obj =
    SerializationTestHelper.deserializeStream(
      "witness/serialization/simple.bin");
  assertTrue(obj instanceof LoggingEvent);

  LoggingEvent event = (LoggingEvent) obj;
  assertEquals("Hello, world.", event.getMessage());
  assertEquals(Level.INFO, event.getLevel());
}
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
 * Deserialize a logging event with an exception.
 * @throws Exception if exception during test.
 *
 */
public void testDeserializationWithException() throws Exception {
  Object obj =
    SerializationTestHelper.deserializeStream(
      "witness/serialization/exception.bin");
  assertTrue(obj instanceof LoggingEvent);

  LoggingEvent event = (LoggingEvent) obj;
  assertEquals("Hello, world.", event.getMessage());
  assertEquals(Level.INFO, event.getLevel());
}
项目:cacheonix-core    文件:LoggingEventTest.java   
/**
 * Deserialize a logging event with an exception.
 * @throws Exception if exception during test.
 *
 */
public void testDeserializationWithLocation() throws Exception {
  Object obj =
    SerializationTestHelper.deserializeStream(
      "witness/serialization/location.bin");
  assertTrue(obj instanceof LoggingEvent);

  LoggingEvent event = (LoggingEvent) obj;
  assertEquals("Hello, world.", event.getMessage());
  assertEquals(Level.INFO, event.getLevel());
}
项目:cacheonix-core    文件:LevelTest.java   
/**
 * Deserialize witness and see if resolved to Level.INFO.
 * @throws Exception if exception during test.
 */
public void testDeserializeINFO() throws Exception {
  Object obj =
    SerializationTestHelper.deserializeStream(
      "witness/serialization/info.bin");
  assertTrue(obj instanceof Level);
  Level info = (Level) obj;
  assertEquals("INFO", info.toString());
  //
  //  JDK 1.1 doesn't support readResolve necessary for the assertion
  if (!System.getProperty("java.version").startsWith("1.1.")) {
     assertTrue(obj == Level.INFO);
  }
}
项目:cacheonix-core    文件:LevelTest.java   
/**
 * Tests that a custom level can be serialized and deserialized
 * and is not resolved to a stock level.
 *
 * @throws Exception if exception during test.
 */
public void testCustomLevelSerialization() throws Exception {
  CustomLevel custom = new CustomLevel();
  Object obj = SerializationTestHelper.serializeClone(custom);
  assertTrue(obj instanceof CustomLevel);

  CustomLevel clone = (CustomLevel) obj;
  assertEquals(Level.INFO.level, clone.level);
  assertEquals(Level.INFO.levelStr, clone.levelStr);
  assertEquals(Level.INFO.syslogEquivalent, clone.syslogEquivalent);
}
项目:log4j2    文件:LevelTest.java   
/**
 * Serialize Level.INFO and check against witness.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testSerializeINFO() throws Exception {
    final int[] skip = new int[]{};
    SerializationTestHelper.assertSerializationEquals(
        "target/test-classes/witness/serialization/info.bin",
        Level.INFO, skip, Integer.MAX_VALUE);
}
项目:log4j2    文件:LevelTest.java   
/**
 * Deserialize witness and see if resolved to Level.INFO.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testDeserializeINFO() throws Exception {
    final Object obj =
        SerializationTestHelper.deserializeStream(
            "target/test-classes/witness/serialization/info.bin");
    assertTrue(obj instanceof Level);
    final Level info = (Level) obj;
    assertEquals("INFO", info.toString());
    //
    //  JDK 1.1 doesn't support readResolve necessary for the assertion
    if (!System.getProperty("java.version").startsWith("1.1.")) {
        assertTrue(obj == Level.INFO);
    }
}
项目:log4j2    文件:LevelTest.java   
/**
 * Tests that a custom level can be serialized and deserialized
 * and is not resolved to a stock level.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testCustomLevelSerialization() throws Exception {
    final CustomLevel custom = new CustomLevel();
    final Object obj = SerializationTestHelper.serializeClone(custom);
    assertTrue(obj instanceof CustomLevel);

    final CustomLevel clone = (CustomLevel) obj;
    assertEquals(Level.INFO.level, clone.level);
    assertEquals(Level.INFO.levelStr, clone.levelStr);
    assertEquals(Level.INFO.syslogEquivalent, clone.syslogEquivalent);
}
项目:logging-log4j2    文件:LevelTest.java   
/**
 * Serialize Level.INFO and check against witness.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testSerializeINFO() throws Exception {
    final int[] skip = new int[]{};
    SerializationTestHelper.assertSerializationEquals(
        "target/test-classes/witness/serialization/info.bin",
        Level.INFO, skip, Integer.MAX_VALUE);
}
项目:logging-log4j2    文件:LevelTest.java   
/**
 * Deserialize witness and see if resolved to Level.INFO.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testDeserializeINFO() throws Exception {
    final Object obj =
        SerializationTestHelper.deserializeStream(
            "target/test-classes/witness/serialization/info.bin");
    assertTrue(obj instanceof Level);
    final Level info = (Level) obj;
    assertEquals("INFO", info.toString());
    //
    //  JDK 1.1 doesn't support readResolve necessary for the assertion
    if (!System.getProperty("java.version").startsWith("1.1.")) {
        assertTrue(obj == Level.INFO);
    }
}
项目:logging-log4j2    文件:LevelTest.java   
/**
 * Tests that a custom level can be serialized and deserialized
 * and is not resolved to a stock level.
 *
 * @throws Exception if exception during test.
 */
@Test
public void testCustomLevelSerialization() throws Exception {
    final CustomLevel custom = new CustomLevel();
    final Object obj = SerializationTestHelper.serializeClone(custom);
    assertTrue(obj instanceof CustomLevel);

    final CustomLevel clone = (CustomLevel) obj;
    assertEquals(Level.INFO.level, clone.level);
    assertEquals(Level.INFO.levelStr, clone.levelStr);
    assertEquals(Level.INFO.syslogEquivalent, clone.syslogEquivalent);
}
项目:cacheonix-core    文件:LevelTest.java   
/**
 * Serialize Level.INFO and check against witness.
 * @throws Exception if exception during test.
 *
 */
public void testSerializeINFO() throws Exception {
  int[] skip = new int[] {  };
  SerializationTestHelper.assertSerializationEquals(
    "witness/serialization/info.bin", Level.INFO, skip, Integer.MAX_VALUE);
}