Search in sources :

Example 71 with LogListener

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

the class IgniteWalRebalanceLoggingTest method checkFollowingPartitionsWereReservedForPotentialHistoryRebalanceMsg.

/**
 * Test utility method.
 *
 * @param lsnrs Listeners to register with server logger.
 * @throws Exception If failed.
 */
private void checkFollowingPartitionsWereReservedForPotentialHistoryRebalanceMsg(LogListener... lsnrs) throws Exception {
    startGridsMultiThreaded(2).cluster().active(true);
    IgniteCache<Integer, String> cache1 = createCache("cache1", "cache_group1");
    IgniteCache<Integer, String> cache2 = createCache("cache2", "cache_group2");
    for (int i = 0; i < KEYS_LOW_BORDER; i++) {
        cache1.put(i, "abc" + i);
        cache2.put(i, "abc" + i);
        if (i % 20 == 0)
            forceCheckpointAndRollOwerWal();
    }
    stopGrid(1);
    for (int i = KEYS_LOW_BORDER; i < KEYS_UPPER_BORDER; i++) {
        cache1.put(i, "abc" + i);
        cache2.put(i, "abc" + i);
        if (i % 20 == 0)
            forceCheckpointAndRollOwerWal();
    }
    srvLog.clearListeners();
    for (LogListener lsnr : lsnrs) srvLog.registerListener(lsnr);
    startGrid(1);
    awaitPartitionMapExchange(false, true, null);
}
Also used : LogListener(org.apache.ignite.testframework.LogListener)

Example 72 with LogListener

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

the class TransactionSensitiveDataTest method checkSensitiveDataDuringExchange.

/**
 * Receiving a log message "Partition release future:" during the exchange
 * to check whether or not sensitive data is in printed transactions.
 *
 * @param check Check sensitive data in log message.
 * @throws Exception If failed.
 */
