本文整理汇总了C#中TableBatchOperation.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# TableBatchOperation.Merge方法的具体用法?C# TableBatchOperation.Merge怎么用?C# TableBatchOperation.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableBatchOperation
的用法示例。
在下文中一共展示了TableBatchOperation.Merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTableBatchOperationsWithEmptyKeysAsync
private async Task DoTableBatchOperationsWithEmptyKeysAsync(TablePayloadFormat format)
{
tableClient.DefaultRequestOptions.PayloadFormat = format;
// Insert Entity
DynamicTableEntity ent = new DynamicTableEntity() { PartitionKey = "", RowKey = "" };
ent.Properties.Add("foo2", new EntityProperty("bar2"));
ent.Properties.Add("foo", new EntityProperty("bar"));
TableBatchOperation batch = new TableBatchOperation();
batch.Insert(ent);
await currentTable.ExecuteBatchAsync(batch);
// Retrieve Entity
TableBatchOperation retrieveBatch = new TableBatchOperation();
retrieveBatch.Retrieve(ent.PartitionKey, ent.RowKey);
TableResult result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"].StringValue, retrievedEntity.Properties["foo"].StringValue);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
Assert.AreEqual(ent.Properties["foo2"].StringValue, retrievedEntity.Properties["foo2"].StringValue);
Assert.AreEqual(ent.Properties["foo2"], retrievedEntity.Properties["foo2"]);
// InsertOrMerge
DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value"));
batch = new TableBatchOperation();
batch.InsertOrMerge(insertOrMergeEntity);
await currentTable.ExecuteBatchAsync(batch);
result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]);
// InsertOrReplace
DynamicTableEntity insertOrReplaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue"));
batch = new TableBatchOperation();
batch.InsertOrReplace(insertOrReplaceEntity);
await currentTable.ExecuteBatchAsync(batch);
result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(1, retrievedEntity.Properties.Count);
Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
// Merge
DynamicTableEntity mergeEntity = new DynamicTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag };
mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged"));
batch = new TableBatchOperation();
batch.Merge(mergeEntity);
await currentTable.ExecuteBatchAsync(batch);
// Retrieve Entity & Verify Contents
result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]);
// Replace
DynamicTableEntity replaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag };
replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace"));
batch = new TableBatchOperation();
batch.Replace(replaceEntity);
await currentTable.ExecuteBatchAsync(batch);
// Retrieve Entity & Verify Contents
result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(replaceEntity.Properties["replaceProp"], retrievedEntity.Properties["replaceProp"]);
// Delete Entity
batch = new TableBatchOperation();
batch.Delete(retrievedEntity);
await currentTable.ExecuteBatchAsync(batch);
// Retrieve Entity
result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
Assert.IsNull(result.Result);
}
示例2: DoTableBatchMergeFailAsync
private async Task DoTableBatchMergeFailAsync(TablePayloadFormat format)
{
tableClient.DefaultRequestOptions.PayloadFormat = format;
// Insert Entity
DynamicTableEntity baseEntity = new DynamicTableEntity("merge test", "foo" + format.ToString());
baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
await currentTable.ExecuteAsync(TableOperation.Insert(baseEntity));
string staleEtag = baseEntity.ETag;
// update entity to rev etag
baseEntity.Properties["prop1"].StringValue = "updated value";
await currentTable.ExecuteAsync(TableOperation.Replace(baseEntity));
OperationContext opContext = new OperationContext();
try
{
// Attempt a merge with stale etag
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = staleEtag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
await currentTable.ExecuteBatchAsync(batch, null, opContext);
Assert.Fail();
}
catch (Exception)
{
TestHelper.ValidateResponse(opContext,
1,
(int)HttpStatusCode.PreconditionFailed,
new string[] { "UpdateConditionNotSatisfied", "ConditionNotMet" },
new string[] { "The update condition specified in the request was not satisfied.", "The condition specified using HTTP conditional header(s) is not met." });
}
// Delete Entity
await currentTable.ExecuteAsync(TableOperation.Delete(baseEntity));
opContext = new OperationContext();
// try merging with deleted entity
try
{
// Attempt a merge with stale etag
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
await currentTable.ExecuteBatchAsync(batch, null, opContext);
Assert.Fail();
}
catch (Exception)
{
TestHelper.ValidateResponse(opContext, 1, (int)HttpStatusCode.NotFound, new string[] { "ResourceNotFound" }, "The specified resource does not exist.");
}
}
示例3: DoTableBatchAllSupportedOperationsAsync
private async Task DoTableBatchAllSupportedOperationsAsync(TablePayloadFormat format)
{
tableClient.DefaultRequestOptions.PayloadFormat = format;
TableBatchOperation batch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
// insert
batch.Insert(GenerateRandomEntity(pk));
// delete
{
DynamicTableEntity entity = GenerateRandomEntity(pk);
await currentTable.ExecuteAsync(TableOperation.Insert(entity));
batch.Delete(entity);
}
// replace
{
DynamicTableEntity entity = GenerateRandomEntity(pk);
await currentTable.ExecuteAsync(TableOperation.Insert(entity));
batch.Replace(entity);
}
// insert or replace
{
DynamicTableEntity entity = GenerateRandomEntity(pk);
await currentTable.ExecuteAsync(TableOperation.Insert(entity));
batch.InsertOrReplace(entity);
}
// merge
{
DynamicTableEntity entity = GenerateRandomEntity(pk);
await currentTable.ExecuteAsync(TableOperation.Insert(entity));
batch.Merge(entity);
}
// insert or merge
{
DynamicTableEntity entity = GenerateRandomEntity(pk);
await currentTable.ExecuteAsync(TableOperation.Insert(entity));
batch.InsertOrMerge(entity);
}
IList<TableResult> results = await currentTable.ExecuteBatchAsync(batch);
Assert.AreEqual(results.Count, 6);
IEnumerator<TableResult> enumerator = results.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
}
示例4: TableBatchOnSecondaryAsync
public async Task TableBatchOnSecondaryAsync()
{
AssertSecondaryEndpoint();
CloudTable table = GenerateCloudTableClient().GetTableReference(GenerateRandomTableName());
TableRequestOptions options = new TableRequestOptions()
{
LocationMode = LocationMode.SecondaryOnly,
RetryPolicy = new NoRetry(),
};
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve("PartitionKey", "RowKey");
OperationContext context = new OperationContext();
await table.ExecuteBatchAsync(batch, options, context);
Assert.AreEqual(StorageLocation.Secondary, context.LastResult.TargetLocation);
batch = new TableBatchOperation();
batch.Insert(new DynamicTableEntity("PartitionKey", "RowKey"));
StorageException e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
batch = new TableBatchOperation();
batch.InsertOrMerge(new DynamicTableEntity("PartitionKey", "RowKey"));
e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
batch = new TableBatchOperation();
batch.InsertOrReplace(new DynamicTableEntity("PartitionKey", "RowKey"));
e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
batch = new TableBatchOperation();
batch.Merge(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });
e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
batch = new TableBatchOperation();
batch.Replace(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });
e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
batch = new TableBatchOperation();
batch.Delete(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });
e = await TestHelper.ExpectedExceptionAsync<StorageException>(
async () => await table.ExecuteBatchAsync(batch, options, null),
"Batch operations other than retrieve should not be sent to secondary");
Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
}
示例5: DoTableBatchMergeAsync
private async Task DoTableBatchMergeAsync(TablePayloadFormat format)
{
tableClient.DefaultRequestOptions.PayloadFormat = format;
// Insert Entity
DynamicTableEntity baseEntity = new DynamicTableEntity("merge test", "foo" + format.ToString());
baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
await currentTable.ExecuteAsync(TableOperation.Insert(baseEntity));
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
await currentTable.ExecuteBatchAsync(batch);
// Retrieve Entity & Verify Contents
TableResult result = await currentTable.ExecuteAsync(TableOperation.Retrieve(baseEntity.PartitionKey, baseEntity.RowKey));
DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(2, retrievedEntity.Properties.Count);
Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
}
示例6: TableBatchMergeAPM
public void TableBatchMergeAPM()
{
CloudTableClient tableClient = GenerateCloudTableClient();
// Insert Entity
DynamicTableEntity baseEntity = new DynamicTableEntity("merge test", "foo");
baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
currentTable.Execute(TableOperation.Insert(baseEntity));
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
using (ManualResetEvent evt = new ManualResetEvent(false))
{
IAsyncResult asyncRes = null;
currentTable.BeginExecuteBatch(batch, (res) =>
{
asyncRes = res;
evt.Set();
}, null);
evt.WaitOne();
currentTable.EndExecuteBatch(asyncRes);
}
// Retrieve Entity & Verify Contents
TableResult result = currentTable.Execute(TableOperation.Retrieve(baseEntity.PartitionKey, baseEntity.RowKey));
DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(2, retrievedEntity.Properties.Count);
Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
}
示例7: TableBatchMergeFailAPM
public void TableBatchMergeFailAPM()
{
CloudTableClient tableClient = GenerateCloudTableClient();
// Insert Entity
DynamicTableEntity baseEntity = new DynamicTableEntity("merge test", "foo");
baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
currentTable.Execute(TableOperation.Insert(baseEntity));
string staleEtag = baseEntity.ETag;
// update entity to rev etag
baseEntity.Properties["prop1"].StringValue = "updated value";
currentTable.Execute(TableOperation.Replace(baseEntity));
OperationContext opContext = new OperationContext();
try
{
// Attempt a merge with stale etag
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = staleEtag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
using (ManualResetEvent evt = new ManualResetEvent(false))
{
IAsyncResult asyncRes = null;
currentTable.BeginExecuteBatch(batch, null, opContext, (res) =>
{
asyncRes = res;
evt.Set();
}, null);
evt.WaitOne();
currentTable.EndExecuteBatch(asyncRes);
}
Assert.Fail();
}
catch (StorageException)
{
TestHelper.ValidateResponse(opContext,
1,
(int)HttpStatusCode.PreconditionFailed,
new string[] { "UpdateConditionNotSatisfied", "ConditionNotMet" },
new string[] { "The update condition specified in the request was not satisfied.", "The condition specified using HTTP conditional header(s) is not met." });
}
// Delete Entity
currentTable.Execute(TableOperation.Delete(baseEntity));
opContext = new OperationContext();
// try merging with deleted entity
try
{
// Attempt a merge with stale etag
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
using (ManualResetEvent evt = new ManualResetEvent(false))
{
IAsyncResult asyncRes = null;
currentTable.BeginExecuteBatch(batch, null, opContext, (res) =>
{
asyncRes = res;
evt.Set();
}, null);
evt.WaitOne();
currentTable.EndExecuteBatch(asyncRes);
}
Assert.Fail();
}
catch (StorageException)
{
TestHelper.ValidateResponse(opContext, 1, (int)HttpStatusCode.NotFound, new string[] { "ResourceNotFound" }, "The specified resource does not exist.");
}
}
示例8: TableBatchOperationsWithEmptyKeys
public void TableBatchOperationsWithEmptyKeys()
{
CloudTableClient tableClient = GenerateCloudTableClient();
// Insert Entity
DynamicTableEntity ent = new DynamicTableEntity() { PartitionKey = "", RowKey = "" };
ent.Properties.Add("foo2", new EntityProperty("bar2"));
ent.Properties.Add("foo", new EntityProperty("bar"));
TableBatchOperation batch = new TableBatchOperation();
batch.Insert(ent);
currentTable.ExecuteBatch(batch);
// Retrieve Entity
TableBatchOperation retrieveBatch = new TableBatchOperation();
retrieveBatch.Retrieve(ent.PartitionKey, ent.RowKey);
TableResult result = currentTable.ExecuteBatch(retrieveBatch).First();
DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"].StringValue, retrievedEntity.Properties["foo"].StringValue);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
Assert.AreEqual(ent.Properties["foo2"].StringValue, retrievedEntity.Properties["foo2"].StringValue);
Assert.AreEqual(ent.Properties["foo2"], retrievedEntity.Properties["foo2"]);
// InsertOrMerge
DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value"));
batch = new TableBatchOperation();
batch.InsertOrMerge(insertOrMergeEntity);
currentTable.ExecuteBatch(batch);
result = currentTable.ExecuteBatch(retrieveBatch).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]);
// InsertOrReplace
DynamicTableEntity insertOrReplaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue"));
batch = new TableBatchOperation();
batch.InsertOrReplace(insertOrReplaceEntity);
currentTable.ExecuteBatch(batch);
result = currentTable.ExecuteBatch(retrieveBatch).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(1, retrievedEntity.Properties.Count);
Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
// Merge
DynamicTableEntity mergeEntity = new DynamicTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag };
mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged"));
batch = new TableBatchOperation();
batch.Merge(mergeEntity);
currentTable.ExecuteBatch(batch);
// Retrieve Entity & Verify Contents
result = currentTable.ExecuteBatch(retrieveBatch).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]);
// Replace
DynamicTableEntity replaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag };
replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace"));
batch = new TableBatchOperation();
batch.Replace(replaceEntity);
currentTable.ExecuteBatch(batch);
// Retrieve Entity & Verify Contents
result = currentTable.ExecuteBatch(retrieveBatch).First();
retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(replaceEntity.Properties["replaceProp"], retrievedEntity.Properties["replaceProp"]);
// Delete Entity
batch = new TableBatchOperation();
batch.Delete(retrievedEntity);
currentTable.ExecuteBatch(batch);
// Retrieve Entity
result = currentTable.ExecuteBatch(retrieveBatch).First();
Assert.IsNull(result.Result);
}
示例9: TableBatchMergeSync
public void TableBatchMergeSync()
{
CloudTableClient tableClient = GenerateCloudTableClient();
// Insert Entity
DynamicTableEntity baseEntity = new DynamicTableEntity("merge test", "foo");
baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
currentTable.Execute(TableOperation.Insert(baseEntity));
DynamicTableEntity mergeEntity = new DynamicTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(mergeEntity);
currentTable.ExecuteBatch(batch);
// Retrieve Entity & Verify Contents
TableResult result = currentTable.Execute(TableOperation.Retrieve(baseEntity.PartitionKey, baseEntity.RowKey));
DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(2, retrievedEntity.Properties.Count);
Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
}
示例10: TableBatchAllSupportedOperationsSync
public void TableBatchAllSupportedOperationsSync()
{
CloudTableClient tableClient = GenerateCloudTableClient();
TableBatchOperation batch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
// insert
batch.Insert(GenerateRandomEnitity(pk));
// delete
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Delete(entity);
}
// replace
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Replace(entity);
}
// insert or replace
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.InsertOrReplace(entity);
}
// merge
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Merge(entity);
}
// insert or merge
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.InsertOrMerge(entity);
}
IList<TableResult> results = currentTable.ExecuteBatch(batch);
Assert.AreEqual(results.Count, 6);
IEnumerator<TableResult> enumerator = results.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
}
示例11: TableBatchAllSupportedOperationsAPM
public void TableBatchAllSupportedOperationsAPM()
{
CloudTableClient tableClient = GenerateCloudTableClient();
TableBatchOperation batch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
// insert
batch.Insert(GenerateRandomEnitity(pk));
// delete
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Delete(entity);
}
// replace
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Replace(entity);
}
// insert or replace
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.InsertOrReplace(entity);
}
// merge
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.Merge(entity);
}
// insert or merge
{
DynamicTableEntity entity = GenerateRandomEnitity(pk);
currentTable.Execute(TableOperation.Insert(entity));
batch.InsertOrMerge(entity);
}
IList<TableResult> results = null;
using (ManualResetEvent evt = new ManualResetEvent(false))
{
IAsyncResult asyncRes = null;
currentTable.BeginExecuteBatch(batch, (res) =>
{
asyncRes = res;
evt.Set();
}, null);
evt.WaitOne();
results = currentTable.EndExecuteBatch(asyncRes);
}
Assert.AreEqual(results.Count, 6);
IEnumerator<TableResult> enumerator = results.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
enumerator.MoveNext();
Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
}
示例12: DoEscapeTestAsync
private async Task DoEscapeTestAsync(string data, bool useBatch, bool includeKey)
{
DynamicTableEntity ent = new DynamicTableEntity(includeKey ? "temp" + data : "temp", Guid.NewGuid().ToString());
ent.Properties.Add("foo", new EntityProperty(data));
// Insert
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Insert(ent);
await currentTable.ExecuteBatchAsync(batch);
}
else
{
await currentTable.ExecuteAsync(TableOperation.Insert(ent));
}
// Retrieve
TableResult res = null;
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve(ent.PartitionKey, ent.RowKey);
res = (await currentTable.ExecuteBatchAsync(batch))[0];
}
else
{
res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey));
}
// Check equality
DynamicTableEntity retrievedEntity = res.Result as DynamicTableEntity;
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.ETag, retrievedEntity.ETag);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
// Merge
ent.Properties.Add("foo2", new EntityProperty("bar2"));
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(ent);
await currentTable.ExecuteBatchAsync(batch);
}
else
{
await currentTable.ExecuteAsync(TableOperation.Merge(ent));
}
// Retrieve
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve(ent.PartitionKey, ent.RowKey);
res = (await currentTable.ExecuteBatchAsync(batch))[0];
}
else
{
res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey));
}
retrievedEntity = res.Result as DynamicTableEntity;
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.ETag, retrievedEntity.ETag);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
// Replace
ent.Properties.Remove("foo2");
ent.Properties.Add("foo3", new EntityProperty("bar3"));
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Replace(ent);
await currentTable.ExecuteBatchAsync(batch);
}
else
{
await currentTable.ExecuteAsync(TableOperation.Replace(ent));
}
// Retrieve
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve(ent.PartitionKey, ent.RowKey);
res = (await currentTable.ExecuteBatchAsync(batch))[0];
}
else
{
res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey));
}
retrievedEntity = res.Result as DynamicTableEntity;
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
//.........这里部分代码省略.........
示例13: DoEscapeTest
private void DoEscapeTest(string data, bool useBatch, bool includeKey)
{
DynamicTableEntity ent = new DynamicTableEntity(includeKey ? "temp" + data : "temp", Guid.NewGuid().ToString());
ent.Properties.Add("foo", new EntityProperty(data));
// Insert
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Insert(ent);
currentTable.ExecuteBatch(batch);
}
else
{
currentTable.Execute(TableOperation.Insert(ent));
}
// Retrieve
TableResult res = null;
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve(ent.PartitionKey, ent.RowKey);
res = (currentTable.ExecuteBatch(batch))[0];
}
else
{
res = currentTable.Execute(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey));
}
// Check equality
DynamicTableEntity retrievedEntity = res.Result as DynamicTableEntity;
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.ETag, retrievedEntity.ETag);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
// Query using data filter
TableQuery query = new TableQuery();
query.Where(string.Format(
"(PartitionKey eq \'{0}\') and (RowKey eq \'{1}\') and (foo eq \'{2}\')",
ent.PartitionKey,
ent.RowKey,
data.Replace("\'", "\'\'")));
retrievedEntity = currentTable.ExecuteQuery(query).Single();
Assert.IsNotNull(retrievedEntity);
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.ETag, retrievedEntity.ETag);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
// Merge
ent.Properties.Add("foo2", new EntityProperty("bar2"));
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Merge(ent);
currentTable.ExecuteBatch(batch);
}
else
{
currentTable.Execute(TableOperation.Merge(ent));
}
// Retrieve
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Retrieve(ent.PartitionKey, ent.RowKey);
res = (currentTable.ExecuteBatch(batch))[0];
}
else
{
res = currentTable.Execute(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey));
}
retrievedEntity = res.Result as DynamicTableEntity;
Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
Assert.AreEqual(ent.ETag, retrievedEntity.ETag);
Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
// Replace
ent.Properties.Remove("foo2");
ent.Properties.Add("foo3", new EntityProperty("bar3"));
if (useBatch)
{
TableBatchOperation batch = new TableBatchOperation();
batch.Replace(ent);
currentTable.ExecuteBatch(batch);
}
else
//.........这里部分代码省略.........
示例14: DoRandomAtomicCalls
async Task DoRandomAtomicCalls()
{
for (int callNum = 0; callNum < MigrationModel.NUM_CALLS_PER_MACHINE; callNum++)
{
SortedDictionary<PrimaryKey, DynamicTableEntity> dump = await peekProxy.DumpReferenceTableAsync();
if (PSharpRuntime.Nondeterministic())
{
// Query
var query = new TableQuery<DynamicTableEntity>();
query.FilterString = ChainTableUtils.CombineFilters(
TableQuery.GenerateFilterCondition(
TableConstants.PartitionKey, QueryComparisons.Equal, MigrationModel.SINGLE_PARTITION_KEY),
TableOperators.And,
NondeterministicUserPropertyFilterString());
await RunQueryAtomicAsync(query);
}
else
{
// Batch write
int batchSize = PSharpRuntime.Nondeterministic() ? 2 : 1;
var batch = new TableBatchOperation();
var rowKeyChoices = new List<string> { "0", "1", "2", "3", "4", "5" };
for (int opNum = 0; opNum < batchSize; opNum++)
{
int opTypeNum = PSharpNondeterminism.Choice(7);
int rowKeyI = PSharpNondeterminism.Choice(rowKeyChoices.Count);
string rowKey = rowKeyChoices[rowKeyI];
rowKeyChoices.RemoveAt(rowKeyI); // Avoid duplicate in same batch
var primaryKey = new PrimaryKey(MigrationModel.SINGLE_PARTITION_KEY, rowKey);
string eTag = null;
if (opTypeNum >= 1 && opTypeNum <= 3)
{
DynamicTableEntity existingEntity;
int etagTypeNum = PSharpNondeterminism.Choice(
dump.TryGetValue(primaryKey, out existingEntity) ? 3 : 2);
switch (etagTypeNum)
{
case 0: eTag = ChainTable2Constants.ETAG_ANY; break;
case 1: eTag = "wrong"; break;
case 2: eTag = existingEntity.ETag; break;
}
}
DynamicTableEntity entity = new DynamicTableEntity
{
PartitionKey = MigrationModel.SINGLE_PARTITION_KEY,
RowKey = rowKey,
ETag = eTag,
Properties = new Dictionary<string, EntityProperty> {
// Give us something to see on merge. Might help with tracing too!
{ string.Format("{0}_c{1}_o{2}", machineId.ToString(), callNum, opNum),
new EntityProperty(true) },
// Property with 50%/50% distribution for use in filters.
{ "isHappy", new EntityProperty(PSharpRuntime.Nondeterministic()) }
}
};
switch (opTypeNum)
{
case 0: batch.Insert(entity); break;
case 1: batch.Replace(entity); break;
case 2: batch.Merge(entity); break;
case 3: batch.Delete(entity); break;
case 4: batch.InsertOrReplace(entity); break;
case 5: batch.InsertOrMerge(entity); break;
case 6:
entity.ETag = ChainTable2Constants.ETAG_DELETE_IF_EXISTS;
batch.Delete(entity); break;
}
}
await RunBatchAsync(batch);
}
}
}
示例15: TableBatchAllSupportedOperationsSync
public void TableBatchAllSupportedOperationsSync()
{
TableBatchOperation batch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
// insert
batch.Insert(GenerateRandomEnitity(pk));
// delete
{
DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
this.repTable.Execute(TableOperation.Insert(entity));
batch.Delete(entity);
}
// replace
{
DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
this.repTable.Execute(TableOperation.Insert(entity));
batch.Replace(entity);
}
// insert or replace
{
DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
this.repTable.Execute(TableOperation.Insert(entity));
batch.InsertOrReplace(entity);
}
// merge
{
DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
this.repTable.Execute(TableOperation.Insert(entity));
batch.Merge(entity);
}
// insert or merge
{
DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
this.repTable.Execute(TableOperation.Insert(entity));
batch.InsertOrMerge(entity);
}
IList<TableResult> results = this.repTable.ExecuteBatch(batch);
Assert.AreEqual(results.Count, 6);
IEnumerator<TableResult> enumerator = results.GetEnumerator();
for (int i = 0; i < results.Count; i++)
{
enumerator.MoveNext();
Assert.AreEqual((int)HttpStatusCode.NoContent, enumerator.Current.HttpStatusCode, "HttpStatusCode mismatch i={0}", i);
}
}