public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/declarativeServices.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["adoTransactionManager"] as IPlatformTransactionManager; }
public TransactionInterceptor( ITransactionAttributeSource transactionAttributeSource, IPlatformTransactionManager transactionManager) { TransactionAttributeSource = transactionAttributeSource; TransactionManager = transactionManager; }
public void ProgrammaticRollback() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(RollbackTestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); ITransactionStatus status = TransactionStatusForNewTransaction(); IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); Expect.Call(ptm.GetTransaction(txatt)).Return(status).Repeat.Once(); ptm.Commit(status); LastCall.On(ptm).Repeat.Once(); mocks.ReplayAll(); RollbackTestObject to = new RollbackTestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); Assert.AreEqual("test description", ito.GetDescription()); mocks.VerifyAll(); }
public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = A.Fake <IPlatformTransactionManager>(); ITransactionStatus status = A.Fake <ITransactionStatus>(); A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); A.CallTo(() => ptm.Commit(status)).Throws(ex); TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } }
public void Test() { BasicConfigurator.Configure(); string assemblyName = GetType().Assembly.GetName().Name; ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/txScopeBugTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["TransactionManager"] as IPlatformTransactionManager; CleanupDatabase(dbProvider.CreateConnection()); List <Thread> threads = new List <Thread>(); for (int i = 0; i < 200; i++) { int taskCounter = i; Debug.WriteLine(String.Format("\n---------\nSpawning Task Number {0}\n---------\n", taskCounter)); Thread t = new Thread(MethodForThread); threads.Add(t); t.Start(taskCounter); } foreach (Thread thread in threads) { thread.Join(); } }
private void DoTestRollbackOnException(Exception exception, bool shouldRollback, bool rollbackException) { ITransactionAttribute txatt = new ConfigurableTransactionAttribute(shouldRollback); MethodInfo mi = typeof(ITestObject).GetMethod("Exceptional"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(mi, txatt); ITransactionStatus status = TransactionStatusForNewTransaction(); IPlatformTransactionManager ptm = (IPlatformTransactionManager)mocks.DynamicMock(typeof(IPlatformTransactionManager)); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); if (shouldRollback) { ptm.Rollback(status); } else { ptm.Commit(status); } TransactionSystemException tex = new TransactionSystemException("system exception"); if (rollbackException) { LastCall.On(ptm).Throw(tex).Repeat.Once(); } else { LastCall.On(ptm).Repeat.Once(); } mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.Exceptional(exception); Assert.Fail("Should have thrown exception"); } catch (Exception e) { if (rollbackException) { Assert.AreEqual(tex, e); } else { Assert.AreEqual(exception, e); } } mocks.VerifyAll(); }
public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); ITransactionStatus status = TransactionStatusForNewTransaction(); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); ptm.Commit(status); LastCall.On(ptm).Throw(ex); mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } mocks.VerifyAll(); }
public PlatformTransactionHolder(ITransactionStatus txStatus, IPlatformTransactionManager txMgr) { AssertUtils.ArgumentNotNull(txStatus, "txStatus"); AssertUtils.ArgumentNotNull(txMgr, "txMgr"); this.txStatus = txStatus; this.txMgr = txMgr; this.commit = false; }
public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/autoDeclarativeServices.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["adoTransactionManager"] as IPlatformTransactionManager; }
public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/templateTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["adoTransactionManager"] as IPlatformTransactionManager; adoOperations = ctx["adoTemplate"] as IAdoOperations; }
public void CopyAttributes() { IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); AttributesTransactionAttributeSource tas = new AttributesTransactionAttributeSource(); TestObjectMgr to = new TestObjectMgr(); ITestObjectMgr ito = (ITestObjectMgr)Advised(to, ptm, tas); ito.DeleteTwoTestObjects("foo", "bar"); }
public void CreateAdoTemplate() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/adoTemplateTests.xml"); Assert.IsNotNull(ctx); dbProvider = ctx["DbProvider"] as IDbProvider; Assert.IsNotNull(dbProvider); adoOperations = new AdoTemplate(dbProvider); transactionManager = new AdoPlatformTransactionManager(dbProvider); }
private void DoTestRollbackOnException(Exception exception, bool shouldRollback, bool rollbackException) { ITransactionAttribute txatt = new ConfigurableTransactionAttribute(shouldRollback); MethodInfo mi = typeof(ITestObject).GetMethod("Exceptional"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(mi, txatt); ITransactionStatus status = A.Fake <ITransactionStatus>(); IPlatformTransactionManager ptm = A.Fake <IPlatformTransactionManager>(); A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status); TransactionSystemException tex = new TransactionSystemException("system exception"); if (rollbackException) { A.CallTo(() => ptm.Rollback(A <ITransactionStatus> ._)).Throws(tex); } TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.Exceptional(exception); Assert.Fail("Should have thrown exception"); } catch (Exception e) { if (rollbackException && shouldRollback) { Assert.AreEqual(tex, e); } else { Assert.AreEqual(exception, e); } } if (shouldRollback) { A.CallTo(() => ptm.Rollback(status)).MustHaveHappenedOnceExactly(); } else { A.CallTo(() => ptm.Commit(status)).MustHaveHappenedOnceExactly(); } }
protected override object Advised(object target, IPlatformTransactionManager ptm, ITransactionAttributeSource tas) { TransactionInterceptor ti = new TransactionInterceptor(); ti.TransactionManager = ptm; Assert.AreEqual(ptm, ti.TransactionManager); ti.TransactionAttributeSource = tas; Assert.AreEqual(tas, ti.TransactionAttributeSource); ProxyFactory pf = new ProxyFactory(target); pf.AddAdvice(0, ti); return pf.GetProxy(); }
public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/templateTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["transactionManager"] as IPlatformTransactionManager; adoOperations = ctx["adoTemplate"] as IAdoOperations; ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager; testObjectManager.DeleteAllTestObjects(); testObjectManager.SaveTwoTestObjects(new TestObject("Jack", 10), new TestObject("Jill", 20)); }
public void SetUp() { //NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser)); BasicConfigurator.Configure(); string assemblyName = GetType().Assembly.GetName().Name; ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/templateTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["hibernateTransactionManager"] as IPlatformTransactionManager; CleanupDatabase(dbProvider.CreateConnection()); }
public HibernateTransactionScope(IPlatformTransactionManager transactionManager) { if (currentScope != null) { isNested = true; } else { this.transactionManager = transactionManager; this.Start(); currentScope = this; } }
public void NullResult() { IPlatformTransactionManager mock = MockRepository.GenerateMock <IPlatformTransactionManager>(); TransactionTemplate temp = new TransactionTemplate(mock); temp.AfterPropertiesSet(); Assert.AreEqual(mock, temp.PlatformTransactionManager); Assert.IsNull(temp.Execute(new TransactionDelegate(DummyTransactionMethod))); mock.AssertWasCalled(x => x.GetTransaction(Arg <ITransactionDefinition> .Is.Anything), constraints => constraints.Repeat.Once()); mock.AssertWasCalled(x => x.Commit(Arg <ITransactionStatus> .Is.Anything), constraints => constraints.Repeat.Once()); }
public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/templateTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["transactionManager"] as IPlatformTransactionManager; adoOperations = ctx["adoTemplate"] as IAdoOperations; ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager; testObjectManager.DeleteAllTestObjects(); testObjectManager.SaveTwoTestObjects(new TestObject("Jack", 10), new TestObject("Jill", 20)); }
protected override object Advised(object target, IPlatformTransactionManager ptm, ITransactionAttributeSource tas) { TransactionInterceptor ti = new TransactionInterceptor(); ti.TransactionManager = ptm; Assert.AreEqual(ptm, ti.TransactionManager); ti.TransactionAttributeSource = tas; Assert.AreEqual(tas, ti.TransactionAttributeSource); ProxyFactory pf = new ProxyFactory(target); pf.AddAdvice(0, ti); return(pf.GetProxy()); }
public void NullResult() { IPlatformTransactionManager mock = A.Fake <IPlatformTransactionManager>(); A.CallTo(() => mock.GetTransaction(A <ITransactionDefinition> ._)).Returns(null); TransactionTemplate temp = new TransactionTemplate(mock); temp.AfterPropertiesSet(); Assert.AreEqual(mock, temp.PlatformTransactionManager); Assert.IsNull(temp.Execute(DummyTransactionMethod)); A.CallTo(() => mock.GetTransaction(A <ITransactionDefinition> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => mock.Commit(A <ITransactionStatus> ._)).MustHaveHappenedOnceExactly(); }
public void ExecuteException() { IPlatformTransactionManager mock = A.Fake <IPlatformTransactionManager>(); TransactionTemplate temp = new TransactionTemplate(mock); try { temp.Execute(DummyExceptionMethod); } catch { } A.CallTo(() => mock.GetTransaction(A <ITransactionDefinition> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => mock.Rollback(A <ITransactionStatus> ._)).MustHaveHappenedOnceExactly(); }
public void ExecuteException() { IPlatformTransactionManager mock = MockRepository.GenerateMock <IPlatformTransactionManager>(); TransactionTemplate temp = new TransactionTemplate(mock); try { temp.Execute(new TransactionDelegate(DummyExceptionMethod)); } catch { } mock.AssertWasCalled(x => x.GetTransaction(Arg <ITransactionDefinition> .Is.Anything), constraints => constraints.Repeat.Once()); mock.AssertWasCalled(x => x.Rollback(Arg <ITransactionStatus> .Is.Anything), constraints => constraints.Repeat.Once()); }
public void Dispose() { try { if (txStatus == null) { return; } if (commit) { txMgr.Commit(txStatus); return; } txMgr.Rollback(txStatus); } finally { txMgr = null; txStatus = null; } }
public void ProgrammaticRollback() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(RollbackTestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); ITransactionStatus status = A.Fake <ITransactionStatus>(); IPlatformTransactionManager ptm = A.Fake <IPlatformTransactionManager>(); A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status).Once(); RollbackTestObject to = new RollbackTestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); Assert.AreEqual("test description", ito.GetDescription()); A.CallTo(() => ptm.Commit(status)).MustHaveHappenedOnceExactly(); }
public void SetUp() { ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/templateTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["adoTransactionManager"] as IPlatformTransactionManager; adoOperations = ctx["adoTemplate"] as IAdoOperations; }
public void SetUp() { //NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser)); BasicConfigurator.Configure(); string assemblyName = GetType().Assembly.GetName().Name; ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/HibernateTxScopeTransactionManagerTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["transactionManager"] as IPlatformTransactionManager; CleanupDatabase(dbProvider.CreateConnection()); }
public void Test() { BasicConfigurator.Configure(); string assemblyName = GetType().Assembly.GetName().Name; ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/txScopeBugTests.xml"); dbProvider = ctx["DbProvider"] as IDbProvider; transactionManager = ctx["TransactionManager"] as IPlatformTransactionManager; CleanupDatabase(dbProvider.CreateConnection()); List<Thread> threads = new List<Thread>(); for (int i = 0; i < 200; i++) { int taskCounter = i; Debug.WriteLine(String.Format("\n---------\nSpawning Task Number {0}\n---------\n", taskCounter)); Thread t = new Thread(MethodForThread); threads.Add(t); t.Start(taskCounter); } foreach (Thread thread in threads) { thread.Join(); } }
public PlatformTransactionHolder(ITransactionStatus txStatus, IPlatformTransactionManager txMgr) { AssertUtils.ArgumentNotNull(txStatus, "txStatus"); AssertUtils.ArgumentNotNull(txMgr, "txMgr"); this.txStatus = txStatus; this.txMgr = txMgr; this.commit = false; }
public void Dispose() { try { if (txStatus == null) return; if (commit) { txMgr.Commit(txStatus); return; } txMgr.Rollback(txStatus); } finally { txMgr = null; txStatus = null; } }
protected abstract object Advised(object target, IPlatformTransactionManager ptm, ITransactionAttributeSource tas);
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Transaction.Support.TransactionTemplate"/> class. /// </summary> /// <remarks> /// <p> /// Mainly targeted at configuration by an object factory. /// </p> /// </remarks> /// <param name="platformTransactionManager"> /// The transaction management strategy to be used. /// </param> public TransactionTemplate( IPlatformTransactionManager platformTransactionManager ) { _platformTransactionManager = platformTransactionManager; }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Transaction.Support.TransactionTemplate"/> class. /// </summary> /// <remarks> /// <p> /// Mainly targeted at configuration by an object factory. /// </p> /// </remarks> /// <param name="platformTransactionManager"> /// The transaction management strategy to be used. /// </param> public TransactionTemplate(IPlatformTransactionManager platformTransactionManager) { _platformTransactionManager = platformTransactionManager; }
public TransactionTemplate(IPlatformTransactionManager transactionManager, ITransactionDefinition transactionDefinition, ILogger logger = null) : base(transactionDefinition) { _logger = logger; TransactionManager = transactionManager; }
public TransactionTemplate(IPlatformTransactionManager transactionManager, ILogger logger = null) { _logger = logger; TransactionManager = transactionManager; }
protected abstract object Advised(object target, IPlatformTransactionManager ptm, ITransactionAttributeSource tas);
public void CreateAdoTemplate() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/adoTemplateTests.xml"); Assert.IsNotNull(ctx); dbProvider = ctx["DbProvider"] as IDbProvider; Assert.IsNotNull(dbProvider); adoOperations = new AdoTemplate(dbProvider); transactionManager = new AdoPlatformTransactionManager(dbProvider); }