private void checkSensitiveDataDuringExchange(BiConsumer<String, String> check) throws Exception {
    assert nonNull(check);
    IgniteEx crd = startGrids(NODE_COUNT);
    awaitPartitionMapExchange();
    AtomicReference<String> strToCheckRef = new AtomicReference<>();
    LogListener logLsnr = LogListener.matches(logStr -> {
        if (logStr.contains("Partition release future:") && currentThread().getName().contains(crd.name())) {
            strToCheckRef.set(logStr);
            return true;
        }
        return false;
    }).build();
    testLog.registerListener(logLsnr);
    IgniteCache<Object, Object> cache = crd.getOrCreateCache(DEFAULT_CACHE_NAME).withKeepBinary();
    IgniteBinary binary = crd.binary();
    BinaryObject binKey = binary.toBinary(new Key(0));
    BinaryObject binPerson = binary.toBinary(new Person(1, "name_1"));
    cache.put(binKey, binPerson);
    Transaction tx = crd.transactions().txStart();
    cache.put(binKey, binPerson);
    GridTestUtils.runAsync(() -> {
        logLsnr.check(10 * crd.configuration().getNetworkTimeout());
        tx.commit();
        return null;
    });
    startGrid(NODE_COUNT);
    check.accept(maskIdHash(strToCheckRef.get()), maskIdHash(toStr(binKey, Key.class)));
    check.accept(maskIdHash(strToCheckRef.get()), maskIdHash(toStr(binPerson, Person.class)));
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteEx(org.apache.ignite.internal.IgniteEx) Thread.currentThread(java.lang.Thread.currentThread) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) AtomicReference(java.util.concurrent.atomic.AtomicReference) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) BiConsumer(java.util.function.BiConsumer) IgniteBinary(org.apache.ignite.IgniteBinary) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) IGNITE_TO_STRING_INCLUDE_SENSITIVE(org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridNearTxPrepareFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareFutureAdapter) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) GridTestUtils.setFieldValue(org.apache.ignite.testframework.GridTestUtils.setFieldValue) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Objects.nonNull(java.util.Objects.nonNull) LogListener(org.apache.ignite.testframework.LogListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteBinary(org.apache.ignite.IgniteBinary) BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 73 with LogListener

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

the class TcpDiscoveryIpFinderFailureTest method runClientNodeIpFinderFailureTest.

/**
 */
private void runClientNodeIpFinderFailureTest(long reconnectDelay) throws Exception {
    List<LogListener> listeners = new ArrayList<>();
    listeners.add(LogListener.matches("Failed to get registered addresses from IP " + "finder (retrying every " + reconnectDelay + "ms; change 'reconnectDelay' to configure " + "the frequency of retries) [maxTimeout=4000]").build());
    listeners.add(LogListener.matches("Unable to get registered addresses from IP finder," + " timeout is reached (consider increasing 'joinTimeout' for join process or " + "'netTimeout' for reconnection) [joinTimeout=10000, netTimeout=4000]").build());
    listeners.forEach(listeningLog::registerListener);
    IgniteConfiguration cfgSrv = getConfigurationDynamicIpFinder("Server", false);
    TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
    discoverySpi.setJoinTimeout(10000);
    discoverySpi.setNetworkTimeout(4000);
    discoverySpi.setReconnectDelay((int) reconnectDelay);
    discoverySpi.setIpFinder(dynamicIpFinder);
    IgniteConfiguration cfgClient = getConfigurationDynamicIpFinder("Client", true, discoverySpi);
    IgniteEx crd = startGrid(cfgSrv);
    IgniteEx client = startGrid(cfgClient);
    waitForTopology(2);
    dynamicIpFinder.breakService();
    Ignition.stop(crd.name(), true);
    CountDownLatch latch = new CountDownLatch(1);
    client.events().localListen(event -> {
        listeners.forEach(lsnr -> assertTrue(lsnr.check()));
        latch.countDown();
        return true;
    }, EVT_CLIENT_NODE_DISCONNECTED);
    assertTrue("Failed to wait for client node disconnected.", latch.await(6, SECONDS));
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 74 with LogListener

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

the class TcpDiscoveryMetricsWarnLogTest method testMetricsWarningLog.

/**
 * Test checks that the desired message occurs in logs.
 *
 * @throws Exception If any error occurs.
 */
@Test
@WithSystemProperty(key = IGNITE_DISCOVERY_METRICS_QNT_WARN, value = "20")
public void testMetricsWarningLog() throws Exception {
    testLog.warning("IGNITE_DISCOVERY_METRICS_QNT_WARN = " + System.getProperty(IGNITE_DISCOVERY_METRICS_QNT_WARN));
    LogListener logLsnr0 = LogListener.matches(LOG_MSG).andMatches("TcpDiscoveryMetricsWarnLogTest0").atLeast(1).build();
    LogListener logLsnr1 = LogListener.matches(LOG_MSG).andMatches("TcpDiscoveryMetricsWarnLogTest1").atLeast(1).build();
    LogListener logLsnr2 = LogListener.matches(LOG_MSG).andMatches("TcpDiscoveryMetricsWarnLogTest2").atLeast(1).build();
    testLog.registerListener(logLsnr0);
    testLog.registerListener(logLsnr1);
    testLog.registerListener(logLsnr2);
    Ignite ignite0 = startGrid(0);
    startGrid(1);
    startClientGrid(2);
    for (int i = 1; i <= 30; i++) createAndFillCache(i, ignite0);
    awaitMetricsUpdate(3);
    assertTrue(logLsnr0.check());
    assertTrue(logLsnr1.check());
    assertTrue(logLsnr2.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 75 with LogListener

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

the class GridIndexRebuildTest method testPartialIndexRebuild.

/**
 * We start several nodes, populate caches, then start replacing values. After that one node is killed, new index
 * created. Finally, we restart the node, index rebuild starting after recovery. And we checke indexes by "validate
 * indexes" task.
 */
@SuppressWarnings("unchecked")
@Test
public void testPartialIndexRebuild() throws Exception {
    LogListener lsnr = LogListener.matches("B+Tree is corrupted").build();
    listeningLog.registerListener(lsnr);
    long start = System.currentTimeMillis();
    IgniteEx grid1 = startGrids(4);
    grid1.cluster().active(true);
    final int accountCnt = 2048;
    try (IgniteDataStreamer streamer = grid1.dataStreamer(SECOND_CACHE)) {
        for (long i = 0; i < accountCnt; i++) streamer.addData(i, new Account(i));
        streamer.flush();
    }
    AtomicBoolean stop = new AtomicBoolean();
    IgniteCache<Object, Object> cache2 = grid1.cache(SECOND_CACHE);
    new Thread(new Runnable() {

        @Override
        public void run() {
            long i = 0;
            while (!stop.get()) {
                try {
                    if (i % 13 == 7)
                        cache2.put(i, new Account2(i));
                    else
                        cache2.put(i, new Account(i));
                    i++;
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    long diff = System.currentTimeMillis() - start;
    U.sleep(7500 - (diff % 5000));
    stopGrid(3);
    stop.set(true);
    cache2.query(new SqlFieldsQuery("CREATE INDEX idx" + UUID.randomUUID().toString().replaceAll("-", "_") + " on Account (amount)")).getAll();
    startGrid(3);
    awaitPartitionMapExchange();
    U.sleep(3_000);
    ImmutableSet<UUID> nodes = ImmutableSet.of(grid(2).localNode().id(), grid(3).localNode().id());
    VisorValidateIndexesTaskArg arg = new VisorValidateIndexesTaskArg(null, null, 10000, 1, true, true);
    VisorTaskArgument<VisorValidateIndexesTaskArg> visorTaskArg = new VisorTaskArgument<>(nodes, arg, true);
    ComputeTaskInternalFuture<VisorValidateIndexesTaskResult> execute = grid1.context().task().execute(new VisorValidateIndexesTask(), visorTaskArg);
    VisorValidateIndexesTaskResult res = execute.get();
    Map<UUID, VisorValidateIndexesJobResult> results = res.results();
    boolean hasIssue = false;
    for (VisorValidateIndexesJobResult jobResult : results.values()) {
        System.err.println(jobResult);
        hasIssue |= jobResult.hasIssues();
    }
    assertFalse(hasIssue);
    assertFalse("B+Tree is corrupted.", lsnr.check());
}
Also used : VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) UUID(java.util.UUID) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) LogListener(org.apache.ignite.testframework.LogListener) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) VisorValidateIndexesTask(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) 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