os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/server1.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/server1.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,171 @@
     1.4 +# 2006 January 09
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this script is testing the server mode of SQLite.
    1.16 +#
    1.17 +# This file is derived from thread1.test
    1.18 +#
    1.19 +# $Id: server1.test,v 1.5 2007/08/29 18:20:17 drh Exp $
    1.20 +
    1.21 +
    1.22 +set testdir [file dirname $argv0]
    1.23 +source $testdir/tester.tcl
    1.24 +
    1.25 +# Skip this whole file if the server testing code is not enabled
    1.26 +#
    1.27 +if {[llength [info command client_step]]==0 || [sqlite3 -has-codec]} {
    1.28 +  finish_test
    1.29 +  return
    1.30 +}
    1.31 +
    1.32 +# The sample server implementation does not work right when memory
    1.33 +# management is enabled.
    1.34 +#
    1.35 +ifcapable memorymanage {
    1.36 +  finish_test
    1.37 +  return
    1.38 +}
    1.39 +
    1.40 +# Create some data to work with
    1.41 +#
    1.42 +do_test server1-1.1 {
    1.43 +  execsql {
    1.44 +    CREATE TABLE t1(a,b);
    1.45 +    INSERT INTO t1 VALUES(1,'abcdefgh');
    1.46 +    INSERT INTO t1 SELECT a+1, b||b FROM t1;
    1.47 +    INSERT INTO t1 SELECT a+2, b||b FROM t1;
    1.48 +    INSERT INTO t1 SELECT a+4, b||b FROM t1;
    1.49 +    SELECT count(*), max(length(b)) FROM t1;
    1.50 +  }
    1.51 +} {8 64}
    1.52 +
    1.53 +# Interleave two threads on read access.  Then make sure a third
    1.54 +# thread can write the database.  In other words:
    1.55 +#
    1.56 +#    read-lock A
    1.57 +#    read-lock B
    1.58 +#    unlock A
    1.59 +#    unlock B
    1.60 +#    write-lock C
    1.61 +#
    1.62 +do_test server1-1.2 {
    1.63 +  client_create A test.db
    1.64 +  client_create B test.db
    1.65 +  client_create C test.db
    1.66 +  client_compile A {SELECT a FROM t1}
    1.67 +  client_step A
    1.68 +  client_result A
    1.69 +} SQLITE_ROW
    1.70 +do_test server1-1.3 {
    1.71 +  client_argc A
    1.72 +} 1
    1.73 +do_test server1-1.4 {
    1.74 +  client_argv A 0
    1.75 +} 1
    1.76 +do_test server1-1.5 {
    1.77 +  client_compile B {SELECT b FROM t1}
    1.78 +  client_step B
    1.79 +  client_result B
    1.80 +} SQLITE_ROW
    1.81 +do_test server1-1.6 {
    1.82 +  client_argc B
    1.83 +} 1
    1.84 +do_test server1-1.7 {
    1.85 +  client_argv B 0
    1.86 +} abcdefgh
    1.87 +do_test server1-1.8 {
    1.88 +  client_finalize A
    1.89 +  client_result A
    1.90 +} SQLITE_OK
    1.91 +do_test server1-1.9 {
    1.92 +  client_finalize B
    1.93 +  client_result B
    1.94 +} SQLITE_OK
    1.95 +do_test server1-1.10 {
    1.96 +  client_compile C {CREATE TABLE t2(x,y)}
    1.97 +  client_step C
    1.98 +  client_result C
    1.99 +} SQLITE_DONE
   1.100 +do_test server1-1.11 {
   1.101 +  client_finalize C
   1.102 +  client_result C
   1.103 +} SQLITE_OK
   1.104 +do_test server1-1.12 {
   1.105 +  catchsql {SELECT name FROM sqlite_master}
   1.106 +  execsql {SELECT name FROM sqlite_master}
   1.107 +} {t1 t2}
   1.108 +
   1.109 +
   1.110 +# Read from table t1.  Do not finalize the statement.  This
   1.111 +# will leave the lock pending.
   1.112 +#
   1.113 +do_test server1-2.1 {
   1.114 +  client_halt *
   1.115 +  client_create A test.db
   1.116 +  client_compile A {SELECT a FROM t1}
   1.117 +  client_step A
   1.118 +  client_result A
   1.119 +} SQLITE_ROW
   1.120 +
   1.121 +# Read from the same table from another thread.  This is allows.
   1.122 +#
   1.123 +do_test server1-2.2 {
   1.124 +  client_create B test.db
   1.125 +  client_compile B {SELECT b FROM t1}
   1.126 +  client_step B
   1.127 +  client_result B
   1.128 +} SQLITE_ROW
   1.129 +
   1.130 +# Write to a different table from another thread.  This is allowed
   1.131 +# because in server mode with a shared cache we have table-level locking.
   1.132 +#
   1.133 +do_test server1-2.3 {
   1.134 +  client_create C test.db
   1.135 +  client_compile C {INSERT INTO t2 VALUES(98,99)}
   1.136 +  client_step C
   1.137 +  client_result C
   1.138 +  client_finalize C
   1.139 +  client_result C
   1.140 +} SQLITE_OK
   1.141 +
   1.142 +# But we cannot insert into table t1 because threads A and B have it locked.
   1.143 +#
   1.144 +do_test server1-2.4 {
   1.145 +  client_compile C {INSERT INTO t1 VALUES(98,99)}
   1.146 +  client_step C
   1.147 +  client_result C
   1.148 +  client_finalize C
   1.149 +  client_result C
   1.150 +} SQLITE_LOCKED
   1.151 +do_test server1-2.5 {
   1.152 +  client_finalize B
   1.153 +  client_wait B
   1.154 +  client_compile C {INSERT INTO t1 VALUES(98,99)}
   1.155 +  client_step C
   1.156 +  client_result C
   1.157 +  client_finalize C
   1.158 +  client_result C
   1.159 +} SQLITE_LOCKED
   1.160 +
   1.161 +# Insert into t1 is successful after finishing the other two threads.
   1.162 +do_test server1-2.6 {
   1.163 +  client_finalize A
   1.164 +  client_wait A
   1.165 +  client_compile C {INSERT INTO t1 VALUES(98,99)}
   1.166 +  client_step C
   1.167 +  client_result C
   1.168 +  client_finalize C
   1.169 +  client_result C
   1.170 +} SQLITE_OK
   1.171 +
   1.172 +client_halt *   
   1.173 +sqlite3_enable_shared_cache 0
   1.174 +finish_test