internal async Task GenerateWithValueType <ValueType>(string logFolder, ValueType value, IStateSerializer <ValueType> valueSerializer) { // directory setup if (FabricDirectory.Exists(logFolder)) { FabricDirectory.Delete(logFolder, true); } FabricDirectory.CreateDirectory(logFolder); var rand = new Random(); var reliabilitySimulator = new ReliabilitySimulator( logFolder, new Uri("fabric:/unittest/service" + rand.Next()), // random service name. OnDataLossCallback, // we are never calling OnDataLossAsync on this ReliabilitySimulator. CreateStateProvider); reliabilitySimulator.CreateReplica(true, false); var replicator = reliabilitySimulator.GetTransactionalReplicator(); replicator.TryAddStateSerializer <ValueType>(valueSerializer); // Constants var distributedDictionary = new DistributedDictionary <long, ValueType>(); var distributedQueue = new DistributedQueue <ValueType>(); var concurrentQueue = new ReliableConcurrentQueue <ValueType>(); // Setup await reliabilitySimulator.OpenReplicaAsync(ReplicaOpenMode.New).ConfigureAwait(false); await reliabilitySimulator.PromoteReplicaAsync(false).ConfigureAwait(false); var result = replicator.CreateAsyncEnumerable(false, false); Assert.AreEqual(0, result.ToEnumerable().Count(), "State Manager must be empty"); // Write data. using (var txn = replicator.CreateTransaction()) { await replicator.AddStateProviderAsync(txn, DictionaryName, distributedDictionary).ConfigureAwait(false); await txn.CommitAsync().ConfigureAwait(false); } result = replicator.CreateAsyncEnumerable(false, false); Assert.AreEqual(2, result.ToEnumerable().Count(), "State Manager must include all the state providers"); await PopulateDictionaryAsync(replicator, DictionaryName, 0, 8, 8, value).ConfigureAwait(false); // Take backup await replicator.BackupAsync(ComplexDataBackupCallbackAsync).ConfigureAwait(false); // Clean up. await reliabilitySimulator.DropReplicaAsync(); }
/// <summary> /// Constructor of TransactionChangeManager. /// </summary> public TransactionChangeManager(ReliabilitySimulator reliabilitySimulator) { this.reliabilitySimulator = reliabilitySimulator; this.reliableCollectionsChanges = new Dictionary <Uri, ReliableCollectionChange>(); }
/// <summary> /// Constructor of StateManager. /// </summary> /// <param name="reliabilitySimulator">ReliabilitySimulator that </param> public StateManager(ReliabilitySimulator reliabilitySimulator) { this.reliabilitySimulator = reliabilitySimulator; this.stateSerializers = new Dictionary <Type, object>(); }
protected static async Task GenerateBackup(string logFolder) { const int NumberOfStateProviders = 6; if (Directory.Exists(logFolder)) { Directory.Delete(logFolder, true); } Directory.CreateDirectory(logFolder); var reliabilitySimulator = new ReliabilitySimulator( logFolder, new Uri("fabric:/unittest/service"), DateTime.UtcNow.ToFileTimeUtc(), DateTime.UtcNow.ToFileTimeUtc(), OnDataLossCallback, CreateStateProvider); reliabilitySimulator.CreateReplica(true, false); var replicator = reliabilitySimulator.GetTransactionalReplicator(); // Constants var distributedDictionary = new DistributedDictionary <long, long>(); var distributedQueue = new DistributedQueue <long>(); var concurrentQueue = new ReliableConcurrentQueue <long>(); // Setup await reliabilitySimulator.OpenReplicaAsync(ReplicaOpenMode.New).ConfigureAwait(false); await reliabilitySimulator.PromoteReplicaAsync(false).ConfigureAwait(false); var result = replicator.CreateAsyncEnumerable(false, false); Assert.AreEqual(0, result.ToEnumerable().Count(), "State Manager must be empty"); // Write data. using (var txn = replicator.CreateTransaction()) { await replicator.AddStateProviderAsync(txn, DictionaryName, distributedDictionary).ConfigureAwait(false); await replicator.AddStateProviderAsync(txn, QueueName, distributedQueue).ConfigureAwait(false); await replicator.AddStateProviderAsync(txn, ConcurrentQueueName, concurrentQueue).ConfigureAwait(false); await txn.CommitAsync().ConfigureAwait(false); } result = replicator.CreateAsyncEnumerable(false, false); Assert.AreEqual(NumberOfStateProviders, result.ToEnumerable().Count(), "State Manager must include all the state providers"); // Assumptions by tests for the backup generated. // 1. TotalDictionaryInserts contains total no of keys in dictionary. // 2. If there are n keys in dictionary, then they are from 0 - (n-1). int batchCount = 8, batchSize = 8; await CollectionHelper.PopulateDictionaryAsync(replicator, DictionaryName, 0, batchCount, batchSize).ConfigureAwait(false); await CollectionHelper.PopulateQueueAsync(replicator, QueueName, 0, batchCount, batchSize).ConfigureAwait(false); await CollectionHelper.PopulateConcurrentQueueAsync(replicator, ConcurrentQueueName, 0, batchCount, batchSize).ConfigureAwait(false); // Take backup await replicator.BackupAsync(BackupCallbackAsync).ConfigureAwait(false); // Clean up. await reliabilitySimulator.DropReplicaAsync(); NumOperationsPerTransaction = batchSize; TotalDictionaryInserts = batchCount * batchSize; TotalDictionaryTransactions = batchCount; TotalQueueTransactions = batchCount; TotoalConcurrentQueueTransactions = batchCount; // + 1 for backup TotalTransactions = TotalDictionaryTransactions + TotalQueueTransactions + TotoalConcurrentQueueTransactions + 1; }