public void TableEntityPropertySetter() { string pk = Guid.NewGuid().ToString(); string rk = Guid.NewGuid().ToString(); Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>(); EntityProperty boolEntity = EntityProperty.GeneratePropertyForBool(null); boolEntity.BooleanValue = true; properties.Add("boolEntity", boolEntity); EntityProperty timeEntity = EntityProperty.GeneratePropertyForDateTimeOffset(null); timeEntity.DateTimeOffsetValue = DateTimeOffset.UtcNow; properties.Add("timeEntity", timeEntity); EntityProperty doubleEntity = EntityProperty.GeneratePropertyForDouble(null); doubleEntity.DoubleValue = 0.1; properties.Add("doubleEntity", doubleEntity); EntityProperty guidEntity = EntityProperty.GeneratePropertyForGuid(null); guidEntity.GuidValue = Guid.NewGuid(); properties.Add("guidEntity", guidEntity); EntityProperty intEntity = EntityProperty.GeneratePropertyForInt(null); intEntity.Int32Value = 1; properties.Add("intEntity", intEntity); EntityProperty longEntity = EntityProperty.GeneratePropertyForLong(null); longEntity.Int64Value = 1; properties.Add("longEntity", longEntity); EntityProperty stringEntity = EntityProperty.GeneratePropertyForString(null); stringEntity.StringValue = "string"; properties.Add("stringEntity", stringEntity); DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity(pk, rk, "*", properties); this.repTable.Execute(TableOperation.Insert(ent)); }
private void InsertOrMergeBatchWithNEntities(int n) { string pk = Guid.NewGuid().ToString(); TableBatchOperation insertBatch = new TableBatchOperation(); TableBatchOperation mergeBatch = new TableBatchOperation(); TableBatchOperation delBatch = new TableBatchOperation(); for (int m = 0; m < n; m++) { insertBatch.InsertOrMerge(GenerateRandomEnitity(pk)); } IList <TableResult> results = this.repTable.ExecuteBatch(insertBatch); foreach (TableResult res in results) { Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent); // update entity and add to merge batch DynamicReplicatedTableEntity ent = res.Result as DynamicReplicatedTableEntity; ent.Properties.Add("foo2", new EntityProperty("bar2")); mergeBatch.InsertOrMerge(ent); } // execute insertOrMerge batch, this time entities exist IList <TableResult> mergeResults = this.repTable.ExecuteBatch(mergeBatch); foreach (TableResult res in mergeResults) { Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent); // Add to delete batch delBatch.Delete((ITableEntity)res.Result); } IList <TableResult> delResults = this.repTable.ExecuteBatch(delBatch); foreach (TableResult res in delResults) { Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent); } }
/// <summary> /// Retrieve an SampleXStoreEntity which doesn't inherit ReplicatedTableEntity through RTable in convert mode /// </summary> /// <param name="jobType"></param> /// <param name="jobId"></param> /// <param name="entityMessage"></param> protected void RetrieveAsSampleXStoreEntity( string jobType, string jobId, string entityMessage) { for (int i = 0; i < this.numberOfPartitions; i++) { for (int j = 0; j < this.numberOfRowsPerPartition; j++) { // // Retrieve // string partitionKey; string rowKey; SampleXStoreEntity.GenerateKeys( this.GenerateJobType(jobType, i), this.GenerateJobId(jobId, i, j), out partitionKey, out rowKey); TableOperation retrieveOperation = TableOperation.Retrieve(partitionKey, rowKey); TableResult retrieveResult = this.repTable.Execute(retrieveOperation); Assert.IsNotNull(retrieveResult, "retrieveResult = null"); DynamicReplicatedTableEntity dynamicReplicatedTableEntity = retrieveResult.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(dynamicReplicatedTableEntity, "dynamicReplicatedTableEntity = null"); SampleXStoreEntity retrievedEntity = SampleXStoreEntity.ToSampleXStoreEntity(dynamicReplicatedTableEntity); Assert.AreEqual( this.GenerateJobType(jobType, i), retrievedEntity.JobType, "JobType mismatch"); Assert.AreEqual( this.GenerateJobId(jobId, i, j), retrievedEntity.JobId, "JobId mismatch"); Assert.AreEqual( this.GenerateMessage(entityMessage, i, j), retrievedEntity.Message, "Message mismatch"); } } }
public void TableBatchInsertOrMergeSync() { // Insert Or Merge with no pre-existing entity DynamicReplicatedTableEntity insertOrMergeEntity = new DynamicReplicatedTableEntity("batchInsertOrMerge entity", "foo"); insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1")); TableBatchOperation batch = new TableBatchOperation(); batch.InsertOrMerge(insertOrMergeEntity); IList <TableResult> batchResultList = this.repTable.ExecuteBatch(batch); // Retrieve Entity & Verify Contents TableResult result = this.repTable.Execute(TableOperation.Retrieve <DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey)); DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count); DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey, batchResultList[0].Etag, retrievedEntity.Properties); mergeEntity.Properties.Add("prop2", new EntityProperty("value2")); TableBatchOperation batch2 = new TableBatchOperation(); batch2.InsertOrMerge(mergeEntity); this.repTable.ExecuteBatch(batch2); // Retrieve Entity & Verify Contents result = this.repTable.Execute(TableOperation.Retrieve <DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey)); retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(2, retrievedEntity.Properties.Count, "retrievedEntity.Properties.Count={0}. (Expecting 2)", retrievedEntity.Properties.Count); Assert.IsNotNull(retrievedEntity); Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]); Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]); }
public void TableBatchEntityOver1MBShouldThrow() { TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); DynamicReplicatedTableEntity ent = GenerateRandomEnitity(pk); ent.Properties.Add("binary", EntityProperty.GeneratePropertyForByteArray(new byte[1024 * 1024])); batch.Insert(ent); OperationContext opContext = new OperationContext(); try { this.repTable.ExecuteBatch(batch, null, opContext); Assert.Fail(); } catch (StorageException) { TestHelper.ValidateResponse(opContext, 2, (int)HttpStatusCode.BadRequest, new string[] { "EntityTooLarge" }, "The entity is larger than the maximum allowed size (1MB)."); } }
public void TableBatchOver4MBShouldThrow() { TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); for (int m = 0; m < 65; m++) { DynamicReplicatedTableEntity ent = GenerateRandomEnitity(pk); // Maximum Entity size is 64KB ent.Properties.Add("binary", EntityProperty.GeneratePropertyForByteArray(new byte[64 * 1024])); batch.Insert(ent); } OperationContext opContext = new OperationContext(); try { this.repTable.ExecuteBatch(batch, null, opContext); Assert.Fail(); } catch (StorageException) { // // ###XXX: NEW SOURCE CODES: The commented out codes were the original codes // //TestHelper.ValidateResponse(opContext, 1, (int)HttpStatusCode.BadRequest, new string[] { "ContentLengthExceeded" }, "The content length for the requested operation has exceeded the limit (4MB)."); TestHelper.ValidateResponse( opContext, 2, (int)HttpStatusCode.RequestEntityTooLarge, new string[] { "RequestBodyTooLarge" }, "The request body is too large and exceeds the maximum permissible limit" ); } }
public void TableBatchWithPropertyOver255CharsShouldThrow() { TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); string propName = new string('a', 256); // propName has 256 chars DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity("foo", "bar"); ent.Properties.Add(propName, new EntityProperty("propbar")); batch.Insert(ent); OperationContext opContext = new OperationContext(); try { this.repTable.ExecuteBatch(batch, null, opContext); Assert.Fail(); } catch (StorageException) { TestHelper.ValidateResponse(opContext, 2, (int)HttpStatusCode.BadRequest, new string[] { "PropertyNameTooLong" }, "The property name exceeds the maximum allowed length (255)."); } }
public void TableBatchOperationsWithEmptyKeys() { // Insert Entity DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity() { PartitionKey = "", RowKey = "" }; ent.Properties.Add("foo2", new EntityProperty("bar2")); ent.Properties.Add("foo", new EntityProperty("bar")); TableBatchOperation batch = new TableBatchOperation(); batch.Insert(ent); this.repTable.ExecuteBatch(batch); // Retrieve Entity TableBatchOperation retrieveBatch = new TableBatchOperation(); retrieveBatch.Retrieve <DynamicReplicatedTableEntity>(ent.PartitionKey, ent.RowKey); TableResult result = this.repTable.ExecuteBatch(retrieveBatch).First(); DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity; 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 DynamicReplicatedTableEntity insertOrMergeEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey); insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value")); batch = new TableBatchOperation(); batch.InsertOrMerge(insertOrMergeEntity); this.repTable.ExecuteBatch(batch); result = this.repTable.ExecuteBatch(retrieveBatch).First(); retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]); // InsertOrReplace DynamicReplicatedTableEntity insertOrReplaceEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey); insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue")); batch = new TableBatchOperation(); batch.InsertOrReplace(insertOrReplaceEntity); this.repTable.ExecuteBatch(batch); result = this.repTable.ExecuteBatch(retrieveBatch).First(); retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(1, retrievedEntity.Properties.Count); Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]); // Merge DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag }; mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged")); batch = new TableBatchOperation(); batch.Merge(mergeEntity); this.repTable.ExecuteBatch(batch); // Retrieve Entity & Verify Contents result = this.repTable.ExecuteBatch(retrieveBatch).First(); retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]); // Replace DynamicReplicatedTableEntity replaceEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag }; replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace")); batch = new TableBatchOperation(); batch.Replace(replaceEntity); this.repTable.ExecuteBatch(batch); // Retrieve Entity & Verify Contents result = this.repTable.ExecuteBatch(retrieveBatch).First(); retrievedEntity = result.Result as DynamicReplicatedTableEntity; 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); this.repTable.ExecuteBatch(batch); // Retrieve Entity result = this.repTable.ExecuteBatch(retrieveBatch).First(); Assert.IsNull(result.Result); }
public void MergeUsingLargerViewId() { long currentViewId = 100; long futureViewId = currentViewId + 1; int expectedVersion = 1; this.UpdateConfiguration(replicas, 0, false, currentViewId); // Insert Entity DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("merge test02", "foo02"); baseEntity.Properties.Add("prop1", new EntityProperty("value1")); Console.WriteLine("Calling TableOperation.Insert()..."); TableResult result = this.repTable.Execute(TableOperation.Insert(baseEntity)); Assert.AreNotEqual(null, result, "Insert(): result = null"); Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Insert(): result.HttpStatusCode mismatch"); // // Call ModifyConfigurationBlob to change the viewId of the wrapper to a larger value // Console.WriteLine("Changing the viewId to futureViewId {0}", futureViewId); this.UpdateConfiguration(replicas, 0, false, futureViewId); // // Merge // DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag }; mergeEntity.Properties.Add("prop2", new EntityProperty("value2")); Console.WriteLine("\nCalling TableOperation.Merge() with a larger viewId..."); result = this.repTable.Execute(TableOperation.Merge(mergeEntity)); expectedVersion++; Assert.AreNotEqual(null, result, "Merge(): result = null"); Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Merge(): result.HttpStatusCode mismatch"); // // InsertOrMerge // DynamicReplicatedTableEntity mergeEntity2 = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag }; mergeEntity2.Properties.Add("prop3", new EntityProperty("value3")); Console.WriteLine("\nCalling TableOperation.InsertOrMerge() with a larger viewId..."); result = this.repTable.Execute(TableOperation.InsertOrMerge(mergeEntity2)); expectedVersion++; Assert.AreNotEqual(null, result, "InsertOrMerge(): result = null"); Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "InsertOrMerge(): result.HttpStatusCode mismatch"); // Retrieve Entity & Verify Contents Console.WriteLine("\nCalling TableOperation.Retrieve() with a larger viewId..."); result = this.repTable.Execute(TableOperation.Retrieve <DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey)); Assert.AreNotEqual(null, result, "Retrieve(): result = null"); DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity; Assert.IsNotNull(retrievedEntity, "retrievedEntity = null"); Assert.AreEqual(3, retrievedEntity.Properties.Count, "Properties.Count mismatch"); Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"], "Properties[prop1] mismatch"); Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"], "Properties[prop2] mismatch"); Assert.AreEqual(mergeEntity2.Properties["prop3"], retrievedEntity.Properties["prop3"], "Properties[prop3] mismatch"); Assert.AreEqual(futureViewId, retrievedEntity._rtable_ViewId, "retrievedEntity._rtable_ViewId mismatch"); Assert.AreEqual(expectedVersion, retrievedEntity._rtable_Version, "retrievedEntity._rtable_Version mismatch"); }