Search in sources :

Example 1 with ListeningTestLogger

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

the class GridCacheHashMapPutAllWarningsTest method testHashSetGetAllTx.

/**
 * @throws Exception If failed.
 */
@Test
public void testHashSetGetAllTx() throws Exception {
    List<String> messages = Collections.synchronizedList(new ArrayList<>());
    testLog = new ListeningTestLogger(false, log());
    testLog.registerListener((s) -> {
        if (s.contains("deadlock"))
            messages.add(s);
    });
    Ignite ignite = startGrid(0);
    IgniteCache<Integer, String> c = ignite.getOrCreateCache(new CacheConfiguration<Integer, String>("getTx").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setCacheMode(CacheMode.PARTITIONED));
    c.put(1, "foo");
    c.put(2, "bar");
    try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
        assertEquals(1, c.getAll(new HashSet<>(Arrays.asList(1, 3))).size());
        tx.commit();
    }
    int found = 0;
    for (String message : messages) {
        if (message.contains("Unordered collection java.util.HashSet is used for getAll operation on cache getTx."))
            found++;
    }
    assertEquals(1, found);
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ListeningTestLogger

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

the class GridCacheHashMapPutAllWarningsTest method testTreeMapClearEntries.

/**
 * @throws Exception If failed.
 */
@Test
public void testTreeMapClearEntries() throws Exception {
    List<String> messages = Collections.synchronizedList(new ArrayList<>());
    testLog = new ListeningTestLogger(false, log());
    testLog.registerListener((s) -> {
        if (s.contains("deadlock"))
            messages.add(s);
    });
    Ignite ignite = startGrid(0);
    startGrid(1);
    IgniteCache<Integer, String> c = ignite.getOrCreateCache(new CacheConfiguration<Integer, String>("entries").setCacheMode(CacheMode.PARTITIONED).setAtomicityMode(CacheAtomicityMode.ATOMIC).setBackups(1));
    for (int i = 0; i < 1000; i++) {
        c.put(i, "foo");
        c.put(i * 2, "bar");
    }
    c.clear();
    assertEquals(0, c.size());
    for (String message : messages) {
        assertFalse(message.contains("Unordered "));
        assertFalse(message.contains("operation on cache"));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with ListeningTestLogger

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

the class GridCacheHashMapPutAllWarningsTest method testHashMapPutAllExactMessage.

/**
 * @throws Exception If failed.
 */
@Test
public void testHashMapPutAllExactMessage() throws Exception {
    List<String> messages = Collections.synchronizedList(new ArrayList<>());
    testLog = new ListeningTestLogger(false, log());
    testLog.registerListener((s) -> {
        if (s.contains("deadlock"))
            messages.add(s);
    });
    Ignite ignite = startGrid(0);
    IgniteCache<Integer, String> c = ignite.getOrCreateCache(new CacheConfiguration<Integer, String>("exact").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
    HashMap<Integer, String> m = new HashMap<>();
    m.put(1, "foo");
    m.put(2, "bar");
    c.putAll(m);
    assertEquals(2, c.size());
    int found = 0;
    for (String message : messages) {
        if (message.contains("Unordered map java.util.HashMap is used for putAll operation on cache exact. " + "This can lead to a distributed deadlock. Switch to a sorted map like TreeMap instead."))
            found++;
    }
    assertEquals(1, found);
}
Also used : HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with ListeningTestLogger

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

the class GridCacheHashMapPutAllWarningsTest method testHashMapInvokeAllLocal.

/**
 * @throws Exception If failed.
 */
@Test
public void testHashMapInvokeAllLocal() throws Exception {
    Assume.assumeFalse("Local transactional caches not supported by MVCC", IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_FORCE_MVCC_MODE_IN_TESTS, false));
    List<String> messages = Collections.synchronizedList(new ArrayList<>());
    testLog = new ListeningTestLogger(false, log());
    testLog.registerListener((s) -> {
        if (s.contains("deadlock"))
            messages.add(s);
    });
    Ignite ignite = startGrid(0);
    IgniteCache<Integer, String> c = ignite.getOrCreateCache(new CacheConfiguration<Integer, String>("invoke").setCacheMode(CacheMode.LOCAL).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
    c.put(1, "foo");
    c.put(2, "bar");
    Map<Integer, EntryProcessorResult<String>> result = c.invokeAll(new HashSet<>(Arrays.asList(1, 2)), new EntryProcessor<Integer, String, String>() {

        @Override
        public String process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
            String newVal = entry.getValue() + "2";
            entry.setValue(newVal);
            return newVal;
        }
    });
    assertEquals(2, result.size());
    assertEquals("bar2", c.get(2));
    int found = 0;
    for (String message : messages) {
        if (message.contains("Unordered collection java.util.HashSet is used for invokeAll operation on cache invoke. "))
            found++;
    }
    assertEquals(1, found);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) EntryProcessorException(javax.cache.processor.EntryProcessorException) Ignite(org.apache.ignite.Ignite) MutableEntry(javax.cache.processor.MutableEntry) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with ListeningTestLogger

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

the class GridCommandHandlerIndexForceRebuildTest method removeLogListener.

/**
 */
private void removeLogListener(IgniteEx ignite, LogListener lsnr) {
    ListeningTestLogger impl = GridTestUtils.getFieldValue(ignite.log(), "impl");
    assertNotNull(impl);
    impl.unregisterListener(lsnr);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

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