Search in sources :

Example 41 with LogListener

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

the class EvictionPolicyFailureHandlerTest method testCacheMapDoesNotContainsWrongEntityAfterTransaction.

/**
 * We expect that localPeek produces an exception, but the entry evict returns false because the transaction locks
 * this entry. After transaction commit, the entry will be evicted.
 */
@Test
public void testCacheMapDoesNotContainsWrongEntityAfterTransaction() throws Exception {
    LogListener lsnr = LogListener.matches(s -> s.contains("The cache entry cannot be touched")).times(1).build();
    log.registerListener(lsnr);
    IgniteEx node = startGrid(0);
    IgniteEx client = startClientGrid(1);
    GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
    cache.put(1, 1);
    CountDownLatch locPeekFinished = new CountDownLatch(1);
    CountDownLatch txStarted = new CountDownLatch(1);
    CountDownLatch txFinished = new CountDownLatch(1);
    GridTestUtils.runAsync(() -> {
        IgniteCache<Object, Object> cache1 = client.cache(DEFAULT_CACHE_NAME);
        IgniteTransactions transactions = client.transactions();
        try (Transaction tx = transactions.txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache1.put(2.1, 2.4);
            txStarted.countDown();
            locPeekFinished.await();
            tx.commit();
        } catch (Exception ignore) {
        }
        txFinished.countDown();
    }, "tx-thread");
    txStarted.await();
    try {
        cache.localPeek(2.1, new CachePeekMode[] { CachePeekMode.ONHEAP });
    } catch (Exception ignore) {
    }
    locPeekFinished.countDown();
    assertTrue(lsnr.check(10_000));
    txFinished.await();
    assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> new Double(2.1).equals(e.key().value(null, false))));
    assertEquals(ACTIVE, node.cluster().state());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Affinity(org.apache.ignite.cache.affinity.Affinity) Transaction(org.apache.ignite.transactions.Transaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) Factory(javax.cache.configuration.Factory) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CachePeekMode(org.apache.ignite.cache.CachePeekMode) FailureHandler(org.apache.ignite.failure.FailureHandler) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) SortedEvictionPolicy(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) SortedEvictionPolicyFactory(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicyFactory) CountDownLatch(java.util.concurrent.CountDownLatch) EvictionPolicy(org.apache.ignite.cache.eviction.EvictionPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IgniteTransactions(org.apache.ignite.IgniteTransactions) EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry) IgniteKernal(org.apache.ignite.internal.IgniteKernal) LogListener(org.apache.ignite.testframework.LogListener) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteTransactions(org.apache.ignite.IgniteTransactions) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 42 with LogListener

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

the class ExpiryPolicyInfoLoggingTest method checkLoggingExpiryInfoForDynamicallyCreatedCache.

/**
 * Checking logging of expiry policy info for dynamically created cache.
 */
@Test
public void checkLoggingExpiryInfoForDynamicallyCreatedCache() throws Exception {
    LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(STARTED_CACHE_MSG, CACHE_2_NAME)) && s.contains(String.format(EXPRITY_POLICY_MSG, AccessedExpiryPolicy.class.getName(), false))).times(1).build();
    log.registerListener(lsnr);
    IgniteEx srv = startGrid(0);
    srv.createCache(new CacheConfiguration<>(CACHE_2_NAME).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5))).setEagerTtl(false));
    assertTrue(lsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) Duration(javax.cache.expiry.Duration) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 43 with LogListener

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

the class ExpiryPolicyInfoLoggingTest method checkLoggingExpiryInfoForStaticallyCreatedCache.

/**
 * Checking logging of expiry policy info for statically created cache.
 */
@Test
public void checkLoggingExpiryInfoForStaticallyCreatedCache() throws Exception {
    LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(STARTED_CACHE_MSG, CACHE_1_NAME)) && s.contains(String.format(EXPRITY_POLICY_MSG, ModifiedExpiryPolicy.class.getName(), true))).times(1).build();
    log.registerListener(lsnr);
    startGrid(0);
    assertTrue(lsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 44 with LogListener

use of org.apache.ignite.testframework.LogListener 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 45 with LogListener

use of org.apache.ignite.testframework.LogListener 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

LogListener (org.apache.ignite.testframework.LogListener)144 Test (org.junit.Test)116 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)93 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)68 IgniteEx (org.apache.ignite.internal.IgniteEx)65 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)35 Ignite (org.apache.ignite.Ignite)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)31 IgniteCache (org.apache.ignite.IgniteCache)24 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)23 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)18 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)16 List (java.util.List)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 Pattern (java.util.regex.Pattern)15 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 UUID (java.util.UUID)12 Collections (java.util.Collections)11