Search in sources :

Example 6 with EpochClock

use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.

the class ArchiveToolTests method checksumRecordingLastSegmentFile.

@Test
void checksumRecordingLastSegmentFile() {
    checksumRecording(out, archiveDir, validRecording3, false, crc32(), epochClock);
    assertTrue(verifyRecording(out, archiveDir, validRecording3, of(APPLY_CHECKSUM), crc32(), epochClock, (file) -> false));
    try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
        assertRecording(catalog, validRecording3, VALID, 963969455, 7 * TERM_LENGTH + 96, 11 * TERM_LENGTH + 320, 18, 100, 7, 13, "ch2", "src2");
    }
    verifyRecording(out, archiveDir, validRecording3, allOf(VerifyOption.class), crc32(), epochClock, (file) -> false);
    try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
        assertRecording(catalog, validRecording3, INVALID, 963969455, 7 * TERM_LENGTH + 96, 11 * TERM_LENGTH + 320, 18, 100, 7, 13, "ch2", "src2");
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) FRAME_ALIGNMENT(io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT) RECORDING_SEGMENT_SUFFIX(io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX) Catalog(io.aeron.archive.Catalog) IoUtil(org.agrona.IoUtil) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) READ(java.nio.file.StandardOpenOption.READ) ByteBuffer.allocate(java.nio.ByteBuffer.allocate) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) EnumSet.allOf(java.util.EnumSet.allOf) AeronArchive(io.aeron.archive.client.AeronArchive) Path(java.nio.file.Path) WRITE(java.nio.file.StandardOpenOption.WRITE) MethodSource(org.junit.jupiter.params.provider.MethodSource) PrintStream(java.io.PrintStream) MutableBoolean(org.agrona.collections.MutableBoolean) LogBufferDescriptor.positionBitsToShift(io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift) ArchiveTool(io.aeron.archive.ArchiveTool) Collections.emptySet(java.util.Collections.emptySet) VERIFY_ALL_SEGMENT_FILES(io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Checksum(io.aeron.archive.checksum.Checksum) Arguments(org.junit.jupiter.params.provider.Arguments) File(java.io.File) Mockito(org.mockito.Mockito) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Collections.addAll(java.util.Collections.addAll) org.junit.jupiter.api(org.junit.jupiter.api) Executable(org.junit.jupiter.api.function.Executable) APPLY_CHECKSUM(io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM) EnumSet.of(java.util.EnumSet.of) Assertions(org.junit.jupiter.api.Assertions) RecordingState(io.aeron.archive.codecs.RecordingState) EpochClock(org.agrona.concurrent.EpochClock) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Checksums.crc32(io.aeron.archive.checksum.Checksums.crc32) Archive.segmentFileName(io.aeron.archive.Archive.segmentFileName) FileChannel(java.nio.channels.FileChannel) Files.deleteIfExists(java.nio.file.Files.deleteIfExists) LogBufferDescriptor.computeTermIdFromPosition(io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition) Catalog(io.aeron.archive.Catalog) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with EpochClock

use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.

the class ArchiveToolTests method checksumRecordingAllSegmentFiles.

@Test
void checksumRecordingAllSegmentFiles() {
    checksumRecording(out, archiveDir, validRecording3, true, crc32(), epochClock);
    assertTrue(verifyRecording(out, archiveDir, validRecording3, allOf(VerifyOption.class), crc32(), epochClock, (file) -> false));
    try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
        assertRecording(catalog, validRecording3, VALID, 963969455, 7 * TERM_LENGTH + 96, 11 * TERM_LENGTH + 320, 18, 100, 7, 13, "ch2", "src2");
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) FRAME_ALIGNMENT(io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT) RECORDING_SEGMENT_SUFFIX(io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX) Catalog(io.aeron.archive.Catalog) IoUtil(org.agrona.IoUtil) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) READ(java.nio.file.StandardOpenOption.READ) ByteBuffer.allocate(java.nio.ByteBuffer.allocate) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) EnumSet.allOf(java.util.EnumSet.allOf) AeronArchive(io.aeron.archive.client.AeronArchive) Path(java.nio.file.Path) WRITE(java.nio.file.StandardOpenOption.WRITE) MethodSource(org.junit.jupiter.params.provider.MethodSource) PrintStream(java.io.PrintStream) MutableBoolean(org.agrona.collections.MutableBoolean) LogBufferDescriptor.positionBitsToShift(io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift) ArchiveTool(io.aeron.archive.ArchiveTool) Collections.emptySet(java.util.Collections.emptySet) VERIFY_ALL_SEGMENT_FILES(io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Checksum(io.aeron.archive.checksum.Checksum) Arguments(org.junit.jupiter.params.provider.Arguments) File(java.io.File) Mockito(org.mockito.Mockito) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Collections.addAll(java.util.Collections.addAll) org.junit.jupiter.api(org.junit.jupiter.api) Executable(org.junit.jupiter.api.function.Executable) APPLY_CHECKSUM(io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM) EnumSet.of(java.util.EnumSet.of) Assertions(org.junit.jupiter.api.Assertions) RecordingState(io.aeron.archive.codecs.RecordingState) EpochClock(org.agrona.concurrent.EpochClock) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Checksums.crc32(io.aeron.archive.checksum.Checksums.crc32) Archive.segmentFileName(io.aeron.archive.Archive.segmentFileName) FileChannel(java.nio.channels.FileChannel) Files.deleteIfExists(java.nio.file.Files.deleteIfExists) LogBufferDescriptor.computeTermIdFromPosition(io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition) Catalog(io.aeron.archive.Catalog) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with EpochClock

use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.

the class TestCluster method awaitResponseMessageCount.

public void awaitResponseMessageCount(final int messageCount) {
    final EpochClock epochClock = client.context().aeron().context().epochClock();
    long heartbeatDeadlineMs = epochClock.time() + TimeUnit.SECONDS.toMillis(1);
    long count;
    while ((count = responseCount.get()) < messageCount) {
        Tests.sleep(1, "count=%d awaiting=%d", count, messageCount);
        client.pollEgress();
        final long nowMs = epochClock.time();
        if (nowMs > heartbeatDeadlineMs) {
            client.sendKeepAlive();
            heartbeatDeadlineMs = nowMs + TimeUnit.SECONDS.toMillis(1);
        }
    }
}
Also used : EpochClock(org.agrona.concurrent.EpochClock)

Example 9 with EpochClock

use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.

the class TestCluster method awaitServiceState.

public void awaitServiceState(final TestNode node, final Predicate<TestNode> predicate) {
    final EpochClock epochClock = client.context().aeron().context().epochClock();
    long keepAliveDeadlineMs = epochClock.time() + TimeUnit.SECONDS.toMillis(1);
    while (!predicate.test(node)) {
        Thread.yield();
        if (Thread.interrupted()) {
            throw new TimeoutException("timeout while awaiting condition");
        }
        final long nowMs = epochClock.time();
        if (nowMs > keepAliveDeadlineMs) {
            client.sendKeepAlive();
            keepAliveDeadlineMs = nowMs + TimeUnit.SECONDS.toMillis(1);
        }
    }
}
Also used : EpochClock(org.agrona.concurrent.EpochClock) TimeoutException(io.aeron.exceptions.TimeoutException)

Example 10 with EpochClock

use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.

the class ClusterTool method nextBackupQuery.

/**
 * Set the time of the next backup query for the cluster backup.
 *
 * @param out        to print the output to.
 * @param clusterDir where the cluster is running.
 * @param delayMs    from the current time for the next backup query.
 */
public static void nextBackupQuery(final PrintStream out, final File clusterDir, final long delayMs) {
    if (markFileExists(clusterDir) || TIMEOUT_MS > 0) {
        try (ClusterMarkFile markFile = openMarkFile(clusterDir, System.out::println)) {
            if (markFile.decoder().componentType() != ClusterComponentType.BACKUP) {
                out.println("not a cluster backup node");
            } else {
                final EpochClock epochClock = SystemEpochClock.INSTANCE;
                nextBackupQueryDeadlineMs(markFile, epochClock.time() + delayMs);
                out.format("%2$tF %1$tH:%1$tM:%1$tS setting next: %2$tF %2$tH:%2$tM:%2$tS%n", new Date(), new Date(nextBackupQueryDeadlineMs(markFile)));
            }
        }
    } else {
        out.println(ClusterMarkFile.FILENAME + " does not exist.");
    }
}
Also used : ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) EpochClock(org.agrona.concurrent.EpochClock) Date(java.util.Date)

Aggregations

EpochClock (org.agrona.concurrent.EpochClock)15 APPLY_CHECKSUM (io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM)11 VERIFY_ALL_SEGMENT_FILES (io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES)11 Catalog (io.aeron.archive.Catalog)11 Checksum (io.aeron.archive.checksum.Checksum)11 INVALID (io.aeron.archive.codecs.RecordingState.INVALID)11 VALID (io.aeron.archive.codecs.RecordingState.VALID)11 LogBufferDescriptor.computeTermIdFromPosition (io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition)11 LogBufferDescriptor.positionBitsToShift (io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift)11 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)11 File (java.io.File)11 IOException (java.io.IOException)11 PrintStream (java.io.PrintStream)11 ByteBuffer (java.nio.ByteBuffer)11 FileChannel (java.nio.channels.FileChannel)11 Path (java.nio.file.Path)11 Collections.emptySet (java.util.Collections.emptySet)11 RECORDING_SEGMENT_SUFFIX (io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX)9 Archive.segmentFileName (io.aeron.archive.Archive.segmentFileName)9 ArchiveTool (io.aeron.archive.ArchiveTool)9