vldpyatkov commented on code in PR #13080: URL: https://github.com/apache/ignite/pull/13080#discussion_r3160873493
########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxSavepointPessimisticTest.java: ########## @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.transactions; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.junit.Test; + +import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * Tests transaction savepoint functionality. + * Currently, savepoint API is supported only for pessimistic transactions. + */ +public class TxSavepointPessimisticTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName) + .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setBackups(1) + .setCacheMode(CacheMode.PARTITIONED)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + @Test + public void testSavepointRejectedForOptimisticTx() throws Exception { + Ignite ignite = startGrid(0); + + try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) { + GridTestUtils.assertThrowsAnyCause(log, + () -> { + tx.savepoint("sp"); + + return null; + }, + IgniteCheckedException.class, + "Savepoints are supported only for PESSIMISTIC transactions."); + } + } + + /** + * @throws Exception If failed. + */ + @Test + public void testSeveralSavepoints() throws Exception { + Ignite ignite = startGrid(0); + IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME); + + int key = 1; + + try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) { + cache.put(key, 1); + + tx.savepoint("sp1"); + + cache.put(key, 2); + + tx.savepoint("sp2"); + + cache.put(key, 3); + + tx.savepoint("sp3"); + + cache.put(key, 4); + + tx.rollbackToSavepoint("sp1"); + + tx.commit(); + } + + assertEquals(Integer.valueOf(1), cache.get(key)); Review Comment: I do not think that this is able to be done, because JUnit has an overloaded method, assertEquals(Object, Object). -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
