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);
}
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"));
}
}
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);
}
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);
}
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);
}
Aggregations