Ejemplo n.º 1
0
        public void APIS_485()
        {
            LogTestStep("Test the lockTimeout is set successfully");
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = DBHelper.connString;
            Assert.AreEqual(-1, conn.LockTimeout);
            
            conn.Open();
            int timeout = 20;
            conn.SetLockTimeout(timeout);
            Assert.AreEqual(timeout, conn.LockTimeout);

            DBHelper.ExecuteSQL("drop table if exists t", conn);
            DBHelper.ExecuteSQL("create table t(id integer)", conn);
            DBHelper.ExecuteSQL("insert into t values (1)", conn);

            conn.SetAutoCommit(false);
            CUBRIDConnection conn2 = null;
            double elapseTime = 0;
            var stopwatch = new Stopwatch();
            try
            {
                Thread thread2 = new Thread(delegate()
                {
                    conn2 = new CUBRIDConnection();
                    conn2.ConnectionString = DBHelper.connString;
                    conn2.Open();
                    conn2.SetAutoCommit(false);

                    conn2.BeginTransaction();
                    DBHelper.ExecuteSQL("update t set id=2", conn2);
                });
                conn.BeginTransaction();
                thread2.Start();
                Thread.Sleep(5000);

                stopwatch.Start();
                DBHelper.ExecuteSQL("update t set id=3", conn);
                thread2.Join();
            }
            catch (Exception ex)
            {
                stopwatch.Stop();
                elapseTime = (double)stopwatch.ElapsedMilliseconds / 1000;
                double diffTime = elapseTime - (double)(timeout / 1000);
                Console.WriteLine("different time = " + stopwatch.ElapsedMilliseconds);
                Console.WriteLine("different time = " + diffTime);
                Log(ex.Message);
                Assert.AreEqual(timeout, conn.LockTimeout);

                if (diffTime >= 0 && diffTime < 10)
                {
                    LogStepPass();
                }
                else
                {
                    LogStepFail();
                }
            }
            finally
            {
                LogTestResult();
                //DBHelper.ExecuteSQL("drop table t", conn);
                conn.Close();
                conn2.Close();
            }
        }
Ejemplo n.º 2
0
        public void SetLockTimeOut_WithParam_Test()
        {
            int timeout;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                LogTestStep("connection is not open");
                try
                {
                    timeout = 2;
                    conn.SetLockTimeout(timeout);
                }
                catch (Exception ex)
                {
                    Assert.AreEqual("The connection is not open!", ex.Message);
                    LogStepPass();
                }
                conn.Close();

                LogTestStep("Valid timout value, and connection is open");
                timeout = 35;
                conn.Open();
                conn.SetLockTimeout(35);
                Assert.AreEqual(35, conn.LockTimeout);
                LogStepPass();

                LogTestStep("Valid timout value, change the lock timeout");
                try
                {
                    Assert.AreEqual(35, conn.LockTimeout); 
                    conn.SetLockTimeout(40);
                    Assert.AreEqual(40, conn.LockTimeout);
                    LogStepPass();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //Assert.AreEqual("Not allowed to change the 'LockTimeout' property while the connection state is!: Open.", ex.Message);
                    LogStepFail();
                }
                finally
                {
                    LogTestResult();
                }
            }
        }