Пример #1
0
		public void TestBindByNameWithWrappedConnection()
		{
			var wrapped = new ReliableConnection((DbConnection)_connection);

			// if the sql uses the same name twice, we need to set bindbyname to true
			var sql = @"select 
                       :p1 p1,
                        :p1 p1,
                        :p2 p2
                        from dual";

			var args = new
			{
				p1 = "one",
				p2 = "two"
			};

			var result = wrapped.QuerySql<dynamic>(sql, args);
			result = wrapped.QuerySql<dynamic>(sql, args);
		}
Пример #2
0
		public void TestReliableConnection()
		{
			int retries = 0;
			var retryStrategy = new RetryStrategy();
			retryStrategy.MaxRetryCount = 1;
			retryStrategy.Retrying += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

			try
			{
				var builder = new OracleConnectionStringBuilder(_connectionStringBuilder.ConnectionString);
				builder.DataSource = "testserver:9999";
				using (var reliable = new ReliableConnection<OracleConnection>(builder.ConnectionString, retryStrategy))
				{
					reliable.Open();
				}
			}
			catch
			{
			}

			Assert.AreEqual(1, retries);
		}
		public void CanCallWrappedConnectionMultiThreaded()
		{
			var reliable = new ReliableConnection((DbConnection)Connection());
			var foo = reliable.AsParallel<IMultiThreaded>();

			var tasks = new List<Task>();
			for (int i = 0; i < 100; i++)
				tasks.Add(foo.FooAsync(i));

			Task.WaitAll(tasks.ToArray());
		}
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the ReliableCommand class, and bind it to the specified ReliableConnection and innerCommand.
 /// </summary>
 /// <param name="retryStrategy">The retry strategy to use for the command.</param>
 /// <param name="innerConnection">The innerConnection to bind to.</param>
 /// <param name="innerCommand">The innerCommand to bind to.</param>
 public ReliableCommand(IRetryStrategy retryStrategy, ReliableConnection innerConnection, DbCommand innerCommand) : base(innerConnection, innerCommand)
 {
     _retryStrategy = retryStrategy;
 }
		public void ExecuteStoredProcWithTVPThroughReliableConnection()
		{
			using (ReliableConnection retry = new ReliableConnection<SqlConnection>(ConnectionString, RetryStrategy))
			{
				retry.Open();

				// the ListParameterHelper.AddEnumerableClassParameters code looks specifically for SqlCommand. 
				// This test ensures that reliable connections work with this.
				var result = retry.Query<int>("ReflectInt32Table", new int[] { 1, 2, 3, 4, 5 });

				Assert.AreEqual(5, result.Count());
			}
		}
Пример #6
0
		public void NonTransientExceptionDoesNotRetry()
		{
			// all exceptions are bad
			_mockRetryStrategy.Setup(r => r.IsTransientException(It.IsAny<Exception>())).Returns(false);

			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.IsFalse(Retries > 0);
		}
Пример #7
0
		public void AsyncWorksWithReliableConnection()
		{
			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			int result = retry.QuerySqlAsync<int>("SELECT 10").Result.First();

			Assert.AreEqual(10, result);
		}
Пример #8
0
		public void TestReliableConnection()
		{
			int retries = 0;
			var retryStrategy = new RetryStrategy();
			retryStrategy.MaxRetryCount = 1;
			retryStrategy.Retrying += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

			try
			{
				DB2ConnectionStringBuilder connectionStringBuilder = new DB2ConnectionStringBuilder();
				connectionStringBuilder.ConnectionString = "Server=testserver:9999;Database=SAMPLE";
				connectionStringBuilder.UserID = "db2admin";
				connectionStringBuilder.Password = "******";
				using (var reliable = new ReliableConnection<DB2Connection>(connectionStringBuilder.ConnectionString, retryStrategy))
				{
					reliable.Open();
				}
			}
			catch
			{
			}

			Assert.AreEqual(1, retries);
		}
Пример #9
0
		public void AsyncBadOpenPerformsRetry()
		{
			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			RetryStrategy.MaxRetryCount = 5;
			try
			{
				retry.QueryAsync("SELECT 1").Wait();
			}
			catch
			{
			}

			Assert.AreEqual(5, Retries);
		}
