Another test - what happens if you try concurrent updates.... breaking the optimistic concurrency locking
static TableServiceContext GetContext()
{
CloudTableClient client = new CloudTableClient(
"https://***.table.core.windows.net",
new StorageCredentialsAccountAndKey("***", "****"));
//client.CreateTableIfNotExist("TestData");
var context1 = client.GetDataServiceContext();
return context1;
}
static Thing GetFredFromContext(TableServiceContext context)
{
var query = context.CreateQuery<Thing>("TestData");
var subquery = from t in query
where t.PartitionKey == "Fred"
&& t.RowKey == "Bloggs"
select t;
var element = subquery.First();
return element;
}
static void Main(string[] args)
{
var context1 = GetContext();
var context2 = GetContext();
var one = GetFredFromContext(context1);
var two = GetFredFromContext(context2);
one.TestField = "test2";
two.TestField = "test3";
context1.UpdateObject(one);
context2.UpdateObject(two);
context1.SaveChanges();
try
{
context2.SaveChanges();
}
catch (Exception e)
{
// exception is caught here -
}
}
The exception is System.Data.Services.Client.DataServiceRequestException
The InnerException is [System.Data.Services.Client.DataServiceClientException] with StatusCode of 412 - from http://msdn.microsoft.com/en-us/library/dd179438.aspx
UpdateConditionNotSatisfied | Precondition Failed (412) |
No comments:
Post a Comment