コード例 #1
0
 public void DeleteTest1()
 {
     Transaction context = new Transaction();
     RID rid = new RID(RID.Type.FLIGHT, "test");
     Customer c = new Customer();
     HashSet<RID> reservations = new HashSet<RID> {rid};
     var db = CreateDatabase();
     TransactionStorage tr = new TransactionStorage(db);
     tr.Write(context, c, reservations);
     tr.Delete(context, c);
     List<Customer> cs = new List<Customer>(tr.GetCustomers(context));
     Assert.AreEqual(0, cs.Count);
 }
コード例 #2
0
 public void AbortTest()
 {
     Transaction context = new Transaction();
     RID rid = new RID(RID.Type.FLIGHT, "test");
     var db = CreateDatabase();
     TransactionStorage tr = new TransactionStorage(db);
     tr.Write(context, rid, new Resource(rid, 10, 11));
     //Resource res = tr.Read(context, rid);
     //Assert.AreEqual(11, res.getPrice());
     tr.Abort(context);
     var res = tr.Read(context, rid);
     Assert.IsNull(res, "Transaction aborted, but record still there");
 }
コード例 #3
0
 public void CommitTest()
 {
     Transaction context = new Transaction();
     Transaction context1 = new Transaction();
     RID rid = new RID(RID.Type.FLIGHT, Guid.NewGuid().ToString().Substring(0, 24));
     var db = CreateDatabase();
     TransactionStorage tr = new TransactionStorage(db);
     tr.Write(context, rid, new Resource(rid, 10, 11));
     Resource res = tr.Read(context1, rid);
     Assert.IsNull(res);
     tr.Prepare(context);
     tr.Commit(context);
     res = tr.Read(context, rid);
     Assert.AreEqual(11, res.getPrice());
 }
コード例 #4
0
        /// <summary>
        /// implemented using the new TransactionStorage class
        /// This method adds a resource to the available ones
        /// </summary>
        /// <param name="context"></param>
        /// <param name="i"></param>
        /// <param name="count"></param>
        /// <param name="price"></param>
        /// <returns></returns>
        public bool Add(TP.Transaction context, TP.RID i, int count, int price)
        {
            WaitForReady();
            Enlist(context);

            _lockManager.LockForWrite(context, i);
            Resource res = _transactionStorage.Read(context, i);

            if (res == null)
            {
                res = new Resource(i, count, price);
            }
            else
            {
                res.incrCount(count);
                res.setPrice(price);
            }

            _transactionStorage.Write(context, i, res);
            return(true);
        }
コード例 #5
0
 public void ReadWriteTest()
 {
     Transaction context = new Transaction();
     RID rid = new RID(RID.Type.FLIGHT, "test");
     Customer c = new Customer();
     HashSet<RID> reservations = new HashSet<RID> {rid};
     var db = CreateDatabase();
     TransactionStorage tr = new TransactionStorage(db);
     tr.Write(context, c, reservations);
     HashSet<RID> actual = tr.Read(context, c);
     Assert.IsTrue(reservations.SetEquals(actual));
 }
コード例 #6
0
 public void WriteDeleteBeforeCommit()
 {
     Transaction context = new Transaction();
     RID rid = new RID(RID.Type.FLIGHT, "test");
     var db = CreateDatabase();
     TransactionStorage tr = new TransactionStorage(db);
     tr.Write(context, rid, new Resource(rid, 10, 11));
     tr.Delete(context, rid);
     Resource res = tr.Read(context, rid);
     Assert.IsNull(res);
 }