예제 #1
0
 public void SetAndGetOriginalValue()
 {
     IObject obj = new BaseObject(null, new object[] { 1, 2, 3 });
     TransactionalValue tvalue = new TransactionalValue(this.trobj, 2);
     Assert.AreEqual(3, tvalue.GetValue(this.CreateTransaction()));
     Assert.AreEqual(3, tvalue.GetValue(0));
 }
예제 #2
0
 public void RaiseIfTwoTransactionChangeTheSameSlot()
 {
     IObject obj = new BaseObject(null, new object[] { 1, 2, 3 });
     TransactionalValue tvalue = new TransactionalValue(this.trobj, 0);
     Transaction transaction1 = this.CreateTransaction();
     tvalue.SetValue(transaction1, 2);
     Transaction transaction2 = this.CreateTransaction();
     tvalue.SetValue(transaction2, 3);
 }
예제 #3
0
        public void RaiseIfTransactionChangeACommittedSlot()
        {
            IObject obj = new BaseObject(null, new object[] { 1, 2, 3 });
            TransactionalValue tvalue = new TransactionalValue(this.trobj, 0);
            Transaction transaction1 = this.CreateTransaction();

            Transaction transaction2 = this.CreateTransaction();
            tvalue.SetValue(transaction2, 3);
            transaction2.Commit(this.manager.Time + 1);
            ////tvalue.CommitValue(transaction2);
            tvalue.SetValue(transaction1, 2);
        }
예제 #4
0
        public void TwoSerializedTransactions()
        {
            IObject obj = new BaseObject(null, new object[] { 1, 2, 3 });
            TransactionalValue tvalue = new TransactionalValue(this.trobj, 0);
            Transaction transaction1 = this.CreateTransaction();
            tvalue.SetValue(transaction1, 2);
            tvalue.CommitValue(transaction1);

            Assert.AreEqual(2, tvalue.GetValue(0));

            Transaction transaction2 = this.CreateTransaction();
            tvalue.SetValue(transaction2, 3);
            tvalue.CommitValue(transaction2);

            Assert.AreEqual(3, tvalue.GetValue(0));
        }
예제 #5
0
 // TODO Review: it's only called with thread local TransactionManager.Current, no lock is needed
 public void RegisterValue(TransactionalValue value)
 {
     if (this.values.Contains(value))
         return;
     this.values.Add(value);
 }
예제 #6
0
        public object this[int n]
        {
            get
            {
                lock (this)
                {
                    if (TransactionManager.CurrentTransaction == null && !this.manager.HasTransactions())
                    {
                        if (this.values.Count > 0)
                            this.ReleaseValues();

                        return this.inner[n];
                    }

                    if (this.values.ContainsKey(n))
                    {
                        if (TransactionManager.CurrentTransaction == null)
                            return this.values[n].GetValue(this.manager.Time);
                        else
                            return this.values[n].GetValue(TransactionManager.CurrentTransaction);
                    }

                    return this.inner[n];
                }
            }

            set
            {
                lock (this)
                {
                    if (TransactionManager.CurrentTransaction == null && !this.manager.HasTransactions())
                    {
                        if (this.values.Count > 0)
                            this.ReleaseValues();

                        this.inner[n] = value;
                        return;
                    }

                    if (!this.values.ContainsKey(n))
                    {
                        TransactionalValue tv = new TransactionalValue(this, n);
                        this.values[n] = tv;
                    }

                    if (TransactionManager.CurrentTransaction == null)
                        this.values[n].SetValue(this.manager.Time, value);
                    else
                        this.values[n].SetValue(TransactionManager.CurrentTransaction, value);
                }
            }
        }