shishkovilja commented on code in PR #11559:
URL: https://github.com/apache/ignite/pull/11559#discussion_r1812587031


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));

Review Comment:
   Default cache seems to be unused. I suggest to move "my-cache" configuration 
from test body to this place.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");

Review Comment:
   ```suggestion
           startClientGrid(1);
   ```
   
   And move it to a test body. Instance can be obtained with `grid(1)` call.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;

Review Comment:
   It seems to be redundant



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);
+    }
+
+    /**
+     * It should throw exception.
+     * @param op Operation.
+     */
+    private void checkNonTxOperation(IgniteEx ignite, 
Consumer<IgniteCache<Object, Object>> op) {

Review Comment:
   ```suggestion
       private void checkIgniteCacheClear(IgniteEx ignite) {
   ```



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");

Review Comment:
   ```suggestion
           srv = startGrid(0);
   ```
   
   And move it to a test body. Instance can be obtained with `grid(0)` call.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {

Review Comment:
   ```suggestion
       public void testIgniteCacheClear() {
   ```



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);
+    }
+
+    /**
+     * It should throw exception.
+     * @param op Operation.
+     */
+    private void checkNonTxOperation(IgniteEx ignite, 
Consumer<IgniteCache<Object, Object>> op) {
+        IgniteCache<Object, Object> cache = ignite.createCache(new 
CacheConfiguration<>("my-cache")
+            .setAtomicityMode(TRANSACTIONAL));
+
+        cache.put(1, 1);
+
+        IgniteException err = null;
+
+        try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, 
READ_COMMITTED)) {
+            cache.put(2, 2);
+
+            op.accept(cache);
+
+            tx.commit();
+        }
+        catch (IgniteException e) {
+            err = e;
+        }
+
+        assertTrue(err != null && err.getMessage().startsWith("Failed to 
invoke a non-transactional operation " +
+            "within a transaction"));
+
+        assertTrue(cache.containsKey(1));
+
+        assertFalse(cache.containsKey(2));
+
+        srv.cache("my-cache").destroy();

Review Comment:
   Redundant destroy.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);

Review Comment:
   Let's move it to a separate test with the name 
`testIgniteCacheClearOnClientNode`



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);
+    }
+
+    /**
+     * It should throw exception.
+     * @param op Operation.
+     */
+    private void checkNonTxOperation(IgniteEx ignite, 
Consumer<IgniteCache<Object, Object>> op) {
+        IgniteCache<Object, Object> cache = ignite.createCache(new 
CacheConfiguration<>("my-cache")
+            .setAtomicityMode(TRANSACTIONAL));
+
+        cache.put(1, 1);
+
+        IgniteException err = null;
+
+        try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, 
READ_COMMITTED)) {
+            cache.put(2, 2);
+
+            op.accept(cache);

Review Comment:
   ```suggestion
               cache.clear();
   ```



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);
+    }
+
+    /**
+     * It should throw exception.
+     * @param op Operation.
+     */
+    private void checkNonTxOperation(IgniteEx ignite, 
Consumer<IgniteCache<Object, Object>> op) {
+        IgniteCache<Object, Object> cache = ignite.createCache(new 
CacheConfiguration<>("my-cache")
+            .setAtomicityMode(TRANSACTIONAL));
+
+        cache.put(1, 1);
+
+        IgniteException err = null;
+
+        try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, 
READ_COMMITTED)) {

Review Comment:
   Replace it with `assertThrows` combined with a `doInTransaction`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java:
##########
@@ -1059,6 +1059,10 @@ public List<GridCacheClearAllRunnable<K, V>> 
splitClearLocally(boolean srv, bool
 
     /** {@inheritDoc} */
     @Override public void clear() throws IgniteCheckedException {
+        if (ctx.transactional() && ctx.grid().transactions().tx() != null)

Review Comment:
   Please investigate if it possible to replace it by 
`IgniteTxManager#checkEmptyTransactions`.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(new 
CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        srv = startGrid("srv0");
+        client = startClientGrid("cli0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests that a non-transactional cache operation {@link 
IgniteCache#clear()} is not allowed within a transaction
+     * and the operation works as expected.
+     */
+    @Test
+    public void testIgniteCacheNonTransactionalOperations() {
+        checkNonTxOperation(srv, IgniteCache::clear);
+
+        checkNonTxOperation(client, IgniteCache::clear);
+    }
+
+    /**
+     * It should throw exception.
+     * @param op Operation.
+     */
+    private void checkNonTxOperation(IgniteEx ignite, 
Consumer<IgniteCache<Object, Object>> op) {
+        IgniteCache<Object, Object> cache = ignite.createCache(new 
CacheConfiguration<>("my-cache")
+            .setAtomicityMode(TRANSACTIONAL));
+
+        cache.put(1, 1);
+
+        IgniteException err = null;
+
+        try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, 
READ_COMMITTED)) {
+            cache.put(2, 2);
+
+            op.accept(cache);
+
+            tx.commit();
+        }
+        catch (IgniteException e) {
+            err = e;
+        }
+
+        assertTrue(err != null && err.getMessage().startsWith("Failed to 
invoke a non-transactional operation " +

Review Comment:
   Replace it with `X.hasCause`



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NonTransactionalOperationsInTxTest.java:
##########
@@ -0,0 +1,88 @@
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Checks how non-transactional cache operations work within a transaction. */
+public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest 
{
+    /** */
+    protected static IgniteEx srv;
+
+    /** */
+    protected static IgniteEx client;

Review Comment:
   It seems to be redundant



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to