Esempio n. 1
0
        public void TestDiscarding()
        {
            using (var dl = new DisposableList())
            {
                var table = new TableWrapper(TestHelpers.GenUnique(TestConfig.TableName), TestConfig.PrimaryStorageAccount, true);
                dl.Add(table.Delete);

                var entity1 = TestHelpers.CreateStarEntity();
                var entity2 = TestHelpers.CreateStarEntity();
                entity2.Version++;
                entity2.Name = "Entity Version 2 name";
                var entity3 = TestHelpers.CreateStarEntity();
                entity3.Name = "Entity Version 3 name";

                TargetTable  ttable = new TargetTable(table);
                XTableResult result;
                StarEntity   rentity;

                result = ttable.Write(TableConvert.ToDynamicTableEntity(entity1));
                Assert.IsFalse(result.Discarded);
                rentity = table.ReadEntity <StarEntity>(entity3.PartitionKey, entity3.RowKey);
                TestHelpers.AssertEqualStars(entity1, rentity);

                result = ttable.Write(TableConvert.ToDynamicTableEntity(entity2));
                Assert.IsFalse(result.Discarded);
                rentity = table.ReadEntity <StarEntity>(entity3.PartitionKey, entity3.RowKey);
                TestHelpers.AssertEqualStars(entity2, rentity);

                result = ttable.Write(TableConvert.ToDynamicTableEntity(entity3));
                Assert.IsTrue(result.Discarded);
                rentity = table.ReadEntity <StarEntity>(entity3.PartitionKey, entity3.RowKey);
                TestHelpers.AssertEqualStars(entity2, rentity);
            }
        }
Esempio n. 2
0
        public void TestETagViolation409()
        {
            using (var dl = new DisposableList())
            {
                var table = new TableWrapper(TestHelpers.GenUnique(TestConfig.TableName), TestConfig.PrimaryStorageAccount, true);
                dl.Add(table.Delete);

                var entity1 = TestHelpers.CreateStarEntity();
                entity1.Version = 1;
                var entity2 = TestHelpers.CreateStarEntity();
                entity2.Version = 2;
                entity2.Name    = "Entity Version 2 name";

                TargetTable  ttable = new TargetTable(table);
                XTableResult result;

                int retryAttempt = 0;
                result = ttable.Write(
                    TableConvert.ToDynamicTableEntity(entity1),
                    () => {
                    if (retryAttempt++ == 0)
                    {
                        result = ttable.Write(TableConvert.ToDynamicTableEntity(entity2));
                        Assert.AreEqual(false, result.Discarded);
                    }
                }
                    );
                Assert.AreEqual(true, result.Discarded);

                var rentity = table.ReadEntity <StarEntity>(entity1.PartitionKey, entity1.RowKey);
                TestHelpers.AssertEqualStars(entity2, rentity);
            }
        }
Esempio n. 3
0
        public void EntityConsistent()
        {
            using (var dl = new DisposableList())
            {
                // create the source table
                var sourceTableWrapper = new TableWrapper(TestHelpers.GenUnique(TestConfig.TableName), TestConfig.PrimaryStorageAccount, true);
                dl.Add(sourceTableWrapper.Delete);

                // initialize the target table and attach it to the disposable container
                var targetTable = new TableWrapper(TestHelpers.GenUnique(TestConfig.TableName), TestConfig.SecondaryStorageAccount, true);
                dl.Add(targetTable.Delete);
                var tableParamsResolver = new InMemoryTargetTableResolver();
                tableParamsResolver.Add(TestHelpers.TableKey, targetTable);

                // create gateway blob storage
                var gateBlob = new InMemoryGatewayBlobStore();

                // create a gateway queue
                var gateQueue       = new QueueWrapper(TestHelpers.GenUnique("gateq"), TestConfig.GatewayStorageAccount);
                var gateQueueWriter = new GatewayQueueWriter(gateQueue, gateBlob);

                var sourceTable = new SourceTable <StarEntity>(sourceTableWrapper, gateQueueWriter, TestHelpers.TableKey);

                var entity = TestHelpers.CreateStarEntity();

                // write the entity
                sourceTable.Write(entity);

                // now verify that the entity was synced to the secondary table storage
                TableGatewayQueueProcessor gateQueueProcessor = new TableGatewayQueueProcessor(
                    new GatewayQueueReader(gateQueue, gateBlob),
                    tableParamsResolver
                    );

                bool result = gateQueueProcessor.ProcessNext();

                Assert.IsTrue(result);

                var targetEntity = targetTable.ReadEntity <StarEntity>(entity.PartitionKey, entity.RowKey);
                TestHelpers.AssertEqualStars(entity, targetEntity);
            }
        }