public void TestQueue() { using (var dl = new DisposableList()) { var docs = TestHelpers.CreateStarDocuments(3); var original = DocdbGatewayMessage.Create("Star", docs); var queue = new QueueWrapper(TestHelpers.GenUnique("gateq"), TestConfig.GatewayStorageAccount); dl.Add(queue.Delete); var blobStorage = new InMemoryGatewayBlobStore(); GatewayQueueWriter writer = new GatewayQueueWriter(queue, blobStorage); writer.Write(original); GatewayQueueReader reader = new GatewayQueueReader(queue, blobStorage); reader.ReadNextMessage <DocdbGatewayMessage>( gm => { var rdocs = gm.DocumentsAs <StarDocument>().ToList(); Assert.AreEqual(docs.Count, rdocs.Count); for (int i = 0; i < rdocs.Count; ++i) { TestHelpers.AssertEqualStars(docs[i], rdocs[i]); } }, (e, gm, cqm) => Assert.Fail()); } }
public void BulkOfEntitiesConsistent() { 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); // 100 entities to satisfy TableStorage's batch requirements var entities = TestHelpers.CreateStarEntities(100); sourceTable.Write(entities); // Now verify that the entities were synced to the secondary table storage TableGatewayQueueProcessor gateQueueProcessor = new TableGatewayQueueProcessor( new GatewayQueueReader(gateQueue, gateBlob), tableParamsResolver ); bool result = gateQueueProcessor.ProcessNext(); Assert.IsTrue(result); var targetEntities = targetTable.ReadEntities <StarEntity>() .ToList(); Assert.AreEqual(entities.Count, targetEntities.Count); foreach (var entity in entities) { TestHelpers.AssertEqualStars( entity, targetEntities.First(x => x.RowKey == entity.RowKey) ); } } }
public void PackUnpack() { var doc = TestHelpers.CreateStarDocument(); var original = DocdbGatewayMessage.Create("Star", doc); var storage = new InMemoryGatewayBlobStore(); byte[] packed = GatewayPacket.Pack(original, storage); var unpacked = GatewayPacket.Unpack <DocdbGatewayMessage>(packed, storage); Assert.AreEqual(original.Key, unpacked.Key); TestHelpers.AssertEqualStars( original.DocumentsAs <StarDocument>().First(), unpacked.DocumentsAs <StarDocument>().First() ); }
public void PackUnpack() { var entity = TestHelpers.CreateStarEntity(); var original = TableGatewayMessage.Create("Person", entity); var storage = new InMemoryGatewayBlobStore(); byte[] packed = GatewayPacket.Pack(original, storage); TableGatewayMessage unpacked = GatewayPacket.Unpack <TableGatewayMessage>(packed, storage); Assert.AreEqual(original.Key, unpacked.Key); TestHelpers.AssertEqualStars( original.EntitiesAs <StarEntity>().First(), unpacked.EntitiesAs <StarEntity>().First() ); }
public void TestMultiQueueBig() { using (var dl = new DisposableList()) { var entities = TestHelpers.CreateStarEntities(10000); var original = TableGatewayMessage.Create("Star", entities); List <QueueWrapper> queues = new List <QueueWrapper>(); for (int i = 0; i < 3; ++i) { var queue = new QueueWrapper(TestHelpers.GenUnique("gateq" + i), TestConfig.GatewayStorageAccount); dl.Add(queue.Delete); queues.Add(queue); } var blobStorage = new InMemoryGatewayBlobStore(); GatewayMultiQueueWriter writer = new GatewayMultiQueueWriter(queues, blobStorage); writer.Write(original); Assert.AreEqual(1, blobStorage.Count); foreach (var queue in queues) { GatewayQueueReader reader = new GatewayQueueReader(queue, blobStorage); bool processed = false; reader.ReadNextMessage <TableGatewayMessage>( gm => { var rentities = gm.EntitiesAs <StarEntity>().ToList(); Assert.AreEqual(entities.Count, rentities.Count); for (int i = 0; i < rentities.Count; ++i) { TestHelpers.AssertEqualStars(entities[i], rentities[i]); } processed = true; }, (e, gm, cqm) => Assert.Fail()); Assert.IsTrue(processed); } } }
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); } }
public void DocumentConsistent() { const string gatewayKey = "Stars"; // 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 doc = TestHelpers.CreateStarDocument(); SourceCollection scol = new SourceCollection(_primaryClient, _primaryCollection, gateQueueWriter, gatewayKey); DocdbGatewayQueueProcessor gateQueueProcessor = new DocdbGatewayQueueProcessor( new GatewayQueueReader(gateQueue, gateBlob), new FixedTargetCollectionResolver(_secondaryClient, _secondaryCollection) ); var tcol = new TargetCollection(_secondaryClient, _secondaryCollection); scol.Write(doc); Assert.IsTrue(gateQueueProcessor.ProcessNext()); var tdoc = tcol.ReadDocument <StarDocument>(doc.Id); TestHelpers.AssertEqualStars(doc, tdoc); Assert.AreEqual(1, tdoc.Version); // same Id but different data in the object doc = TestHelpers.CreateStarDocument(); scol.Write(doc); Assert.AreEqual(2, doc.Version); // verify the side effect of setting Version Assert.IsTrue(gateQueueProcessor.ProcessNext()); tdoc = tcol.ReadDocument <StarDocument>(doc.Id); TestHelpers.AssertEqualStars(doc, tdoc); Assert.AreEqual(2, tdoc.Version); }