DiagnosticProcessor extends GridProcessorAdapter { public void dumpPageHistory( @NotNull PageHistoryDiagnoster.DiagnosticPageBuilder builder ) throws IgniteCheckedException { logTime(log, "DiagnosticPageHistory", () -> pageHistoryDiagnoster.dumpPageHistory(builder)); } DiagnosticProcessor(GridKernalContext ctx); @Override void onKernalStart(boolean active); void dumpPageHistory(
        @NotNull PageHistoryDiagnoster.DiagnosticPageBuilder builder
    ); void onFailure(Ignite ignite, FailureContext failureCtx); ReconciliationExecutionContext reconciliationExecutionContext(); static final String DEFAULT_TARGET_FOLDER; }
@Test public void dumpPageHistoryToDefaultDir() throws Exception { diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .pageIds(expectedPageId) .addAction(PRINT_TO_LOG) .addAction(PRINT_TO_FILE) ); Path path = Paths.get(U.defaultWorkDirectory(), DEFAULT_TARGET_FOLDER); File dumpFile = path.toFile().listFiles((dir, name) -> name.endsWith(FILE_FORMAT))[0]; List<String> records = Files.readAllLines(dumpFile.toPath()); assertTrue(!records.isEmpty()); assertTrue(records.stream().anyMatch(line -> line.contains("CheckpointRecord"))); }
@Test public void dumpRawPageHistoryToDefaultDir() throws Exception { diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .pageIds(expectedPageId) .addAction(PRINT_TO_RAW_FILE) ); Path path = Paths.get(U.defaultWorkDirectory(), DEFAULT_TARGET_FOLDER); File dumpFile = path.toFile().listFiles((dir, name) -> name.endsWith(RAW_FILE_FORMAT))[0]; try (SegmentIO io = new SegmentIO(0L, new RandomAccessFileIO(dumpFile, StandardOpenOption.READ))) { SegmentHeader hdr = RecordV1Serializer.readSegmentHeader(io, new SimpleSegmentFileInputFactory()); assertFalse(hdr.isCompacted()); assertEquals(RecordSerializerFactory.LATEST_SERIALIZER_VERSION, hdr.getSerializerVersion()); } }
@Test public void dumpPageHistoryToCustomAbsoluteDir() throws Exception { Path path = Paths.get(U.defaultWorkDirectory(), TEST_DUMP_PAGE_FILE); try { diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .pageIds(expectedPageId) .folderForDump(path.toFile()) .addAction(PRINT_TO_FILE) ); File dumpFile = path.toFile().listFiles((dir, name) -> name.endsWith(FILE_FORMAT))[0]; List<String> records = Files.readAllLines(dumpFile.toPath()); assertTrue(!records.isEmpty()); assertTrue(records.stream().anyMatch(line -> line.contains("CheckpointRecord"))); } finally { U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), TEST_DUMP_PAGE_FILE, false)); } }
@Test public void dumpPageHistoryToCustomRelativeDir() throws Exception { Path path = Paths.get(U.defaultWorkDirectory(), DEFAULT_TARGET_FOLDER, TEST_DUMP_PAGE_FILE); diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .pageIds(expectedPageId) .folderForDump(new File(TEST_DUMP_PAGE_FILE)) .addAction(PRINT_TO_FILE) ); File dumpFile = path.toFile().listFiles((dir, name) -> name.endsWith(FILE_FORMAT))[0]; List<String> records = Files.readAllLines(dumpFile.toPath()); assertTrue(!records.isEmpty()); assertTrue(records.stream().anyMatch(line -> line.contains("CheckpointRecord"))); }
@Test public void dumpOnlyCheckpointRecordBecausePageIdNotSet() throws Exception { diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .addAction(PRINT_TO_LOG) .addAction(PRINT_TO_FILE) ); Path path = Paths.get(U.defaultWorkDirectory(), DEFAULT_TARGET_FOLDER); File dumpFile = path.toFile().listFiles((dir, name) -> name.endsWith(FILE_FORMAT))[0]; List<String> records = Files.readAllLines(dumpFile.toPath()); assertTrue(records.stream().allMatch(line -> line.contains("CheckpointRecord"))); }
@Test(expected = NullPointerException.class) public void throwExceptionBecauseNotAnyActionsWasSet() throws IgniteCheckedException { diagnosticProcessor.dumpPageHistory(new PageHistoryDiagnoster.DiagnosticPageBuilder() .pageIds(expectedPageId) ); }