@Test
  public void testSnapshotPerformance() {
    ExchangeSnapshotFactory instance = ExchangeSnapshotFactory.getInstance();

    for (int i = 0; i < 20; i++) {
      MockExchange mockExchange = createExchange();

      char[] buf = new char[(int) (Math.random() * 1024)];
      for (int x = buf.length - 1; x >= 0; x--) {
        buf[x] = (char) (Math.random() * 128);
      }

      mockExchange.getMessage().setContent(new String(buf));

      // add an attachment
      byte[] bufAttachment = new byte[(int) (1024 * 1024 * 5)];
      for (int x = buf.length - 1; x >= 0; x--) {
        bufAttachment[x] = (byte) (Math.random() * 128);
      }

      mockExchange
          .getMessage()
          .addAttachment(
              "file", new MockDataSource("mock", "applicaton/octet-stream", bufAttachment));

      long startedAt = System.currentTimeMillis();
      ExchangeSnapshot snapshot = instance.createSnapshot(mockExchange);
      assertNotNull(snapshot);

      System.out.println("Snapshot created at " + (System.currentTimeMillis() - startedAt) + " ms");
    }
  }
 @Test
 public void exchangeSnapshotFactory() {
   ExchangeSnapshotFactory instance = null;
   try {
     instance = ExchangeSnapshotFactory.getInstance();
     assertNotNull(instance);
   } catch (Exception e) {
     fail("Factory instatiation failed");
   }
 }
  @Test
  public void exchangeSnapshotCreate() {
    ExchangeSnapshotFactory instance = ExchangeSnapshotFactory.getInstance();
    MockExchange mockExchange = createExchange();

    long startedAt = System.currentTimeMillis();
    ExchangeSnapshot snapshot = instance.createSnapshot(mockExchange);
    assertNotNull(snapshot);

    System.out.println("Snapshot created at " + (System.currentTimeMillis() - startedAt) + " ms");

    assertNotNull(snapshot.getContext());
    assertNotNull(snapshot.getContract());
    assertNotNull(snapshot.getPhase());
    assertNotNull(snapshot.getState());

    assertNotNull(snapshot.getMessageBytes());
    assertNotNull(snapshot.getMessage());

    // restore & compare

    mockExchange.getMessage().setContent("CHANGED");
    assertEquals("ORIGINAL", snapshot.getMessage().getContent());
  }