Search in sources :

Example 31 with GridStringLogger

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

the class LongJVMPauseDetectorTest method testStopWorkerThread.

/**
 * @throws Exception If failed.
 */
@Test
public void testStopWorkerThread() throws Exception {
    strLog = new GridStringLogger(true);
    strLog.logLength(300_000);
    startGrid(0);
    stopGrid(0);
    String log = strLog.toString();
    assertFalse(log.contains("jvm-pause-detector-worker has been interrupted."));
    assertTrue(log.contains("jvm-pause-detector-worker has been stopped."));
}
Also used : GridStringLogger(org.apache.ignite.testframework.GridStringLogger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 32 with GridStringLogger

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

the class IgniteMassLoadSandboxTest method testCoveredWalLogged.

/**
 * Test that WAL segments that are fully covered by checkpoint are logged
 *
 * @throws Exception if failed.
 */
@Test
public void testCoveredWalLogged() throws Exception {
    GridStringLogger log0 = null;
    try {
        log0 = new GridStringLogger();
        final IgniteConfiguration cfg = getConfiguration("testCoveredWalLogged");
        cfg.setGridLogger(log0);
        cfg.getDataStorageConfiguration().setWalAutoArchiveAfterInactivity(10);
        final Ignite ignite = G.start(cfg);
        ignite.cluster().active(true);
        final IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME);
        cache.put(1, new byte[cfg.getDataStorageConfiguration().getWalSegmentSize() - 1024]);
        forceCheckpoint();
        cache.put(1, new byte[cfg.getDataStorageConfiguration().getWalSegmentSize() - 1024]);
        forceCheckpoint();
        cache.put(1, new byte[cfg.getDataStorageConfiguration().getWalSegmentSize() - 1024]);
        forceCheckpoint();
        // needed by GridStringLogger
        Thread.sleep(200);
        final String log = log0.toString();
        final String[] lines = log.split("\\r?\\n");
        final Pattern chPtrn = Pattern.compile("Checkpoint finished");
        final Pattern idxPtrn = Pattern.compile("idx=([0-9]+),");
        final Pattern covererdPtrn = Pattern.compile("walSegmentsCovered=\\[(.+)\\], ");
        boolean hasCheckpoint = false;
        long nextCovered = 0;
        for (String line : lines) {
            if (!chPtrn.matcher(line).find())
                continue;
            hasCheckpoint = true;
            final Matcher idxMatcher = idxPtrn.matcher(line);
            assertTrue(idxMatcher.find());
            final long idx = Long.valueOf(idxMatcher.group(1));
            final Matcher coveredMatcher = covererdPtrn.matcher(line);
            if (!coveredMatcher.find()) {
                // no wal segments are covered by checkpoint
                assertEquals(nextCovered, idx);
                continue;
            }
            final String coveredMatcherGrp = coveredMatcher.group(1);
            final long[] covered = !coveredMatcherGrp.isEmpty() ? Arrays.stream(coveredMatcherGrp.split(" - ")).mapToLong(e -> Integer.valueOf(e.trim())).toArray() : new long[0];
            assertEquals(nextCovered, covered[0]);
            final long lastCovered = covered[covered.length - 1];
            // current wal is excluded
            assertEquals(idx - 1, lastCovered);
            nextCovered = lastCovered + 1;
        }
        assertTrue(hasCheckpoint);
    } finally {
        System.out.println(log0 != null ? log0.toString() : "Error initializing GridStringLogger");
        stopAllGrids();
    }
}
Also used : Pattern(java.util.regex.Pattern) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Matcher(java.util.regex.Matcher) GridStringLogger(org.apache.ignite.testframework.GridStringLogger) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 33 with GridStringLogger

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

the class IgniteDevOnlyLogTest method testDevOnlyQuietMessage.

