Search in sources :

Example 21 with LogListener

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

the class CacheExchangeMergeTest method testNoConcurrentModificationExceptionAfterMergeExchanges.

/**
 * Test checks that there will be no {@link ConcurrentModificationException}
 * when merging exchanges and iterating over {@link ExchangeDiscoveryEvents#events} at the same time.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoConcurrentModificationExceptionAfterMergeExchanges() throws Exception {
    testSpi = true;
    LogListener logLsnr = matches("Merge exchange future on finish [").build();
    listeningLog.registerAllListeners(logLsnr);
    AtomicBoolean stop = new AtomicBoolean();
    Collection<Exception> exceptions = new ConcurrentLinkedQueue<>();
    try {
        startGrid(0);
        for (int i = 1; i < 9; i++) {
            IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(i));
            TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) cfg.getCommunicationSpi());
            spi.blockMessages((node, msg) -> delay(msg));
            runAsync(() -> startGrid(cfg), "create-node-" + cfg.getIgniteInstanceName());
            spi.waitForBlocked();
        }
        List<Ignite> allNodes = IgnitionEx.allGridsx();
        CountDownLatch latch = new CountDownLatch(allNodes.size());
        for (Ignite gridEx : allNodes) {
            runAsync(() -> {
                Collection<DiscoveryEvent> evts = ((IgniteEx) gridEx).context().cache().context().exchange().lastTopologyFuture().events().events();
                latch.countDown();
                int i = 0;
                while (!stop.get()) {
                    try {
                        for (DiscoveryEvent evt : evts) {
                            if (nonNull(evt))
                                i++;
                        }
                    } catch (ConcurrentModificationException e) {
                        exceptions.add(e);
                        log.error("i = " + i, e);
                        break;
                    }
                }
            }, "get-ex-" + gridEx.configuration().getIgniteInstanceName());
        }
        for (Ignite node : allNodes) TestRecordingCommunicationSpi.spi(node).stopBlock();
        latch.await();
        awaitPartitionMapExchange();
    } finally {
        stop.set(true);
    }
    assertTrue(logLsnr.check());
    assertTrue(exceptions.isEmpty());
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LogListener(org.apache.ignite.testframework.LogListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentModificationException(java.util.ConcurrentModificationException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with LogListener

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

the class GridCacheRebalancingUnmarshallingFailedSelfTest method runTest.

/**
 * @throws Exception e.
 */
