示例#1
0
        public void RetrieveViaXStoreThenEnableRTableThenDeleteViaRTable()
        {
            // This issue happens when we transition such:
            // 1. we Retrieve using an XStore lib.
            // 2. switched to RTable lib.
            // 3. then Delete the entry using RTable lib.
            string jobType = "jobType-RetrieveXStoreEntity";
            string jobId   = "jobId-RetrieveXStoreEntity";

            //
            // Retrieve using XStore library
            //
            string partitionKey;
            string rowKey;

            SampleXStoreEntity.GenerateKeys(
                this.GenerateJobType(jobType, 0),
                this.GenerateJobId(jobId, 0, 0),
                out partitionKey,
                out rowKey);
            TableOperation retrieveOperation = TableOperation.Retrieve <SampleXStoreEntity>(partitionKey, rowKey);
            TableResult    retrieveResult    = this.xstoreCloudTable.Execute(retrieveOperation);

            Assert.IsNotNull(retrieveResult, "retrieveResult = null");
            SampleXStoreEntity retrievedEntity = (SampleXStoreEntity)retrieveResult.Result;

            Assert.AreEqual(
                this.GenerateMessage(this.message, 0, 0),
                retrievedEntity.Message,
                "Retrieve(): Message mismatch");


            //
            // we switch to RTable and convertXSToreTableMode = true
            //
            Assert.True(this.configurationWrapper.IsConvertToRTableMode(), "Convert flag should be True");

            //
            // Delete using RTable library
            //
            InitDynamicReplicatedTableEntity deleteTableEntity = SampleXStoreEntity.ToInitDynamicReplicatedTableEntity(retrievedEntity);

            TableOperation deleteOperation = TableOperation.Delete(deleteTableEntity);
            TableResult    deleteResult    = this.repTable.Execute(deleteOperation);

            Assert.IsNotNull(deleteResult, "deleteResult = null");

            retrieveOperation = TableOperation.Retrieve(partitionKey, rowKey);
            retrieveResult    = this.repTable.Execute(retrieveOperation);
            Assert.IsNotNull(retrieveResult, "retrieveResult = null");
            Assert.AreEqual(retrieveResult.HttpStatusCode, (int)HttpStatusCode.NotFound, "entry should not exist!");

            this.PerformInsertOperationAndValidate(jobType, jobId, this.message);
            this.PerformRetrieveOperationAndValidate(jobType, jobId, this.message, true); // check _rtable_ViewId
        }
示例#2
0
        /// <summary>
        /// Check whether this instance matches the specified object or not
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            SampleXStoreEntity dst = obj as SampleXStoreEntity;

            if (dst == null)
            {
                return(false);
            }
            else
            {
                return(this.JobType == dst.JobType && this.JobId == dst.JobId && this.Message == dst.Message);
            }
        }
示例#3
0
        public static SampleXStoreEntity ToSampleXStoreEntity(DynamicReplicatedTableEntity dynamicReplicatedTableEntity)
        {
            var entity = new SampleXStoreEntity()
            {
                PartitionKey = dynamicReplicatedTableEntity.PartitionKey,
                RowKey       = dynamicReplicatedTableEntity.RowKey,
                Timestamp    = dynamicReplicatedTableEntity.Timestamp,
                ETag         = dynamicReplicatedTableEntity.ETag
            };

            // we could reflect, but keeping it simple.
            entity.JobType = dynamicReplicatedTableEntity.Properties["JobType"].StringValue;
            entity.JobId   = dynamicReplicatedTableEntity.Properties["JobId"].StringValue;
            entity.Message = dynamicReplicatedTableEntity.Properties["Message"].StringValue;

            return(entity);
        }
示例#4
0
        /// <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");
                }
            }
        }
