public void TestExecuteStatementUsesTransactionLifecyle() { int txnCount = 0; int executeCount = 0; int commitCount = 0; int retryCount = 0; mockSession.Setup(x => x.StartTransaction()).Returns(new StartTransactionResult { TransactionId = "testTransactionIdddddd" }).Callback(() => txnCount++); mockSession.Setup(x => x.ExecuteStatement( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <List <IIonValue> >())).Returns(new ExecuteStatementResult { FirstPage = new Page { NextPageToken = null, Values = new List <ValueHolder>() } }).Callback(() => executeCount++); mockSession.Setup(x => x.CommitTransaction(It.IsAny <string>(), It.IsAny <MemoryStream>())) .Returns(new CommitTransactionResult { CommitDigest = new MemoryStream(digest) }).Callback(() => commitCount++); var result = qldbSession.Execute( "testStatement", (int retry) => retryCount = retry); Assert.AreEqual(1, txnCount); Assert.AreEqual(1, executeCount); Assert.AreEqual(1, commitCount); Assert.AreEqual(0, retryCount); }
public void Execute_CustomerTransactionTest(Func <TransactionExecutor, Object> transaction, Object expected, Type expectedExceptionType, Type innerExceptionType, Times startTxnTimes, Times executeTimes, Times commitTimes, Times abortTimes, Times retryTimes) { mockSession.Setup(x => x.StartTransaction()).Returns(new StartTransactionResult { TransactionId = "testTransactionIdddddd" }); mockSession.Setup(x => x.ExecuteStatement( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <List <IIonValue> >())).Returns(new ExecuteStatementResult { FirstPage = new Page { NextPageToken = null, Values = new List <ValueHolder>() } }); mockSession.Setup(x => x.CommitTransaction(It.IsAny <string>(), It.IsAny <MemoryStream>())) .Returns(new CommitTransactionResult { CommitDigest = new MemoryStream(digest) }); try { var result = qldbSession.Execute(transaction); Assert.IsNull(expectedExceptionType); Assert.AreEqual(expected, result); } catch (Exception e) { Assert.IsNotNull(expectedExceptionType); Assert.IsInstanceOfType(e, expectedExceptionType); if (innerExceptionType != null) { Assert.IsInstanceOfType(e.InnerException, innerExceptionType); } } mockSession.Verify(s => s.StartTransaction(), startTxnTimes); mockSession.Verify(s => s.ExecuteStatement(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <List <IIonValue> >()), executeTimes); mockSession.Verify(s => s.CommitTransaction(It.IsAny <string>(), It.IsAny <MemoryStream>()), commitTimes); mockSession.Verify(s => s.AbortTransaction(), abortTimes); mockAction.Verify(s => s.DisposeDelegate(qldbSession), retryTimes); }