コード例 #1
0
        public void CommitTransaction(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSource");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c    = new TwoColumnsTableFixture(connection, "TransactionDest");
            DbSource <MySimpleRow>      source = new DbSource <MySimpleRow>(connection, "TransactionSource");
            DbDestination <MySimpleRow> dest   = new DbDestination <MySimpleRow>(connection, "TransactionDest", batchSize: 2);

            //Act & Assert
            connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            source.LinkTo(dest);

            source.Execute();
            dest.Wait();

            //Assert
            if (connection.GetType() == typeof(SqlConnectionManager))
            {
                Assert.Equal(3, RowCountTask.Count(connection.Clone(), "TransactionDest", RowCountOptions.NoLock));
            }
            connection.CommitTransaction();
            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest"));
            Assert.Equal(3, RowCountTask.Count(connection.Clone(), "TransactionDest"));

            //Assert Connections are closed
            Assert.True(dest.BulkInsertConnectionManager.State == null);
            Assert.True(connection.State == null);
        }
コード例 #2
0
        public void TwoTransactionsAndParallelWriting(IConnectionManager connection)
        {
            if (connection.ConnectionManagerType == ConnectionManagerType.SQLite)
            {
                return;
            }
            //Arrange
            var concopy = connection.Clone();
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSourceParallelWrite");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c1      = new TwoColumnsTableFixture(connection, "TransactionDest1");
            TwoColumnsTableFixture      d2c2      = new TwoColumnsTableFixture(connection, "TransactionDest2");
            DbSource <MySimpleRow>      source    = new DbSource <MySimpleRow>(connection, "TransactionSourceParallelWrite");
            DbDestination <MySimpleRow> dest1     = new DbDestination <MySimpleRow>(connection, "TransactionDest1", batchSize: 2);
            DbDestination <MySimpleRow> dest2     = new DbDestination <MySimpleRow>(concopy, "TransactionDest2", batchSize: 2);
            Multicast <MySimpleRow>     multicast = new Multicast <MySimpleRow>();

            //Act & Assert
            connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            concopy.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);

            source.Execute();
            dest1.Wait();
            dest2.Wait();
            connection.CommitTransaction();
            concopy.CommitTransaction();

            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest1"));
            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest2"));
        }
コード例 #3
0
        public void LeaveOpen(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSource");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c    = new TwoColumnsTableFixture(connection, "TransactionDest");
            DbSource <MySimpleRow>      source = new DbSource <MySimpleRow>(connection, "TransactionSource");
            DbDestination <MySimpleRow> dest   = new DbDestination <MySimpleRow>(connection, "TransactionDest", batchSize: 2);

            //Act
            connection.LeaveOpen = true;
            connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            connection.CommitTransaction();

            //Assert
            Assert.Equal(connection, dest.BulkInsertConnectionManager);

            //Assert Connections are closed
            Assert.True(dest.BulkInsertConnectionManager.State == System.Data.ConnectionState.Open);
            Assert.True(connection.State == System.Data.ConnectionState.Open);

            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest"));
        }
コード例 #4
0
        public void OneTransactionAndParallelWriting(IConnectionManager connection)
        {
            if (connection.ConnectionManagerType == ConnectionManagerType.SQLite)
            {
                return;
            }
            if (connection.ConnectionManagerType == ConnectionManagerType.Oracle)
            {
                return;
            }

            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSourceParallelWrite");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c1      = new TwoColumnsTableFixture(connection, "TransactionDest1");
            TwoColumnsTableFixture      d2c2      = new TwoColumnsTableFixture(connection, "TransactionDest2");
            DbSource <MySimpleRow>      source    = new DbSource <MySimpleRow>(connection, "TransactionSourceParallelWrite");
            DbDestination <MySimpleRow> dest1     = new DbDestination <MySimpleRow>(connection, "TransactionDest1", batchSize: 2);
            DbDestination <MySimpleRow> dest2     = new DbDestination <MySimpleRow>(connection, "TransactionDest2", batchSize: 2);
            Multicast <MySimpleRow>     multicast = new Multicast <MySimpleRow>();

            //Act & Assert
            Assert.ThrowsAny <Exception>(() =>
            {
                try
                {
                    connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                    source.LinkTo(multicast);
                    multicast.LinkTo(dest1);
                    multicast.LinkTo(dest2);

                    source.Execute();
                    dest1.Wait();
                    dest2.Wait();
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.RollbackTransaction();
                    connection.Close();
                }
            });
            if (connection.GetType() == typeof(MySqlConnectionManager))
            {
                Task.Delay(200).Wait(); //MySql needs a little bit longer to free resources
            }
        }
コード例 #5
0
        private TResult TransactionalImpl <TResult>(Func <TResult> acao)
        {
            var commit = true;

            try
            {
                ConnectionManager.BeginTransaction();
                return(acao.Invoke());
            }
            catch (Exception)
            {
                commit = false;
                throw;
            }
            finally
            {
                ConnectionManager.EndTransaction(commit);
            }
        }
コード例 #6
0
        public void CloseConnectionDuringTransaction(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSource");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c    = new TwoColumnsTableFixture(connection, "TransactionDest");
            DbSource <MySimpleRow>      source = new DbSource <MySimpleRow>(connection, "TransactionSource");
            DbDestination <MySimpleRow> dest   = new DbDestination <MySimpleRow>(connection, "TransactionDest", batchSize: 2);

            //Act & Assert
            connection.BeginTransaction();
            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest"));
            connection.Close();
            Assert.Equal(0, RowCountTask.Count(connection, "TransactionDest"));

            //Assert Connections are closed
            Assert.True(dest.BulkInsertConnectionManager.State == null);
            Assert.True(connection.State == null);
        }
コード例 #7
0
        public void WriteParallelWhileTransactionOpen(IConnectionManager connection, int numberOfRows)
        {
            //Arrange
            BigDataCsvSource.CreateCSVFileIfNeeded(numberOfRows);
            ReCreateDestinationTable(connection, "TransactionDestination1");
            ReCreateDestinationTable(connection, "TransactionDestination2");

            var source = new CsvSource(BigDataCsvSource.GetCompleteFilePath(numberOfRows));
            var dest1  = new DbDestination(connection, "TransactionDestination1");
            var dest2  = new DbDestination(connection, "TransactionDestination2");
            var multi  = new Multicast();

            //Act & Assert
            Assert.ThrowsAny <Exception>(() =>
            {
                connection.BeginTransaction();
                source.LinkTo(multi);
                multi.LinkTo(dest1);
                multi.LinkTo(dest2);
                source.Execute();
                dest1.Wait();
                dest2.Wait();
            });
        }
コード例 #8
0
 public async Task BeforeExecute(ICallExecutionContext context)
 {
     _connectionManager.BeginTransaction();
 }