示例#5
0
        /// <summary>
        /// Insert some entities into the XStore Table.
        /// There will be "numberOfPartitions" partitions
        /// and "numberOfRowsPerPartition" rows per partition.
        /// Assumption is that those entities do NOT exist currently.
        /// </summary>
        /// <param name="jobType"></param>
        /// <param name="jobId"></param>
        /// <param name="entityMessage"></param>
        protected void InsertXStoreEntities(
            string jobType,
            string jobId,
            string entityMessage)
        {
            for (int i = 0; i < this.numberOfPartitions; i++)
            {
                for (int j = 0; j < this.numberOfRowsPerPartition; j++)
                {
                    SampleXStoreEntity sampleXStoreEntity = new SampleXStoreEntity(
                        this.GenerateJobType(jobType, i),
                        this.GenerateJobId(jobId, i, j),
                        this.GenerateMessage(entityMessage, i, j));

                    //
                    // Insert
                    //
                    TableOperation insertOperation = TableOperation.Insert(sampleXStoreEntity);
                    TableResult    insertResult    = this.xstoreCloudTable.Execute(insertOperation);

                    Assert.IsNotNull(insertResult, "insertResult = null");
                    Assert.AreEqual((int)HttpStatusCode.NoContent, insertResult.HttpStatusCode, "entry #{0} row {1}: insertResult.HttpStatusCode mismatch", i, j);
                    Assert.IsFalse(string.IsNullOrEmpty(insertResult.Etag), "partition #{0} row {1}: insertResult.ETag = null or empty", i, j);

                    ITableEntity row = (ITableEntity)insertResult.Result;
                    //
                    // Retrieve
                    //
                    TableOperation retrieveOperation = TableOperation.Retrieve <SampleXStoreEntity>(row.PartitionKey, row.RowKey);
                    TableResult    retrieveResult    = this.xstoreCloudTable.Execute(retrieveOperation);

                    Assert.IsNotNull(retrieveResult, "retrieveResult = null");
                    Assert.AreEqual((int)HttpStatusCode.OK, retrieveResult.HttpStatusCode, "partition #{0} row {1}: retrieveResult.HttpStatusCode mismatch", i, j);
                    SampleXStoreEntity retrievedEntity = (SampleXStoreEntity)retrieveResult.Result;
                    Assert.IsTrue(sampleXStoreEntity.Equals(retrievedEntity), "entry #{0} row {1}: sampleXStoreEntity != retrievedEntity");
                }
            }
        }
        /// <summary>
        /// Insert some entities into the XStore Table.
        /// There will be "numberOfPartitions" partitions
        /// and "numberOfRowsPerPartition" rows per partition.
        /// Assumption is that those entities do NOT exist currently.
        /// </summary>
        /// <param name="jobType"></param>
        /// <param name="jobId"></param>
        /// <param name="entityMessage"></param>
        protected void InsertXStoreEntities(
            string jobType,
            string jobId,
            string entityMessage)
        {
            for (int i = 0; i < this.numberOfPartitions; i++)
            {
                for (int j = 0; j < this.numberOfRowsPerPartition; j++)
                {
                    SampleXStoreEntity sampleXStoreEntity = new SampleXStoreEntity(
                        this.GenerateJobType(jobType, i),
                        this.GenerateJobId(jobId, i, j),
                        this.GenerateMessage(entityMessage, i, j));

                    //
                    // Insert
                    //
                    TableOperation insertOperation = TableOperation.Insert(sampleXStoreEntity);
                    TableResult insertResult = this.xstoreCloudTable.Execute(insertOperation);

                    Assert.IsNotNull(insertResult, "insertResult = null");
                    Assert.AreEqual((int)HttpStatusCode.NoContent, insertResult.HttpStatusCode, "entry #{0} row {1}: insertResult.HttpStatusCode mismatch", i, j);
                    Assert.IsFalse(string.IsNullOrEmpty(insertResult.Etag), "partition #{0} row {1}: insertResult.ETag = null or empty", i, j);

                    ITableEntity row = (ITableEntity)insertResult.Result;
                    //
                    // Retrieve
                    //
                    TableOperation retrieveOperation = TableOperation.Retrieve<SampleXStoreEntity>(row.PartitionKey, row.RowKey);
                    TableResult retrieveResult = this.xstoreCloudTable.Execute(retrieveOperation);

                    Assert.IsNotNull(retrieveResult, "retrieveResult = null");
                    Assert.AreEqual((int)HttpStatusCode.OK, retrieveResult.HttpStatusCode, "partition #{0} row {1}: retrieveResult.HttpStatusCode mismatch", i, j);
                    SampleXStoreEntity retrievedEntity = (SampleXStoreEntity)retrieveResult.Result;
                    Assert.IsTrue(sampleXStoreEntity.Equals(retrievedEntity), "entry #{0} row {1}: sampleXStoreEntity != retrievedEntity");
                }
            }
        }
示例#7
0
        public static InitDynamicReplicatedTableEntity ToInitDynamicReplicatedTableEntity(SampleXStoreEntity xstoreEntity)
        {
            IDictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();

            // we could reflect, but keeping it simple.
            properties.Add("JobType", new EntityProperty(xstoreEntity.JobType));
            properties.Add("JobId", new EntityProperty(xstoreEntity.JobId));
            properties.Add("Message", new EntityProperty(xstoreEntity.Message));

            InitDynamicReplicatedTableEntity entity = new InitDynamicReplicatedTableEntity(
                xstoreEntity.PartitionKey,
                xstoreEntity.RowKey,
                xstoreEntity.ETag,
                properties);

            return(entity);
        }