@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"); } }
private MockExchange createExchange() { MockExchange mockExchange = new MockExchange(); InOnlyOperation testOperation = new InOnlyOperation("test"); testOperation.setInputType(QName.valueOf("test:input")); mockExchange.provider( new ServiceImpl(QName.valueOf("test:inputService"), null, null, null), testOperation); mockExchange.setPhase(ExchangePhase.IN); mockExchange.getMessage().setContent("ORIGINAL"); return mockExchange; }
@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()); }