Search in sources :

Example 31 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class WaitForBackupsOnShutdownSystemPropertyTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    super.beforeTest();
    listeningLog = new ListeningTestLogger(log);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 32 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class IgniteSecurityProcessorTest method testThrowIllegalStateExceptionIfNodeNotFoundInDiscoCache.

/**
 * Checks that {@link IgniteSecurityProcessor#withContext(UUID)} throws exception in case a node ID is unknown.
 */
@Test
public void testThrowIllegalStateExceptionIfNodeNotFoundInDiscoCache() {
    GridKernalContext ctx = mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(new IgniteConfiguration());
    when(ctx.discovery()).thenReturn(mock(GridDiscoveryManager.class));
    LogListener logLsnr = LogListener.matches(s -> s.contains("Failed to obtain a security context.")).times(1).build();
    ListeningTestLogger log = new ListeningTestLogger(false);
    log.registerListener(logLsnr);
    when(ctx.log(IgniteSecurityProcessor.class)).thenReturn(log);
    GridSecurityProcessor secPrc = mock(GridSecurityProcessor.class);
    IgniteSecurityProcessor ignSecPrc = new IgniteSecurityProcessor(ctx, secPrc);
    assertThrowsWithCause(() -> ignSecPrc.withContext(UUID.randomUUID()), IllegalStateException.class);
    assertTrue(logLsnr.check());
}
Also used : GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) LogListener(org.apache.ignite.testframework.LogListener) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) Test(org.junit.Test)

Example 33 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class PerformanceStatisticsRotateFileTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    listeningLog = new ListeningTestLogger(log);
    startGrids(NODES_CNT - 1);
    startClientGrid(NODES_CNT);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 34 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class IgniteSnapshotManagerSelfTest method testSnapshotAlwaysStartsNewCheckpoint.

/**
 * @throws Exception If fails.
 */
@Test
public void testSnapshotAlwaysStartsNewCheckpoint() throws Exception {
    long testTimeout = 30_000;
    listenLog = new ListeningTestLogger(log);
    LogListener lsnr = LogListener.matches("Snapshot operation is scheduled on local node").times(1).build();
    listenLog.registerListener(lsnr);
    IgniteEx ignite = startGridsWithCache(1, 4096, key -> new Account(key, key), new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    assertTrue("Test requires that only forced checkpoints were allowed.", ignite.configuration().getDataStorageConfiguration().getCheckpointFrequency() >= TimeUnit.DAYS.toMillis(365));
    GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
    // Ensure that previous checkpoint finished.
    dbMgr.getCheckpointer().currentProgress().futureFor(CheckpointState.FINISHED).get(testTimeout);
    CountDownLatch beforeCpEnter = new CountDownLatch(1);
    CountDownLatch beforeCpExit = new CountDownLatch(1);
    // Block checkpointer on start.
    dbMgr.addCheckpointListener(new CheckpointListener() {

        @Override
        public void beforeCheckpointBegin(CheckpointListener.Context ctx) throws IgniteCheckedException {
            beforeCpEnter.countDown();
            U.await(beforeCpExit, testTimeout, TimeUnit.MILLISECONDS);
        }

        @Override
        public void onMarkCheckpointBegin(CheckpointListener.Context ctx) {
        // No-op.
        }

        @Override
        public void onCheckpointBegin(CheckpointListener.Context ctx) {
        // No-op.
        }
    });
    dbMgr.forceCheckpoint("snapshot-task-hang-test");
    beforeCpEnter.await(testTimeout, TimeUnit.MILLISECONDS);
    IgniteFuture<Void> snpFut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
    // Wait until the snapshot task checkpoint listener is registered.
    assertTrue(GridTestUtils.waitForCondition(lsnr::check, testTimeout));
    // Unblock checkpointer.
    beforeCpExit.countDown();
    // Make sure the snapshot has been taken.
    snpFut.get(testTimeout);
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Example 35 with ListeningTestLogger

use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.

the class DiagnosticProcessorTest method testOutputDiagnosticCorruptedPagesInfo.

/**
 * Check that when an CorruptedTreeException is thrown, a "corruptedPages_TIMESTAMP.txt"
 * will be created and a warning will be in the log.
 *
 * @throws Exception If failed.
 */
@Test
public void testOutputDiagnosticCorruptedPagesInfo() throws Exception {
    ListeningTestLogger listeningTestLog = new ListeningTestLogger(GridAbstractTest.log);
    IgniteEx n = startGrid(0, cfg -> {
        cfg.setGridLogger(listeningTestLog);
    });
    n.cluster().state(ClusterState.ACTIVE);
    awaitPartitionMapExchange();
    for (int i = 0; i < 10_000; i++) n.cache(DEFAULT_CACHE_NAME).put(i, "val_" + i);
    assertNotNull(n.context().diagnostic());
    T2<Integer, Long> anyPageId = findAnyPageId(n);
    assertNotNull(anyPageId);
    LogListener logLsnr = LogListener.matches("CorruptedTreeException has occurred. " + "To diagnose it, make a backup of the following directories: ").build();
    listeningTestLog.registerListener(logLsnr);
    n.context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, new CorruptedTreeException("Test ex", null, DEFAULT_CACHE_NAME, anyPageId.get1(), anyPageId.get2())));
    assertTrue(logLsnr.check());
    Path diagnosticPath = getFieldValue(n.context().diagnostic(), "diagnosticPath");
    List<File> corruptedPagesFiles = Arrays.stream(diagnosticPath.toFile().listFiles()).filter(f -> corruptedPagesFileNamePattern().matcher(f.getName()).matches()).collect(toList());
    assertEquals(1, corruptedPagesFiles.size());
    assertTrue(corruptedPagesFiles.get(0).length() > 0);
}
Also used : Path(java.nio.file.Path) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Arrays(java.util.Arrays) DiagnosticProcessor.walDirs(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.walDirs) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FailureContext(org.apache.ignite.failure.FailureContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Path(java.nio.file.Path) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) SegmentRouter(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentRouter) DFLT_WAL_PATH(org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH) F(org.apache.ignite.internal.util.typedef.F) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) LongStream(java.util.stream.LongStream) FailureType(org.apache.ignite.failure.FailureType) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) DEFAULT_TARGET_FOLDER(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.DEFAULT_TARGET_FOLDER) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Test(org.junit.Test) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collectors.toList(java.util.stream.Collectors.toList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Pattern(java.util.regex.Pattern) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) FailureContext(org.apache.ignite.failure.FailureContext) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) File(java.io.File) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)101 Test (org.junit.Test)51 LogListener (org.apache.ignite.testframework.LogListener)48 IgniteEx (org.apache.ignite.internal.IgniteEx)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)30 Ignite (org.apache.ignite.Ignite)21 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)21 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)17 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)14 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 List (java.util.List)8 Pattern (java.util.regex.Pattern)8 ClusterState (org.apache.ignite.cluster.ClusterState)7 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)7 Collections (java.util.Collections)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6