private void runTest() throws Exception {
    customLog = new ListeningTestLogger(log);
    LogListener unmarshalErrorLogListener = LogListener.matches(UNMARSHALING_ERROR_PATTERN).atLeast(1).build();
    customLog.registerListener(unmarshalErrorLogListener);
    assert marshaller != null;
    readCnt.set(Integer.MAX_VALUE);
    startGrid(0);
    for (int i = 0; i < 100; i++) grid(0).cache(CACHE).put(new TestKey(String.valueOf(i)), i);
    readCnt.set(1);
    startGrid(1);
    readCnt.set(Integer.MAX_VALUE);
    for (int i = 0; i < 50; i++) assert grid(1).cache(CACHE).get(new TestKey(String.valueOf(i))) != null;
    stopGrid(0);
    for (int i = 50; i < 100; i++) assertNull(grid(1).cache(CACHE).get(new TestKey(String.valueOf(i))));
    assertTrue("Unmarshal log error message is not valid.", unmarshalErrorLogListener.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 23 with LogListener

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

the class CorruptedTreeFailureHandlingTest method testCorruptedPage.

/**
 * Check that if a corrupted page exists, an {@link CorruptedTreeException}
 * will be thrown and a diagnostic file will be generated.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorruptedPage() throws Exception {
    IgniteEx srv = startGrid(0);
    File diagnosticDir = new File(srv.context().config().getWorkDirectory(), "diagnostic");
    FileUtils.deleteDirectory(diagnosticDir);
    srv.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, Integer> cache = srv.getOrCreateCache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 10; i++) cache.put(i, i);
    int pageSize = srv.configuration().getDataStorageConfiguration().getPageSize();
    int grpId = srv.context().cache().cacheGroups().stream().filter(context -> context.cacheOrGroupName().equals(DEFAULT_CACHE_NAME)).findAny().orElseThrow(() -> new RuntimeException("Cache group not found")).groupId();
    stopGrid(0, false);
    // Node is stopped, we're ready to corrupt partition data.
    long link = linkRef.get();
    long pageId = PageIdUtils.pageId(link);
    int itemId = PageIdUtils.itemId(link);
    ByteBuffer pageBuf = ByteBuffer.allocateDirect(pageSize);
    OpenOption[] options = { StandardOpenOption.READ, StandardOpenOption.WRITE };
    try (RandomAccessFileIO fileIO = new RandomAccessFileIO(fileRef.get(), options)) {
        DataPageIO dataPageIO = DataPageIO.VERSIONS.latest();
        long pageOff = pageSize + PageIdUtils.pageIndex(pageId) * pageSize;
        // Read index page.
        fileIO.position(pageOff);
        fileIO.readFully(pageBuf);
        long pageAddr = GridUnsafe.bufferAddress(pageBuf);
        // Remove existing item from index page.
        dataPageIO.removeRow(pageAddr, itemId, pageSize);
        // Recalculate CRC.
        PageIO.setCrc(pageAddr, 0);
        pageBuf.rewind();
        PageIO.setCrc(pageAddr, FastCrc.calcCrc(pageBuf, pageSize));
        // Write it back.
        pageBuf.rewind();
        fileIO.position(pageOff);
        fileIO.writeFully(pageBuf);
    }
    LogListener logLsnr = LogListener.matches("CorruptedTreeException has occurred. " + "To diagnose it, make a backup of the following directories: ").build();
    srv = startGrid(0, cfg -> {
        cfg.setGridLogger(new ListeningTestLogger(cfg.getGridLogger(), logLsnr));
    });
    // Add modified page to WAL so it won't be restored to previous (valid) state.
    pageBuf.rewind();
    ByteBuffer cpBuf = ByteBuffer.allocate(pageBuf.capacity());
    cpBuf.put(pageBuf);
    PageSnapshot pageSnapshot = new PageSnapshot(new FullPageId(pageId, grpId), cpBuf.array(), pageSize);
    srv.context().cache().context().wal().log(pageSnapshot);
    // Access cache.
    cache = srv.cache(DEFAULT_CACHE_NAME);
    try {
        for (int i = 0; i < CACHE_ENTRIES; i++) cache.get(i);
        fail("Cache operations are expected to fail");
    } catch (Throwable e) {
        assertTrue(X.hasCause(e, CorruptedTreeException.class));
    }
    assertTrue(GridTestUtils.waitForCondition(() -> G.allGrids().isEmpty(), 10_000L));
    assertTrue(diagnosticDir.exists());
    assertTrue(diagnosticDir.isDirectory());
    Pattern corruptedPagesFileNamePtrn = corruptedPagesFileNamePattern();
    File[] txtFiles = diagnosticDir.listFiles((dir, name) -> corruptedPagesFileNamePtrn.matcher(name).matches());
    assertFalse(F.isEmpty(txtFiles));
    assertEquals(1, txtFiles.length);
    assertTrue(logLsnr.check());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) RandomAccessFileIO(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIO) ClusterState(org.apache.ignite.cluster.ClusterState) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) MvccDataLeafIO(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataLeafIO) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) Before(org.junit.Before) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FailureHandler(org.apache.ignite.failure.FailureHandler) Test(org.junit.Test) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) DataLeafIO(org.apache.ignite.internal.processors.cache.tree.DataLeafIO) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FastCrc(org.apache.ignite.internal.processors.cache.persistence.wal.crc.FastCrc) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) Pattern(java.util.regex.Pattern) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) Pattern(java.util.regex.Pattern) LogListener(org.apache.ignite.testframework.LogListener) RandomAccessFileIO(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIO) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) ByteBuffer(java.nio.ByteBuffer) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) IgniteEx(org.apache.ignite.internal.IgniteEx) File(java.io.File) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with LogListener

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

the class EagerTtlTest method testNotEagerExpireOnPut.

/**
 * Checks that an assertion error does not happen during expiration in transactions.
 *
 * @throws Exception If failed.
 */
@Test
public void testNotEagerExpireOnPut() throws Exception {
    eagerTtl = false;
    IgniteEx ignite = startGrid(0);
    ignite.cluster().state(ClusterState.ACTIVE);
    LogListener assertListener = LogListener.matches(ANY_ASSERTION_ERR).build();
    listeningLog.registerListener(assertListener);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < ENTRIES; i++) cache.put(i, i);
    for (TransactionIsolation isolation : TransactionIsolation.values()) {
        U.sleep(EXPIRATION_TIME);
        for (int i = 0; i < ENTRIES; i++) {
            try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.OPTIMISTIC, isolation)) {
                if (i % 2 == 0)
                    cache.putAll(Collections.singletonMap(i, isolation.ordinal() + 1));
                else
                    cache.getAndPut(i, isolation.ordinal() + 1);
                tx.commit();
            }
        }
    }
    assertFalse(GridTestUtils.waitForCondition(assertListener::check, 2_000));
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 25 with LogListener

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

the class ListeningTestLoggerTest method testUnregister.

/**
 * Checks that re-register works fine.
 */
@Test
public void testUnregister() {
    String msg = "catch me";
    LogListener lsnr1 = LogListener.matches(msg).times(1).build();
    LogListener lsnr2 = LogListener.matches(msg).times(2).build();
    log.registerListener(lsnr1);
    log.registerListener(lsnr2);
    log.info(msg);
    log.unregisterListener(lsnr1);
    log.info(msg);
    assertTrue(lsnr1.check());
    assertTrue(lsnr2.check());
    // Repeat these steps to ensure that the state is cleared during registration.
    log.registerListener(lsnr1);
    log.registerListener(lsnr2);
    log.info(msg);
    log.unregisterListener(lsnr1);
    log.info(msg);
    assertTrue(lsnr1.check());
    assertTrue(lsnr2.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) 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