ToFileDumpProcessor { public static String toFileDump(SharedPageLockTrackerDump pageLockDump, File dir, String name) throws IgniteCheckedException { try { if (!dir.exists()) dir.mkdirs(); File file = new File(dir, PREFIX_NAME + name + "_" + DATE_FMT.format(new Date(pageLockDump.time))); return saveToFile(ToStringDumpHelper.toStringDump(pageLockDump), file); } catch (IOException e) { throw new IgniteCheckedException(e); } }  static String toFileDump(SharedPageLockTrackerDump pageLockDump, File dir, String name); static final SimpleDateFormat DATE_FMT; static final String PREFIX_NAME; }
@Test public void toFileDump() throws Exception { String igHome = U.defaultWorkDirectory(); System.out.println("IGNITE_HOME:" + igHome); SharedPageLockTracker pageLockTracker = new SharedPageLockTracker(); pageLockTracker.onBeforeReadLock(1, 2, 3); pageLockTracker.onReadLock(1, 2, 3, 4); SharedPageLockTrackerDump pageLockDump = pageLockTracker.dump(); Assert.assertNotNull(pageLockDump); String expDumpStr = ToStringDumpHelper.toStringDump(pageLockDump); String filePath = ToFileDumpProcessor.toFileDump(pageLockDump, file = new File(igHome), "test"); System.out.println("Dump saved:" + filePath); boolean found = false; for (File file : file.listFiles()) { if (file.getAbsolutePath().equals(filePath)) { found = true; break; } } Assert.assertTrue(found); String actDumpStr; try (FileChannel ch = FileChannel.open(get(filePath), StandardOpenOption.READ)) { long size = ch.size(); ByteBuffer buf = ByteBuffer.allocate((int)size); while (buf.position() != buf.capacity()) ch.read(buf); actDumpStr = new String(buf.array()); } Assert.assertEquals(expDumpStr, actDumpStr); }