Пример #10
0
		public void AsyncBadQueryPerformsRetry()
		{
			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			RetryStrategy.MaxRetryCount = 5;
			try
			{
				retry.QuerySqlAsync("INVALID SQL").Wait();
			}
			catch
			{
			}

			Assert.AreEqual(5, Retries);
		}
Пример #11
0
		public void StoredProcedureParametersDetectedWithReliableSqlConnection()
		{
			ReliableConnection retry = new ReliableConnection(_connection, RetryStrategy);

			// the SqlCommand.DeriveParameters code looks specifically for SqlCommand. 
			// This test ensures that reliable connections work with this.

			using (IDbTransaction t = retry.BeginTransaction())
			{
				retry.ExecuteSql("CREATE PROC InsightTestProc (@Value int = 5) AS SELECT Value=@Value", transaction: t);

				int result = retry.Query<int>("InsightTestProc", new { Value = 1 }, transaction: t).First();

				Assert.AreEqual(1, result);
			}
		}
Пример #12
0
		public void ExecuteStoredProcWithTVPThroughReliableConnection()
		{
			ReliableConnection retry = new ReliableConnection(_connection, RetryStrategy);

			try
			{
				retry.ExecuteSql("CREATE TYPE [Int32Table] AS TABLE ([Value] [int])");
				retry.ExecuteSql("CREATE PROC InsightTestProc (@Value Int32Table READONLY) AS SELECT * FROM @Value");

				// the ListParameterHelper.AddEnumerableClassParameters code looks specifically for SqlCommand. 
				// This test ensures that reliable connections work with this.
				var result = retry.Query<int>("InsightTestProc", new int[] { 1, 2, 3, 4, 5 });

				Assert.AreEqual(5, result.Count());
			}
			finally
			{
				Cleanup("IF EXISTS (SELECT * FROM sys.objects WHERE name = 'InsightTestProc') DROP PROCEDURE [InsightTestProc]");
				Cleanup("IF EXISTS (SELECT * FROM sys.types WHERE name = 'Int32Table') DROP TYPE [Int32Table]");
			}
		}
Пример #13
0
		public void MaxRetryCountCapsNumberOfRetries()
		{
			int retries = 0;
			RetryStrategy.Retrying += (sender, re) => { retries++; };
			RetryStrategy.MaxRetryCount = 5;

			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.AreEqual(5, retries);
		}
Пример #14
0
		public void BadOpenPerformsRetry()
		{
			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.IsTrue(Retries > 0);
		}
 public void ReliableShouldWorkWithTransaction()
 {
     var reliable = new ReliableConnection((DbConnection)Connection());
     using (var conn = reliable.OpenWithTransaction())
     {
         var ret = conn.QuerySql(@"SELECT 1");
     }
 }
Пример #16
0
		public void TestReliableConnection()
		{
			int retries = 0;
			var retryStrategy = new RetryStrategy();
			retryStrategy.MaxRetryCount = 1;
			retryStrategy.Retrying += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

			try
			{
				var builder = new MySqlConnectionStringBuilder(_connectionStringBuilder.ConnectionString);
				builder.Server = "localhost";
				builder.Port = 9999;
				using (var reliable = new ReliableConnection<MySqlConnection>(builder.ConnectionString, retryStrategy))
				{
					reliable.Open();
				}
			}
			catch
			{
			}

			Assert.AreEqual(1, retries);
		}
Пример #17
-1
		public void TestReliableConnection()
		{
			int retries = 0;
			var retryStrategy = new RetryStrategy();
			retryStrategy.MaxRetryCount = 1;
			retryStrategy.Retrying += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

			try
			{
				var builder = new AseConnectionStringBuilder();
				builder.ConnectionString = "Data Source=testserver;Port=9999;User ID=sa;Password=Password1";
				using (var reliable = new ReliableConnection<AseConnection>(builder.ConnectionString, retryStrategy))
				{
					reliable.Open();
				}
			}
			catch
			{
			}

			Assert.AreEqual(1, retries);
		}