public async Task PersistenceProvider_Mock_WriteRead() { string testName = TestContext.TestName; IStorageProvider store = new MockStorageProvider(); var cfg = new ProviderConfiguration(providerCfgProps, null); await store.Init(testName, storageProviderManager, cfg); await Test_PersistenceProvider_WriteRead(testName, store); }
public async Task PersistenceProvider_FileStore_WriteRead() { string testName = TestContext.TestName; IStorageProvider store = new OrleansFileStorage(); providerCfgProps.Add("RootDirectory", "Data"); var cfg = new ProviderConfiguration(providerCfgProps, null); await store.Init(testName, storageProviderManager, cfg); await Test_PersistenceProvider_WriteRead(testName, store); }
public async Task SendAndReceiveFromAzureQueue() { var properties = new Dictionary<string, string> { {AzureQueueAdapterFactory.DataConnectionStringPropertyName, StorageTestConstants.DataConnectionString}, {AzureQueueAdapterFactory.DeploymentIdPropertyName, deploymentId} }; var config = new ProviderConfiguration(properties, "type", "name"); var adapterFactory = new AzureQueueAdapterFactory(); adapterFactory.Init(config, AZURE_QUEUE_STREAM_PROVIDER_NAME, TraceLogger.GetLogger("AzureQueueAdapter", TraceLogger.LoggerType.Application), new DefaultServiceProvider()); await SendAndReceiveFromQueueAdapter(adapterFactory, config); }
public async Task SendAndReceiveFromSQS() { var properties = new Dictionary<string, string> { {SQSAdapterFactory.DataConnectionStringPropertyName, AWSTestConstants.DefaultSQSConnectionString}, {SQSAdapterFactory.DeploymentIdPropertyName, deploymentId} }; var config = new ProviderConfiguration(properties, "type", "name"); var adapterFactory = new SQSAdapterFactory(); adapterFactory.Init(config, SQS_STREAM_PROVIDER_NAME, LogManager.GetLogger("SQSAdapter", LoggerType.Application), null); await SendAndReceiveFromQueueAdapter(adapterFactory, config); }
public async Task SendAndReceiveFromAzureQueue() { var properties = new Dictionary<string, string> { {AzureQueueAdapterFactory.DataConnectionStringPropertyName, TestDefaultConfiguration.DataConnectionString}, {AzureQueueAdapterFactory.DeploymentIdPropertyName, deploymentId}, {AzureQueueAdapterFactory.MessageVisibilityTimeoutPropertyName, "00:00:30" } }; var config = new ProviderConfiguration(properties, "type", "name"); var adapterFactory = new AzureQueueAdapterFactory(); adapterFactory.Init(config, AZURE_QUEUE_STREAM_PROVIDER_NAME, LogManager.GetLogger("AzureQueueAdapter", LoggerType.Application), null); await SendAndReceiveFromQueueAdapter(adapterFactory, config); }
// Load from an element with the format <NameProviders>...</NameProviders> // that contains a sequence of Provider elements (see the ProviderConfiguration type) internal static ProviderCategoryConfiguration Load(XmlElement child) { string name = child.LocalName.Substring(0, child.LocalName.Length - 9); var category = new ProviderCategoryConfiguration(name); var nsManager = new XmlNamespaceManager(new NameTable()); nsManager.AddNamespace("orleans", "urn:orleans"); ProviderConfiguration.LoadProviderConfigurations( child, nsManager, category.Providers, c => category.Providers.Add(c.Name, c)); return(category); }
// Load from an element with the format <NameProviders>...</NameProviders> // that contains a sequence of Provider elements (see the ProviderConfiguration type) internal void Load(XmlElement child) { if (!child.LocalName.EndsWith("Providers", StringComparison.Ordinal)) { throw new FormatException("Providers node name is not correct at element " + child.LocalName); } Name = child.LocalName.Substring(0, child.LocalName.Length - 9); Providers = new Dictionary <string, IProviderConfiguration>(); var nsManager = new XmlNamespaceManager(new NameTable()); nsManager.AddNamespace("orleans", "urn:orleans"); ProviderConfiguration.LoadProviderConfigurations(child, nsManager, Providers, c => Providers.Add(c.Name, c)); }
public DynamoDBStorageProviderTests() { if (!AWSTestConstants.IsDynamoDbAvailable) throw new SkipException("Unable to connect to DynamoDB simulator"); DefaultProviderRuntime = new StorageProviderManager(new GrainFactory(), null); ((StorageProviderManager)DefaultProviderRuntime).LoadEmptyStorageProviders(new ClientProviderRuntime(new GrainFactory(), null)).WaitWithThrow(TestConstants.InitTimeout); SerializationManager.InitializeForTesting(); var properties = new Dictionary<string, string>(); properties["DataConnectionString"] = $"Service={AWSTestConstants.Service}"; var config = new ProviderConfiguration(properties, null); var provider = new DynamoDBStorageProvider(); provider.Init("DynamoDBStorageProviderTests", DefaultProviderRuntime, config).Wait(); PersistenceStorageTests = new CommonStorageTests(provider); }
internal static void LoadProviderConfigurations(XmlElement root, XmlNamespaceManager nsManager, IDictionary <string, IProviderConfiguration> alreadyLoaded, Action <ProviderConfiguration> add) { var nodes = root.SelectNodes("orleans:Provider", nsManager); foreach (var node in nodes) { var subElement = node as XmlElement; if (subElement == null) { continue; } var config = new ProviderConfiguration(); config.Load(subElement, alreadyLoaded, nsManager); add(config); } }
internal static void RegisterProvider(IDictionary <string, ProviderCategoryConfiguration> providerConfigurations, string providerCategory, string providerTypeFullName, string providerName, IDictionary <string, string> properties = null) { if (string.IsNullOrEmpty(providerCategory)) { throw new ArgumentException("Provider Category cannot be null or empty string", "providerCategory"); } if (string.IsNullOrEmpty(providerTypeFullName)) { throw new ArgumentException("Provider type full name cannot be null or empty string", "providerTypeFullName"); } if (string.IsNullOrEmpty(providerName)) { throw new ArgumentException("Provider name cannot be null or empty string", "providerName"); } ProviderCategoryConfiguration category; if (!providerConfigurations.TryGetValue(providerCategory, out category)) { category = new ProviderCategoryConfiguration(providerCategory); providerConfigurations.Add(category.Name, category); } if (category.Providers.ContainsKey(providerName)) { throw new InvalidOperationException( string.Format("{0} provider of type {1} with name '{2}' has been already registered", providerCategory, providerTypeFullName, providerName)); } var config = new ProviderConfiguration( properties ?? new Dictionary <string, string>(), providerTypeFullName, providerName); category.Providers.Add(config.Name, config); }
internal static void RegisterProvider(IDictionary<string, ProviderCategoryConfiguration> providerConfigurations, string providerCategory, string providerTypeFullName, string providerName, IDictionary<string, string> properties = null) { if (string.IsNullOrEmpty(providerCategory)) throw new ArgumentException("Provider Category cannot be null or empty string", "providerCategory"); if (string.IsNullOrEmpty(providerTypeFullName)) throw new ArgumentException("Provider type full name cannot be null or empty string", "providerTypeFullName"); if (string.IsNullOrEmpty(providerName)) throw new ArgumentException("Provider name cannot be null or empty string", "providerName"); ProviderCategoryConfiguration category; if (!providerConfigurations.TryGetValue(providerCategory, out category)) { category = new ProviderCategoryConfiguration(providerCategory); providerConfigurations.Add(category.Name, category); } if (category.Providers.ContainsKey(providerName)) throw new InvalidOperationException( string.Format("{0} provider of type {1} with name '{2}' has been already registered", providerCategory, providerTypeFullName, providerName)); var config = new ProviderConfiguration( properties ?? new Dictionary<string, string>(), providerTypeFullName, providerName); category.Providers.Add(config.Name, config); }
internal static void LoadProviderConfigurations(XmlElement root, XmlNamespaceManager nsManager, IDictionary<string, IProviderConfiguration> alreadyLoaded, Action<ProviderConfiguration> add) { var nodes = root.SelectNodes("orleans:Provider", nsManager); foreach (var node in nodes) { var subElement = node as XmlElement; if (subElement == null) continue; var config = new ProviderConfiguration(); config.Load(subElement, alreadyLoaded, nsManager); add(config); } }
/// <summary> /// Returns a correct implementation of the persistence provider according to environment variables. /// </summary> /// <remarks>If the environment invariants have failed to hold upon creation of the storage provider, /// a <em>null</em> value will be provided.</remarks> public async Task<IStorageProvider> GetStorageProvider(string storageInvariant) { //Make sure the environment invariants hold before trying to give a functioning SUT instantiation. //This is done instead of the constructor to have more granularity on how the environment should be initialized. try { using(await StorageLock.LockAsync()) { if(AdoNetInvariants.Invariants.Contains(storageInvariant)) { if(!StorageProviders.ContainsKey(storageInvariant)) { Storage = Invariants.EnsureStorageForTesting(Invariants.ActiveSettings.ConnectionStrings.First(i => i.StorageInvariant == storageInvariant)); var properties = new Dictionary<string, string>(); properties["DataConnectionString"] = Storage.Storage.ConnectionString; properties["AdoInvariant"] = storageInvariant; var config = new ProviderConfiguration(properties, null); var storageProvider = new AdoNetStorageProvider(); await storageProvider.Init(storageInvariant + "_StorageProvider", DefaultProviderRuntime, config); StorageProviders[storageInvariant] = storageProvider; } } } } catch { StorageProviders.Add(storageInvariant, null); } return StorageProviders[storageInvariant]; }
private async Task<ShardedStorageProvider> ConfigureShardedStorageProvider(string name, StorageProviderManager storageProviderMgr) { var composite = new ShardedStorageProvider(); var provider1 = (IStorageProvider)storageProviderMgr.GetProvider("Store1"); var provider2 = (IStorageProvider)storageProviderMgr.GetProvider("Store2"); List<IProvider> providers = new List<IProvider>(); providers.Add(provider1); providers.Add(provider2); var cfg = new ProviderConfiguration(providerCfgProps, providers); await composite.Init(name, storageProviderMgr, cfg); return composite; }
public async Task PersistenceProvider_Memory_FixedLatency_WriteRead() { string testName = TestContext.TestName; TimeSpan expectedLatency = TimeSpan.FromMilliseconds(200); IStorageProvider store = new MemoryStorageWithLatency(); providerCfgProps.Add("Latency", expectedLatency.ToString()); providerCfgProps.Add("MockCalls", "true"); var cfg = new ProviderConfiguration(providerCfgProps, null); await store.Init(testName, storageProviderManager, cfg); GrainReference reference = GrainReference.FromGrainId(GrainId.NewId()); var state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(testName, reference, state); TimeSpan writeTime = sw.Elapsed; Console.WriteLine("{0} - Write time = {1}", store.GetType().FullName, writeTime); Assert.IsTrue(writeTime >= expectedLatency, "Write: Expected minimum latency = {0} Actual = {1}", expectedLatency, writeTime); sw.Restart(); var storedState = new GrainState<TestStoreGrainState>(); await store.ReadStateAsync(testName, reference, storedState); TimeSpan readTime = sw.Elapsed; Console.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); Assert.IsTrue(readTime >= expectedLatency, "Read: Expected minimum latency = {0} Actual = {1}", expectedLatency, readTime); }
public async Task PersistenceProvider_Azure_WriteRead_Json() { string testName = TestContext.TestName; IStorageProvider store = new AzureTableStorage(); providerCfgProps.Add("DataConnectionString", StorageTestConstants.DataConnectionString); providerCfgProps.Add("UseJsonFormat", "true"); var cfg = new ProviderConfiguration(providerCfgProps, null); await store.Init(testName, storageProviderManager, cfg); await Test_PersistenceProvider_WriteRead(testName, store); }