Esempio n. 1
0
        public async Task OpenAsync_WithRetry()
        {
            IConnectionFactory factory = new SqliteConnectionFactoryWithRetry(10, TimeSpan.FromSeconds(30));

            using (var connection = await factory.OpenAsync(_connectionString))
            {
                Assert.IsNotNull(connection);
                Assert.AreEqual(ConnectionState.Open, connection.State);
                connection.Close();
            }
        }
        public void BeginTransaction_WithRetry()
        {
            var retryOptions = new RetryOptions(10, TimeSpan.FromSeconds(60));

            ITransactionFactory transactionFactory = new SqliteTransactionFactoryWithRetry(retryOptions);
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactoryWithRetry(retryOptions);

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Serializable, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
        public void BeginTransaction_WithIsolationLevel_WithRetry_Fail()
        {
            // sqlite only supports IsolationLevel.Serializable
            var retryPolicy = new SqliteTransientRetryPolicy(10, TimeSpan.FromSeconds(60));

            ITransactionFactory transactionFactory = new SqliteTransactionFactoryWithRetry(retryPolicy);
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactoryWithRetry(retryPolicy);

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection, IsolationLevel.Snapshot))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Snapshot, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }