示例#1
0
 public async Task Conflict()
 {
     var client = new Client(Cluster(5));
     var aborted = false;
     using (var t1 = client.BeginWriteTransaction())
     {
         using (var t2 = client.BeginWriteTransaction())
         {
             await t1.Write("foo", "bar");
             await t2.Write("foo", await t2.Read("foo") + "baz");
             await t1.Commit();
             try
             {
                 await t2.Commit();
             }
             catch (Exception)
             {
                 aborted = true;
             }
         }
     }
     using (var t = client.BeginReadTransaction())
     {
         Assert.IsTrue(aborted);
         Assert.AreEqual("bar", await t.Read("foo"));
     }
 }
示例#2
0
 public async Task NonConflict()
 {
     var client = new Client(Cluster(5));
     using (var t = client.BeginWriteTransaction())
     {
         await t.Write("foo", "bing");
         await t.Write("bar", "bing");
         await t.Commit();
     }
     using (var t = client.BeginReadTransaction())
     {
         Assert.AreEqual("bing", await t.Read("foo"));
         using (var w = client.BeginWriteTransaction())
         {
             await w.Write("foo", "baz");
             await w.Write("bar", "baz");
             await w.Commit();
             await Task.Delay(500);//allow for propogation
         }
         //note that read remains consistent despite interleaving write
         Assert.AreEqual("bing", await t.Read("bar"));
     }
 }