Ejemplo n.º 1
0
        public void TestAmbientOptimisticTransactionThrowsOptimisticExceptionOnConflict()
        {
            var cache        = GetCache();
            var transactions = Ignite.GetTransactions();

            var scope = new TransactionScope();
            var old   = cache[1];

            Assert.IsNotNull(transactions.Tx);
            Assert.AreEqual(TransactionConcurrency.Optimistic, transactions.Tx.Concurrency);
            Assert.AreEqual(TransactionIsolation.Serializable, transactions.Tx.Isolation);

            Task.Factory.StartNew(() =>
            {
                Assert.IsNull(transactions.Tx);
                cache[1] = -1;
            }, TaskCreationOptions.LongRunning)
            .Wait();

            Assert.AreEqual(old, cache[1]);
            cache[1] = old + 1;

            // Complete() just sets a flag, actual Commit is called from Dispose().
            scope.Complete();

            var ex = Assert.Throws <TransactionOptimisticException>(() => scope.Dispose());

            StringAssert.StartsWith(
                "Failed to prepare transaction, read/write conflict [key=1, keyCls=java.lang.Integer, val=-1",
                ex.Message);

            Assert.AreEqual(-1, cache[1]);
            Assert.IsNull(transactions.Tx);
        }
Ejemplo n.º 2
0
        public void TestExplicitOptimisticTransactionThrowsOptimisticExceptionOnConflict()
        {
            var cache        = GetCache();
            var transactions = Ignite.GetTransactions();

            using (var tx = transactions.TxStart())
            {
                Assert.IsNotNull(transactions.Tx);
                Assert.AreEqual(TransactionConcurrency.Optimistic, tx.Concurrency);
                Assert.AreEqual(TransactionIsolation.Serializable, tx.Isolation);

                var old = cache[1];

                Task.Factory.StartNew(() =>
                {
                    Assert.IsNull(transactions.Tx);
                    cache[1] = -1;
                }).Wait();

                Assert.AreEqual(old, cache[1]);
                cache[1] = old + 1;

                var ex = Assert.Throws <TransactionOptimisticException>(() => tx.Commit());
                StringAssert.StartsWith(
                    "Failed to prepare transaction, read/write conflict [key=1, keyCls=java.lang.Integer, val=-1",
                    ex.Message);
            }

            Assert.AreEqual(-1, cache[1]);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="target">Target.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="flagSkipStore">Skip store flag.</param>
        /// <param name="flagKeepBinary">Keep binary flag.</param>
        /// <param name="flagNoRetries">No-retries mode flag.</param>
        public CacheImpl(Ignite grid, IUnmanagedTarget target, Marshaller marsh,
                         bool flagSkipStore, bool flagKeepBinary, bool flagNoRetries) : base(target, marsh)
        {
            Debug.Assert(grid != null);

            _ignite         = grid;
            _flagSkipStore  = flagSkipStore;
            _flagKeepBinary = flagKeepBinary;
            _flagNoRetries  = flagNoRetries;

            _txManager = GetConfiguration().AtomicityMode == CacheAtomicityMode.Transactional
                ? new CacheTransactionManager(grid.GetTransactions())
                : null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="flagSkipStore">Skip store flag.</param>
        /// <param name="flagKeepBinary">Keep binary flag.</param>
        /// <param name="flagNoRetries">No-retries mode flag.</param>
        /// <param name="flagPartitionRecover">Partition recover mode flag.</param>
        public CacheImpl(IPlatformTargetInternal target,
                         bool flagSkipStore, bool flagKeepBinary, bool flagNoRetries, bool flagPartitionRecover)
            : base(target)
        {
            _ignite               = target.Marshaller.Ignite;
            _flagSkipStore        = flagSkipStore;
            _flagKeepBinary       = flagKeepBinary;
            _flagNoRetries        = flagNoRetries;
            _flagPartitionRecover = flagPartitionRecover;

            _txManager = GetConfiguration().AtomicityMode == CacheAtomicityMode.Transactional
                ? new CacheTransactionManager(_ignite.GetTransactions())
                : null;

            _readException = stream => ReadException(Marshaller.StartUnmarshal(stream));
        }