Skip to content

Commit

Permalink
SPRNET-1444 - change default tx isolation mode from ReadCommitted to …
Browse files Browse the repository at this point in the history
…Unspecified
  • Loading branch information
sbohlen committed Oct 22, 2012
1 parent f783f7b commit ba55754
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class DefaultTransactionDefinition : ITransactionDefinition
//TODO Refactoring to sync with Spring 2.0 for nt/enums for various default values.

private TransactionPropagation _transactionPropagation = TransactionPropagation.Required;
private IsolationLevel _transactionIsolationLevel = IsolationLevel.ReadCommitted;
private IsolationLevel _transactionIsolationLevel = IsolationLevel.Unspecified;
private int _timeout = DefaultTransactionDefinition.TIMEOUT_DEFAULT;
private bool _readOnly = false;
private string _name = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Spring.Data
public class AdoPlatformTransactionManagerTests
{
private MockRepository mocks;
private IsolationLevel _defaultIsolationLevel = IsolationLevel.Unspecified;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -74,7 +75,7 @@ public void TransactionCommit()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Commit();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -115,7 +116,7 @@ public void TransactionRollback()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -165,7 +166,7 @@ public void ParticipatingTransactionWithRollbackOnly()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -237,7 +238,7 @@ public void PropagationRequiresNewWithExistingTransaction()
Expect.Call(dbProvider.CreateConnection()).Return(connection).Repeat.Twice();
connection.Open();
LastCall.On(connection).Repeat.Twice();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction).Repeat.Twice();
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction).Repeat.Twice();
//standard tx timeout.
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -279,7 +280,7 @@ public void PropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource(
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
transaction.Commit();
LastCall.On(transaction).Repeat.Once();
connection.Dispose();
Expand All @@ -291,7 +292,7 @@ public void PropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource(
Expect.Call(dbProvider2.CreateConnection()).Return(connection2);
connection2.Open();
LastCall.On(connection2).Repeat.Once();
Expect.Call(connection2.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction2);
Expect.Call(connection2.BeginTransaction(_defaultIsolationLevel)).Return(transaction2);
transaction2.Rollback();
LastCall.On(transaction2).Repeat.Once();
connection2.Dispose();
Expand Down Expand Up @@ -334,7 +335,7 @@ public void PropagationRequiresNewWithExistingTransactionAndUnrelatedFailingData
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
connection.Dispose();
Expand Down Expand Up @@ -394,7 +395,7 @@ public void PropagationNotSupportedWithExistingTransaction()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Commit();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -430,7 +431,7 @@ public void PropagationNeverWithExistingTransaction()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -481,7 +482,7 @@ public void PropagationRequiresNewWithExistingConnection()
Expect.Call(dbProvider.CreateConnection()).Return(connection2);
connection2.Open();
LastCall.On(connection2).Repeat.Once();
Expect.Call(connection2.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction2);
Expect.Call(connection2.BeginTransaction(_defaultIsolationLevel)).Return(transaction2);
transaction2.Commit();
LastCall.On(transaction2).Repeat.Once();
connection2.Dispose();
Expand Down Expand Up @@ -572,7 +573,7 @@ private void DoTransactionWithTimeout(int timeout)
connection.Open();

LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
Expect.Call(connection.CreateCommand()).Return(command);
command.CommandText = "some SQL statement";
LastCall.On(command).Repeat.Once();
Expand Down Expand Up @@ -673,7 +674,7 @@ public void TransactionWithExceptionOnCommit()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Commit();
LastCall.On(transaction).Throw(new TestSqlException("Cannot commit", "314"));
Expand Down Expand Up @@ -716,7 +717,7 @@ public void TransactionWithExceptionOnCommitAndRollbackOnCommitFailure()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
transaction.Commit();
LastCall.On(transaction).Throw(new TestSqlException("Cannot commit", "314"));

Expand Down Expand Up @@ -762,7 +763,7 @@ public void TransactionWithExceptionOnRollback()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Rollback();
LastCall.On(transaction).Throw(new TestSqlException("Cannot commit", "314"));
Expand Down Expand Up @@ -876,7 +877,7 @@ public void ExistingTransactionWithPropagationNestedNotSupported()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);

transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -922,7 +923,7 @@ public void TransactionWithPropagationNested()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
//standard tx timeout.
transaction.Commit();
LastCall.On(transaction).Repeat.Once();
Expand Down Expand Up @@ -970,7 +971,7 @@ public void TransactionWithPropagationNestedAndRollback()
Expect.Call(dbProvider.CreateConnection()).Return(connection);
connection.Open();
LastCall.On(connection).Repeat.Once();
Expect.Call(connection.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
Expect.Call(connection.BeginTransaction(_defaultIsolationLevel)).Return(transaction);
transaction.Rollback();
LastCall.On(transaction).Repeat.Once();
connection.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void PropagationRequiresNewWithExistingTransaction()
// inner tx
ConfigureServiceConfig(serviceConfig, false);
serviceConfig.TransactionOption = TransactionOption.RequiresNew;
serviceConfig.IsolationLevel = TransactionIsolationLevel.ReadCommitted;
serviceConfig.IsolationLevel = TransactionIsolationLevel.Any;
txAdapter.Enter(serviceConfig);
Expect.Call(txAdapter.IsInTransaction).Return(true);
txAdapter.SetAbort();
Expand Down Expand Up @@ -204,7 +204,7 @@ private SimpleServiceConfig ConfigureServiceConfig(SimpleServiceConfig serviceCo
if (standardIsolationAndProp)
{
serviceConfig.TransactionOption = TransactionOption.Required;
serviceConfig.IsolationLevel = TransactionIsolationLevel.ReadCommitted;
serviceConfig.IsolationLevel = TransactionIsolationLevel.Any;
}
return serviceConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void TransactionCommit()
{
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
TransactionOptions txOptions = new TransactionOptions();
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
txOptions.IsolationLevel = IsolationLevel.Unspecified;
txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);

Expect.Call(txAdapter.RollbackOnly).Return(false);
Expand Down Expand Up @@ -94,7 +94,7 @@ public void TransactionRollback()
{
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
TransactionOptions txOptions = new TransactionOptions();
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
txOptions.IsolationLevel = IsolationLevel.Unspecified;
txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);
txAdapter.Dispose();
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public void PropagationRequiresNewWithExistingTransaction()
{
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
TransactionOptions txOptions = new TransactionOptions();
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
txOptions.IsolationLevel = IsolationLevel.Unspecified;
txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);

//inner tx actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void RollbackOnTests()
public void ToStringTests()
{
DefaultTransactionAttribute dta = new DefaultTransactionAttribute();
Assert.AreEqual( "PROPAGATION_Required,ISOLATION_ReadCommitted,-System.Exception", dta.ToString());
Assert.AreEqual( "PROPAGATION_Required,ISOLATION_Unspecified,-System.Exception", dta.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ValidPropagationCodeOnly()
ITransactionAttribute ta = editor.Value;
Assert.IsTrue( ta != null );
Assert.IsTrue( ta.PropagationBehavior == TransactionPropagation.Required );
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted );
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.Unspecified );
Assert.IsFalse( ta.ReadOnly );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void checkTransactionProperties( ITransactionAttributeSource tas, Method
{
ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
Assert.IsTrue( ta != null );
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted );
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.Unspecified );
Assert.IsTrue( ta.PropagationBehavior == transactionPropagation);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ public void VanillaTest()
Assert.IsTrue( true == def.ReadOnly );
}
[Test]
public void IsolationLeveNonDefaultl()
public void PropogationBehaviorDefault()
{
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
Assert.IsTrue( def.PropagationBehavior == TransactionPropagation.Required );
}
[Test]
[Test]
public void IsolationLevelDefault()
{
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
Assert.IsTrue(def.TransactionIsolationLevel == IsolationLevel.Unspecified);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void InvalidTimeout()
{
Expand Down

0 comments on commit ba55754

Please sign in to comment.