tkalkirill commented on code in PR #806:
URL: https://github.com/apache/ignite-3/pull/806#discussion_r875656067
##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointerTest.java:
##########
@@ -100,43 +107,56 @@ void testStartAndStop() throws Exception {
@Test
void testScheduleCheckpoint() {
- Checkpointer checkpointer = new Checkpointer(
+ Checkpointer checkpointer = spy(new Checkpointer(
log,
"test",
null,
null,
mock(CheckpointWorkflow.class),
mock(CheckpointPagesWriterFactory.class),
1,
- () -> 1_000
- );
+ () -> 1_000,
+ () -> 0
+ ));
assertNull(checkpointer.currentProgress());
CheckpointProgressImpl scheduledProgress = (CheckpointProgressImpl)
checkpointer.scheduledProgress();
- long nextCheckpointDelayNanos =
scheduledProgress.nextCheckpointDelayNanos();
- String reason = scheduledProgress.reason();
+ long nextCheckpointNanosOnCreateCheckpointer =
scheduledProgress.nextCheckpointNanos();
+ String reasonOnCreateCheckpointer = scheduledProgress.reason();
assertThat(
- nextCheckpointDelayNanos,
- allOf(greaterThanOrEqualTo(MILLISECONDS.toNanos(995)),
lessThanOrEqualTo(MILLISECONDS.toNanos(1005)))
+ nextCheckpointNanosOnCreateCheckpointer - nanoTime(),
+ allOf(greaterThan(0L),
lessThanOrEqualTo(MILLISECONDS.toNanos(1_000)))
);
+ assertNull(reasonOnCreateCheckpointer);
+
assertSame(scheduledProgress, checkpointer.scheduleCheckpoint(3000,
"test0"));
assertNull(checkpointer.currentProgress());
- assertEquals(nextCheckpointDelayNanos,
scheduledProgress.nextCheckpointDelayNanos());
- assertEquals(reason, scheduledProgress.reason());
+ assertEquals(nextCheckpointNanosOnCreateCheckpointer,
scheduledProgress.nextCheckpointNanos());
+ assertEquals(reasonOnCreateCheckpointer, scheduledProgress.reason());
assertSame(scheduledProgress, checkpointer.scheduleCheckpoint(100,
"test1"));
assertNull(checkpointer.currentProgress());
- assertEquals(MILLISECONDS.toNanos(100),
scheduledProgress.nextCheckpointDelayNanos());
+ assertNotEquals(nextCheckpointNanosOnCreateCheckpointer,
scheduledProgress.nextCheckpointNanos());
+ assertNotEquals(reasonOnCreateCheckpointer,
scheduledProgress.reason());
+
+ assertThat(
+ scheduledProgress.nextCheckpointNanos() - nanoTime(),
+ allOf(greaterThan(0L),
lessThanOrEqualTo(MILLISECONDS.toNanos(100)))
+ );
+
assertEquals("test1", scheduledProgress.reason());
+ long nextCheckpointNanosSchedule100Mills =
scheduledProgress.nextCheckpointNanos();
+ String reasonSchedule100Mills = scheduledProgress.reason();
Review Comment:
Fix it.
##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointerTest.java:
##########
@@ -316,6 +357,50 @@ void testDoCheckpoint() throws Exception {
assertEquals(checkpointer.currentProgress().currentCheckpointPagesCount(), 3);
}
+ @Test
+ void testNextCheckpointInterval() {
+ AtomicLong checkpointFrequency = new AtomicLong();
+ AtomicInteger checkpointFrequencyDeviation = new AtomicInteger();
+
+ Checkpointer checkpointer = new Checkpointer(
+ log,
+ "test",
+ null,
+ null,
+ mock(CheckpointWorkflow.class),
+ mock(CheckpointPagesWriterFactory.class),
+ 1,
+ checkpointFrequency::get,
+ checkpointFrequencyDeviation::get
+ );
+
+ // Checks case 0 deviation.
+
+ checkpointFrequencyDeviation.set(0);
+
+ checkpointFrequency.set(1_000);
+ assertEquals(1_000, checkpointer.nextCheckpointInterval());
+
+ checkpointFrequency.set(2_000);
+ assertEquals(2_000, checkpointer.nextCheckpointInterval());
+
+ // Checks for non-zero deviation.
+
+ checkpointFrequencyDeviation.set(10);
+
+ assertThat(
+ checkpointer.nextCheckpointInterval(),
+ allOf(greaterThanOrEqualTo(1_900L), lessThanOrEqualTo(2_100L))
+ );
+
+ checkpointFrequencyDeviation.set(200);
Review Comment:
Fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]