public void TestRecoverAfterFailOnTransactionAfterPrepareSent() { // Test initialize - Fills in queue with data to send and clears the DB. PurgeDatabase(); PurgeAndFillQueue(); using (INetTxConnection connection = dtcFactory.CreateNetTxConnection()) { ITransport transport = (connection as Connection).ITransport; TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport; Assert.IsNotNull(tcpFaulty); tcpFaulty.OnewayCommandPostProcessor += this.FailOnPrepareTransportHook; connection.ExceptionListener += this.OnException; connection.Start(); ReadFromQueueAndInsertIntoDbWithCommit(connection); Thread.Sleep(2000); } // not visible yet because it must be rolled back VerifyNoMessagesInQueueNoRecovery(); // verify sql server has NOT commited the transaction VerifyDatabaseTableIsEmpty(); // check messages are present in the queue NetTxTransactionContext.ResetDtcRecovery(); VerifyBrokerQueueCount(); }
public void TestRecoverAfterRollbackFailWhenScopeAborted() { // Test initialize - Fills in queue with data to send and clears the DB. PurgeDatabase(); PurgeAndFillQueue(); using (INetTxConnection connection = dtcFactory.CreateNetTxConnection()) { connection.ExceptionListener += this.OnException; connection.Start(); ITransport transport = (connection as Connection).ITransport; TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport; Assert.IsNotNull(tcpFaulty); tcpFaulty.OnewayCommandPreProcessor += this.FailOnRollbackTransportHook; ReadFromQueueAndInsertIntoDbWithScopeAborted(connection); Thread.Sleep(2000); } // verify sql server has NOT commited the transaction VerifyDatabaseTableIsEmpty(); // check messages are recovered and present in the queue NetTxTransactionContext.ResetDtcRecovery(); VerifyBrokerQueueCount(); }
public void TestRecoverAfterFailOnTransactionCommit() { // Test initialize - Fills in DB with data to send. PrepareDatabase(); using (INetTxConnection connection = dtcFactory.CreateNetTxConnection()) { connection.ExceptionListener += this.OnException; connection.Start(); ITransport transport = (connection as Connection).ITransport; TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport; Assert.IsNotNull(tcpFaulty); tcpFaulty.OnewayCommandPreProcessor += this.FailOnCommitTransportHook; ReadFromDbAndProduceToQueueWithCommit(connection); Thread.Sleep(1000); } // transaction should not have been commited VerifyNoMessagesInQueueNoRecovery(); // verify sql server has commited the transaction VerifyDatabaseTableIsEmpty(); // check messages are present in the queue NetTxTransactionContext.ResetDtcRecovery(); VerifyBrokerQueueCount(); }
public void TestConsumeWithDBInsertLogLocation() { const string logLocation = @".\RecoveryDir"; string newConnectionUri = connectionUri + "?nms.RecoveryPolicy.RecoveryLogger.Location=" + logLocation + "&nms.configuredResourceManagerId=" + dtcFactory.ConfiguredResourceManagerId; // Test initialize - Fills in queue with data to send and clears the DB. PurgeDatabase(); PurgeAndFillQueue(); if (Directory.Exists(logLocation)) { Directory.Delete(logLocation, true); } Directory.CreateDirectory(logLocation); dtcFactory = new NetTxConnectionFactory(ReplaceEnvVar(newConnectionUri)); using (INetTxConnection connection = dtcFactory.CreateNetTxConnection()) { connection.ExceptionListener += this.OnException; connection.Start(); ITransport transport = (connection as Connection).ITransport; TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport; Assert.IsNotNull(tcpFaulty); tcpFaulty.OnewayCommandPreProcessor += this.FailOnCommitTransportHook; ReadFromQueueAndInsertIntoDbWithCommit(connection); Thread.Sleep(2000); } Assert.AreEqual(1, Directory.GetFiles(logLocation).Length); // verify sql server has commited the transaction VerifyDatabaseTableIsFull(); // check messages are NOT present in the queue NetTxTransactionContext.ResetDtcRecovery(); VerifyBrokerQueueCount(0, newConnectionUri); Assert.AreEqual(0, Directory.GetFiles(logLocation).Length); }
public void TestRecoverAfterTransactionScopeAborted() { // Test initialize - Fills in queue with data to send and clears the DB. PurgeDatabase(); PurgeAndFillQueue(); using (INetTxConnection connection = dtcFactory.CreateNetTxConnection()) { connection.ExceptionListener += this.OnException; connection.Start(); ReadFromQueueAndInsertIntoDbWithScopeAborted(connection); Thread.Sleep(2000); } // verify sql server has NOT commited the transaction VerifyDatabaseTableIsEmpty(); // check messages are present in the queue NetTxTransactionContext.ResetDtcRecovery(); VerifyBrokerQueueCount(); }