/// <summary> /// Finds exisiting entities for the batch /// </summary> protected List <VersionedTableEntity> FindExistingVersions(IList <T> batch, string partitionKey) { string filter = string.Empty; // Add Entities RowKey for (int i = 0; i < batch.Count; ++i) { if (i > 0) { filter += " or "; } filter += TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, batch[i].RowKey); } // Filter by Partition Key filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey), TableOperators.And, filter); // Read only Version column along with PartitionKey and RowKey List <VersionedTableEntity> entities = Table .ReadEntities <VersionedTableEntity>(new List <string> { VersionColumn }, filter) .ToList(); return(entities); }
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) ); } } }