/**
 * Check that dev-only messages appear in the log.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-9328")
@Test
public void testDevOnlyQuietMessage() throws Exception {
    additionalArgs = Collections.singletonList("-D" + IgniteSystemProperties.IGNITE_QUIET + "=true");
    log = new GridStringLogger(false, grid(0).log());
    Ignite ignite = startGrid(1);
    String msg = getMessage(ignite);
    warnDevOnly(msg);
    assertTrue(log.toString().contains(msg));
}
Also used : GridStringLogger(org.apache.ignite.testframework.GridStringLogger) Ignite(org.apache.ignite.Ignite) Ignore(org.junit.Ignore) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 34 with GridStringLogger

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

the class IgniteDevOnlyLogTest method testDevOnlyVerboseMessage.

/**
 * Check that dev-only messages appear in the log.
 */
@Test
public void testDevOnlyVerboseMessage() throws Exception {
    additionalArgs = Collections.singletonList("-D" + IgniteSystemProperties.IGNITE_QUIET + "=false");
    log = new GridStringLogger(false, grid(0).log());
    Ignite ignite = startGrid(1);
    String msg = getMessage(ignite);
    warnDevOnly(msg);
    assertTrue(log.toString().contains(msg));
}
Also used : GridStringLogger(org.apache.ignite.testframework.GridStringLogger) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 35 with GridStringLogger

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

the class IgniteDiagnosticMessagesTest method checkRemoteTx.

/**
 * @param atomicityMode Cache atomicity mode.
 * @throws Exception If failed.
 */
public void checkRemoteTx(CacheAtomicityMode atomicityMode) throws Exception {
    int timeout = 3500;
    System.setProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, String.valueOf(timeout));
    try {
        testSpi = true;
        startGrid(0);
        GridStringLogger strLog = this.strLog = new GridStringLogger();
        strLog.logLength(1024 * 100);
        startGrid(1);
        awaitPartitionMapExchange();
        CacheConfiguration ccfg = cacheConfiguration(atomicityMode).setBackups(1);
        if (atomicityMode != TRANSACTIONAL_SNAPSHOT || MvccFeatureChecker.isSupported(MvccFeatureChecker.Feature.NEAR_CACHE))
            ccfg.setNearConfiguration(new NearCacheConfiguration<>());
        final Ignite node0 = ignite(0);
        final Ignite node1 = ignite(1);
        node0.createCache(ccfg);
        UUID id0 = node0.cluster().localNode().id();
        TestRecordingCommunicationSpi.spi(node0).blockMessages(GridDhtTxPrepareResponse.class, node1.name());
        int txCnt = 4;
        final List<Integer> keys = primaryKeys(node1.cache(DEFAULT_CACHE_NAME), txCnt, 0);
        final AtomicInteger idx = new AtomicInteger();
        IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME);
                try (Transaction tx = node1.transactions().txStart()) {
                    Integer key = keys.get(idx.getAndIncrement());
                    cache.getAndPut(key, "new-" + key);
                    tx.commit();
                }
                return null;
            }
        }, txCnt, "tx");
        U.sleep(timeout * 2);
        assertFalse(fut.isDone());
        TestRecordingCommunicationSpi.spi(node0).stopBlock();
        fut.get();
        String log = strLog.toString();
        assertTrue(log.contains("Related transactions ["));
        assertTrue(log.contains("General node info [id=" + id0));
    } finally {
        System.clearProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT);
    }
}
Also used : GridStringLogger(org.apache.ignite.testframework.GridStringLogger) IgniteCache(org.apache.ignite.IgniteCache) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridStringLogger (org.apache.ignite.testframework.GridStringLogger)37 Ignite (org.apache.ignite.Ignite)22 Test (org.junit.Test)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)9 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)9 UUID (java.util.UUID)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Transaction (org.apache.ignite.transactions.Transaction)5 URLClassLoader (java.net.URLClassLoader)4 IgniteCache (org.apache.ignite.IgniteCache)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)2 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)2 File (java.io.File)1 Callable (java.util.concurrent.Callable)1