/// <summary>
        /// Ensures the storage with the given connection is functional and if not, tries to make it functional.
        /// </summary>
        /// <param name="connection">The connection with which to ensure the storage is functional.</param>
        /// <param name="storageName">Storage name. This is optional.</param>
        /// <returns></returns>
        public RelationalStorageForTesting EnsureStorageForTesting(StorageConnection connection, string storageName = null)
        {
            if (AdoNetInvariants.Invariants.Contains(connection.StorageInvariant))
            {
                const string RelationalStorageTestDb = "OrleansStorageTests";
                return(RelationalStorageForTesting.SetupInstance(connection.StorageInvariant, storageName ?? RelationalStorageTestDb, connection.ConnectionString).GetAwaiter().GetResult());
            }

            return(null);
        }
        /// <summary>
        /// Checks if a given storage is reachable.
        /// </summary>
        /// <param name="connection">The connection to check.</param>
        /// <returns></returns>
        private static async Task <bool> CanConnectToStorage(StorageConnection connection)
        {
            //How detect if a database can be connected is surprisingly tricky. Some information at
            //http://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most.
            var storage = RelationalStorage.CreateInstance(connection.StorageInvariant, connection.ConnectionString);
            var query   = connection.ConnectionString != AdoNetInvariants.InvariantNameOracleDatabase ? "SELECT 1;" : "SELECT 1 FROM DUAL;";

            try
            {
                await storage.ExecuteAsync(query);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Ensures the storage with the given connection is functional and if not, tries to make it functional.
        /// </summary>
        /// <param name="connection">The connection with which to ensure the storage is functional.</param>
        /// <param name="storageName">Storage name. This is optional.</param>
        /// <returns></returns>
        public RelationalStorageForTesting EnsureStorageForTesting(StorageConnection connection, string storageName = null)
        {

            if(AdoNetInvariants.Invariants.Contains(connection.StorageInvariant))
            {
                const string RelationalStorageTestDb = "OrleansStorageTests";
                return RelationalStorageForTesting.SetupInstance(connection.StorageInvariant, storageName ?? RelationalStorageTestDb, connection.ConnectionString).GetAwaiter().GetResult();
            }

            return null;
        }
        /// <summary>
        /// Checks if a given storage is reachable.
        /// </summary>
        /// <param name="connection">The connection to check.</param>
        /// <returns></returns>
        private static async Task<bool> CanConnectToStorage(StorageConnection connection)
        {
            //How detect if a database can be connected is surprisingly tricky. Some information at
            //http://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most.
            var storage = RelationalStorage.CreateInstance(connection.StorageInvariant, connection.ConnectionString);
            var query = connection.ConnectionString != AdoNetInvariants.InvariantNameOracleDatabase ? "SELECT 1;" : "SELECT 1 FROM DUAL;";
            try
            {
                await storage.ExecuteAsync(query);
            }
            catch
            {
                return false;
            }

            return true;
        }