Exemple #1
0
        public void TestTransactionPipelining()
        {
            DoQuery("CREATE TEMPORARY TABLE Test (value int)");

            using (var scheduler = new TaskScheduler())
                using (var qm = new ConnectionWrapper(scheduler, Connection)) {
                    var getNumValues = qm.BuildQuery("SELECT COUNT(value) FROM test");

                    var addValue = qm.BuildQuery("INSERT INTO test (value) VALUES (?)");

                    var t  = qm.CreateTransaction();
                    var fq = addValue.ExecuteNonQuery(1);
                    var fr = t.Rollback();

                    scheduler.WaitFor(Future.WaitForAll(t.Future, fq, fr));

                    var  fgnv      = getNumValues.ExecuteScalar();
                    long numValues = Convert.ToInt64(
                        scheduler.WaitFor(fgnv)
                        );
                    Assert.AreEqual(0, numValues);

                    t  = qm.CreateTransaction();
                    fq = addValue.ExecuteNonQuery(1);
                    var fc = t.Commit();

                    scheduler.WaitFor(Future.WaitForAll(t.Future, fq, fc));

                    fgnv      = getNumValues.ExecuteScalar();
                    numValues = Convert.ToInt64(
                        scheduler.WaitFor(fgnv)
                        );
                    Assert.AreEqual(1, numValues);
                }
        }
Exemple #2
0
        IEnumerator <object> CrashyTransactionTask(ConnectionWrapper cw, Query addValue)
        {
            using (var trans = cw.CreateTransaction()) {
                yield return(addValue.ExecuteNonQuery(1));

                yield return(addValue.ExecuteNonQuery());

                yield return(trans.Commit());
            }
        }
Exemple #3
0
        static IEnumerator <object> TransactionalSequentialInsertTask(ConnectionWrapper cw, Query query, int numInsertions)
        {
            using (var xact = cw.CreateTransaction()) {
                yield return(xact);

                for (int i = 0; i < numInsertions; i++)
                {
                    yield return(query.ExecuteNonQuery(i, i * 2));
                }

                yield return(xact.Commit());
            }
        }