Annotation of embedaddon/sqlite3/test/multiplex.test, revision 1.1.1.1

1.1       misho       1: # 2010 October 29
                      2: #
                      3: # The author disclaims copyright to this source code.  In place of
                      4: # a legal notice, here is a blessing:
                      5: #
                      6: #    May you do good and not evil.
                      7: #    May you find forgiveness for yourself and forgive others.
                      8: #    May you share freely, never taking more than you give.
                      9: #
                     10: #***********************************************************************
                     11: #
                     12: 
                     13: set testdir [file dirname $argv0]
                     14: source $testdir/tester.tcl
                     15: source $testdir/malloc_common.tcl
                     16: 
                     17: # The tests in this file assume that SQLite is compiled without
                     18: # ENABLE_8_3_NAMES.
                     19: #
                     20: ifcapable 8_3_names {
                     21:   puts -nonewline "SQLite compiled with SQLITE_ENABLE_8_3_NAMES. "
                     22:   puts            "Skipping tests multiplex-*."
                     23:   finish_test
                     24:   return
                     25: }
                     26: 
                     27: set g_chunk_size [ expr ($::SQLITE_MAX_PAGE_SIZE*16384) ]
                     28: set g_max_chunks 32
                     29: 
                     30: # This handles appending the chunk number
                     31: # to the end of the filename.  if 
                     32: # SQLITE_MULTIPLEX_EXT_OVWR is defined, then
                     33: # it overwrites the last 2 bytes of the 
                     34: # file name with the chunk number.
                     35: proc multiplex_name {name chunk} {
                     36:   if {$chunk==0} { return $name }
                     37:   set num [format "%03d" $chunk]
                     38:   ifcapable {multiplex_ext_overwrite} {
                     39:     set name [string range $name 0 [expr [string length $name]-2-1]]
                     40:   }
                     41:   return $name$num
                     42: }
                     43: 
                     44: # This saves off the parameters and calls the 
                     45: # underlying sqlite3_multiplex_control() API.
                     46: proc multiplex_set {db name chunk_size max_chunks} {
                     47:   global g_chunk_size
                     48:   global g_max_chunks
                     49:   set g_chunk_size [ expr (($chunk_size+($::SQLITE_MAX_PAGE_SIZE-1)) & ~($::SQLITE_MAX_PAGE_SIZE-1)) ]
                     50:   set g_max_chunks $max_chunks
                     51:   set rc [catch {sqlite3_multiplex_control $db $name chunk_size $chunk_size} msg]
                     52:   if { $rc==0 } { 
                     53:     set rc [catch {sqlite3_multiplex_control $db $name max_chunks $max_chunks} msg]
                     54:   }
                     55:   list $msg
                     56: }
                     57: 
                     58: # This attempts to delete the base file and 
                     59: # and files with the chunk extension.
                     60: proc multiplex_delete {name} {
                     61:   global g_max_chunks
                     62:   forcedelete $name
                     63:   for {set i 0} {$i<$g_max_chunks} {incr i} {
                     64:     forcedelete [multiplex_name $name $i]
                     65:     forcedelete [multiplex_name $name-journal $i]
                     66:     forcedelete [multiplex_name $name-wal $i]
                     67:   }
                     68: }
                     69: 
                     70: db close
                     71: 
                     72: multiplex_delete test.db
                     73: multiplex_delete test2.db
                     74: 
                     75: #-------------------------------------------------------------------------
                     76: #   multiplex-1.1.*: Test initialize and shutdown.
                     77: 
                     78: do_test multiplex-1.1 { sqlite3_multiplex_initialize nosuchvfs 1 } {SQLITE_ERROR}
                     79: do_test multiplex-1.2 { sqlite3_multiplex_initialize "" 1 }        {SQLITE_OK}
                     80: do_test multiplex-1.3 { sqlite3_multiplex_initialize "" 1 }        {SQLITE_MISUSE}
                     81: do_test multiplex-1.4 { sqlite3_multiplex_shutdown }               {SQLITE_OK}
                     82: 
                     83: do_test multiplex-1.5 { sqlite3_multiplex_initialize "" 0 }        {SQLITE_OK}
                     84: do_test multiplex-1.6 { sqlite3_multiplex_shutdown }               {SQLITE_OK}
                     85: do_test multiplex-1.7 { sqlite3_multiplex_initialize "" 1 }        {SQLITE_OK}
                     86: do_test multiplex-1.8 { sqlite3_multiplex_shutdown }               {SQLITE_OK}
                     87: 
                     88: 
                     89: do_test multiplex-1.9.1  { sqlite3_multiplex_initialize "" 1 }     {SQLITE_OK}
                     90: do_test multiplex-1.9.2  { sqlite3 db test.db }                    {}
                     91: do_test multiplex-1.9.3  { multiplex_set db main 32768 16 }        {SQLITE_OK}
                     92: do_test multiplex-1.9.4  { multiplex_set db main 32768 -1 }        {SQLITE_OK}
                     93: do_test multiplex-1.9.6  { multiplex_set db main 31 16 }           {SQLITE_OK}
                     94: do_test multiplex-1.9.7  { multiplex_set db main 32768 100 }       {SQLITE_OK}
                     95: do_test multiplex-1.9.8  { multiplex_set db main 1073741824 1 }    {SQLITE_OK}
                     96: do_test multiplex-1.9.9  { db close }                              {}
                     97: do_test multiplex-1.9.10 { sqlite3_multiplex_shutdown }            {SQLITE_OK}
                     98: 
                     99: do_test multiplex-1.10.1  { sqlite3_multiplex_initialize "" 1 }                                  {SQLITE_OK}
                    100: do_test multiplex-1.10.2  { sqlite3 db test.db }                                                 {}
                    101: do_test multiplex-1.10.3  { lindex [ catchsql { SELECT multiplex_control(2, 32768); } ] 0 }      {0}
                    102: do_test multiplex-1.10.4  { lindex [ catchsql { SELECT multiplex_control(3, -1); } ] 0 }         {0}
                    103: do_test multiplex-1.10.6  { lindex [ catchsql { SELECT multiplex_control(2, 31); } ] 0 }         {0}
                    104: do_test multiplex-1.10.7  { lindex [ catchsql { SELECT multiplex_control(3, 100); } ] 0 }        {0}
                    105: do_test multiplex-1.10.8  { lindex [ catchsql { SELECT multiplex_control(2, 1073741824); } ] 0 } {0}
                    106: do_test multiplex-1.10.9  { db close }                                                           {}
                    107: do_test multiplex-1.10.10 { sqlite3_multiplex_shutdown }                                         {SQLITE_OK}
                    108: 
                    109: do_test multiplex-1.11.1  { sqlite3_multiplex_initialize "" 1 }               {SQLITE_OK}
                    110: do_test multiplex-1.11.2  { sqlite3 db test.db }                              {}
                    111: do_test multiplex-1.11.3  { sqlite3_multiplex_control db main enable 0  }     {SQLITE_OK}
                    112: do_test multiplex-1.11.4  { sqlite3_multiplex_control db main enable 1  }     {SQLITE_OK}
                    113: do_test multiplex-1.11.5  { sqlite3_multiplex_control db main enable -1 }     {SQLITE_OK}
                    114: do_test multiplex-1.11.6  { db close }                                        {}
                    115: do_test multiplex-1.11.7  { sqlite3_multiplex_shutdown }                      {SQLITE_OK}
                    116: 
                    117: do_test multiplex-1.12.1  { sqlite3_multiplex_initialize "" 1 }                           {SQLITE_OK}
                    118: do_test multiplex-1.12.2  { sqlite3 db test.db }                                          {}
                    119: do_test multiplex-1.12.3  { lindex [ catchsql { SELECT multiplex_control(1, 0); } ] 0 }   {0}
                    120: do_test multiplex-1.12.4  { lindex [ catchsql { SELECT multiplex_control(1, 1); } ] 0 }   {0}
                    121: do_test multiplex-1.12.5  { lindex [ catchsql { SELECT multiplex_control(1, -1); } ] 0 }  {0}
                    122: do_test multiplex-1.12.6  { db close }                                                    {}
                    123: do_test multiplex-1.12.7  { sqlite3_multiplex_shutdown }                                  {SQLITE_OK}
                    124: 
                    125: do_test multiplex-1.13.1  { sqlite3_multiplex_initialize "" 1 }                           {SQLITE_OK}
                    126: do_test multiplex-1.13.2  { sqlite3 db test.db }                                          {}
                    127: do_test multiplex-1.13.3  { lindex [ catchsql { SELECT multiplex_control(-1, 0); } ] 0 }  {1}
                    128: do_test multiplex-1.13.4  { lindex [ catchsql { SELECT multiplex_control(4, 1); } ] 0 }   {1}
                    129: do_test multiplex-1.13.6  { db close }                                                    {}
                    130: do_test multiplex-1.13.7  { sqlite3_multiplex_shutdown }                                  {SQLITE_OK}
                    131: 
                    132: #-------------------------------------------------------------------------
                    133: # Some simple warm-body tests with a single database file in rollback 
                    134: # mode:
                    135: #
                    136: #   multiplex-2.1.*: Test simple writing to a multiplex file.
                    137: #
                    138: #   multiplex-2.2.*: More writing.
                    139: #
                    140: #   multiplex-2.3.*: Open and close a second db.
                    141: #
                    142: #   multiplex-2.4.*: Try to shutdown the multiplex system before closing the db
                    143: #                file. Check that this fails and the multiplex system still works
                    144: #                afterwards. Then close the database and successfully shut
                    145: #                down the multiplex system.
                    146: #
                    147: #   multiplex-2.5.*: More reading/writing.
                    148: #
                    149: #   multiplex-2.6.*: More reading/writing with varying small chunk sizes, as
                    150: #                well as varying journal mode.
                    151: #
                    152: #   multiplex-2.7.*: Disable/enable tests.
                    153: #
                    154: 
                    155: sqlite3_multiplex_initialize "" 1
                    156: multiplex_set db main 32768 16
                    157: 
                    158: forcedelete test.x
                    159: foreach f [glob -nocomplain {test.x*[0-9][0-9][0-9]}] {
                    160:   forcedelete $f
                    161: }
                    162: do_test multiplex-2.1.2 {
                    163:   sqlite3 db test.x
                    164:   execsql {
                    165:     PRAGMA page_size=1024;
                    166:     PRAGMA auto_vacuum=OFF;
                    167:     PRAGMA journal_mode=DELETE;
                    168:   }
                    169:   execsql {
                    170:     CREATE TABLE t1(a, b);
                    171:     INSERT INTO t1 VALUES(1, randomblob(1100));
                    172:     INSERT INTO t1 VALUES(2, randomblob(1100));
                    173:   }
                    174: } {}
                    175: do_test multiplex-2.1.3 { file size [multiplex_name test.x 0] } {4096}
                    176: do_test multiplex-2.1.4 {
                    177:   execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
                    178: } {}
                    179: 
                    180: do_test multiplex-2.2.1 {
                    181:   execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
                    182: } {}
                    183: do_test multiplex-2.2.3 { file size [multiplex_name test.x 0] } {6144}
                    184: 
                    185: do_test multiplex-2.3.1 {
                    186:   sqlite3 db2 test2.x
                    187:   db2 close
                    188: } {}
                    189: 
                    190: 
                    191: do_test multiplex-2.4.1 {
                    192:   sqlite3_multiplex_shutdown
                    193: } {SQLITE_MISUSE}
                    194: do_test multiplex-2.4.2 {
                    195:   execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
                    196: } {}
                    197: do_test multiplex-2.4.4 { file size [multiplex_name test.x 0] } {7168}
                    198: do_test multiplex-2.4.5 {
                    199:   db close
                    200:   sqlite3 db test.x
                    201:   db eval vacuum
                    202:   db close
                    203:   glob test.x*
                    204: } {test.x}
                    205: do_test multiplex-2.4.99 {
                    206:   sqlite3_multiplex_shutdown
                    207: } {SQLITE_OK}
                    208: 
                    209: do_test multiplex-2.5.1 {
                    210:   multiplex_delete test.x
                    211:   sqlite3_multiplex_initialize "" 1
                    212:   sqlite3 db test.x
                    213:   multiplex_set db main 4096 16
                    214: } {SQLITE_OK}
                    215: 
                    216: do_test multiplex-2.5.2 {
                    217:   execsql {
                    218:     PRAGMA page_size = 1024;
                    219:     PRAGMA journal_mode = delete;
                    220:     PRAGMA auto_vacuum = off;
                    221:     CREATE TABLE t1(a PRIMARY KEY, b);
                    222:   }
                    223: } {delete}
                    224: 
                    225: do_test multiplex-2.5.3 { 
                    226:   execsql { 
                    227:     INSERT INTO t1 VALUES(1, 'one');
                    228:     INSERT INTO t1 VALUES(2, randomblob(4000));
                    229:     INSERT INTO t1 VALUES(3, 'three');
                    230:     INSERT INTO t1 VALUES(4, randomblob(4000));
                    231:     INSERT INTO t1 VALUES(5, 'five');
                    232:     INSERT INTO t1 VALUES(6, randomblob($g_chunk_size));
                    233:     INSERT INTO t1 VALUES(7, randomblob($g_chunk_size));
                    234:   }
                    235: } {}
                    236: 
                    237: do_test multiplex-2.5.4 {
                    238:   db eval {SELECT * FROM t1 WHERE a=1}
                    239: } {1 one}
                    240: 
                    241: do_test multiplex-2.5.5 {
                    242:   db eval {SELECT * FROM t1 WHERE a=3}
                    243: } {3 three}
                    244: 
                    245: do_test multiplex-2.5.6 {
                    246:   db eval {SELECT * FROM t1 WHERE a=5}
                    247: } {5 five}
                    248: 
                    249: do_test multiplex-2.5.7 {
                    250:   db eval {SELECT a,length(b) FROM t1 WHERE a=2}
                    251: } {2 4000}
                    252: 
                    253: do_test multiplex-2.5.8 {
                    254:   db eval {SELECT a,length(b) FROM t1 WHERE a=4}
                    255: } {4 4000}
                    256: 
                    257: do_test multiplex-2.5.9 { file size [multiplex_name test.x 0] } [list $g_chunk_size]
                    258: do_test multiplex-2.5.10 { file size [multiplex_name test.x 1] } [list $g_chunk_size]
                    259: 
                    260: do_test multiplex-2.5.99 {
                    261:   db close
                    262:   sqlite3_multiplex_shutdown
                    263: } {SQLITE_OK}
                    264: 
                    265: 
                    266: set all_journal_modes {delete persist truncate memory off}
                    267: foreach jmode $all_journal_modes {
                    268:   for {set sz 151} {$sz<8000} {set sz [expr $sz+419]} {
                    269: 
                    270:     do_test multiplex-2.6.1.$sz.$jmode {
                    271:       multiplex_delete test.db
                    272:       sqlite3_multiplex_initialize "" 1
                    273:       sqlite3 db test.db
                    274:       multiplex_set db main $sz 32
                    275:     } {SQLITE_OK}
                    276: 
                    277:     do_test multiplex-2.6.2.$sz.$jmode {
                    278:       db eval {
                    279:         PRAGMA page_size = 1024;
                    280:         PRAGMA auto_vacuum = off;
                    281:       }
                    282:       db eval "PRAGMA journal_mode = $jmode;"
                    283:     } $jmode
                    284: 
                    285:     do_test multiplex-2.6.3.$sz.$jmode { 
                    286:       execsql { 
                    287:         CREATE TABLE t1(a PRIMARY KEY, b);
                    288:         INSERT INTO t1 VALUES(1, 'one');
                    289:         INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
                    290:       }
                    291:     } {}
                    292: 
                    293:     do_test multiplex-2.6.4.$sz.$jmode {
                    294:       db eval {SELECT b FROM t1 WHERE a=1}
                    295:     } {one}
                    296: 
                    297:     do_test multiplex-2.6.5.$sz.$jmode {
                    298:       db eval {SELECT length(b) FROM t1 WHERE a=2}
                    299:     } [list $g_chunk_size]
                    300: 
                    301:     do_test multiplex-2.6.6.$sz.$jmode { file size [multiplex_name test.db 0] } [list $g_chunk_size]
                    302: 
                    303:     do_test multiplex-2.6.99.$sz.$jmode {
                    304:       db close
                    305:       sqlite3_multiplex_shutdown
                    306:     } {SQLITE_OK}
                    307: 
                    308:   }
                    309: }
                    310: 
                    311: do_test multiplex-2.7.1  { multiplex_delete test.db }                                       {}
                    312: do_test multiplex-2.7.2  { sqlite3_multiplex_initialize "" 1 }                              {SQLITE_OK}
                    313: do_test multiplex-2.7.3  { sqlite3 db test.db }                                             {}
                    314: do_test multiplex-2.7.4  { lindex [ catchsql { SELECT multiplex_control(2, 65536); } ] 0 }  {0}
                    315: do_test multiplex-2.7.5  { lindex [ catchsql { SELECT multiplex_control(1, 0); } ] 0 }      {0}
                    316: do_test multiplex-2.7.6 { 
                    317:   execsql { 
                    318:     CREATE TABLE t1(a PRIMARY KEY, b);
                    319:     INSERT INTO t1 VALUES(1, randomblob(1000));
                    320:   }
                    321: } {}
                    322: # verify only one file, and file size is less than chunks size
                    323: do_test multiplex-2.7.7  { expr ([file size [multiplex_name test.db 0]] < 65536) } {1}
                    324: do_test multiplex-2.7.8  { file exists [multiplex_name test.db 1] }                {0}
                    325: do_test multiplex-2.7.9 { 
                    326:   execsql { 
                    327:     INSERT INTO t1 VALUES(2, randomblob(65536));
                    328:   }
                    329: } {}
                    330: # verify only one file, and file size exceeds chunks size
                    331: do_test multiplex-2.7.10 { expr ([file size [multiplex_name test.db 0]] > 65536) } {1}
                    332: do_test multiplex-2.7.11 { file exists [multiplex_name test.db 1] }                {0}
                    333: do_test multiplex-2.7.12 { db close }                                              {}
                    334: do_test multiplex-2.7.13 { sqlite3_multiplex_shutdown }                            {SQLITE_OK}
                    335: 
                    336: #-------------------------------------------------------------------------
                    337: # Try some tests with more than one connection to a database file. Still
                    338: # in rollback mode.
                    339: #
                    340: #   multiplex-3.1.*: Two connections to a single database file.
                    341: #
                    342: #   multiplex-3.2.*: Two connections to each of several database files (that
                    343: #                are in the same multiplex group).
                    344: #
                    345: do_test multiplex-3.1.1 {
                    346:   multiplex_delete test.db
                    347:   sqlite3_multiplex_initialize "" 1
                    348:   sqlite3 db test.db
                    349:   multiplex_set db main 32768 16
                    350: } {SQLITE_OK}
                    351: do_test multiplex-3.1.2 {
                    352:   execsql {
                    353:     PRAGMA page_size = 1024;
                    354:     PRAGMA journal_mode = delete;
                    355:     PRAGMA auto_vacuum = off;
                    356:     CREATE TABLE t1(a PRIMARY KEY, b);
                    357:     INSERT INTO t1 VALUES(1, 'one');
                    358:   }
                    359:   file size [multiplex_name test.db 0]
                    360: } {3072}
                    361: do_test multiplex-3.1.3 {
                    362:   sqlite3 db2 test.db
                    363:   execsql { CREATE TABLE t2(a, b) } db2
                    364: } {}
                    365: do_test multiplex-3.1.4 {
                    366:   execsql { CREATE TABLE t3(a, b) }
                    367: } {}
                    368: do_test multiplex-3.1.5 {
                    369:   catchsql { CREATE TABLE t3(a, b) }
                    370: } {1 {table t3 already exists}}
                    371: do_test multiplex-3.1.6 {
                    372:   db close
                    373:   db2 close
                    374: } {}
                    375: 
                    376: do_test multiplex-3.2.1a {
                    377: 
                    378:   multiplex_delete test.db
                    379:   multiplex_delete test2.db
                    380: 
                    381:   sqlite3 db1a test.db
                    382:   sqlite3 db2a test2.db
                    383: 
                    384:   foreach db {db1a db2a} {
                    385:     execsql {
                    386:       PRAGMA page_size = 1024;
                    387:       PRAGMA journal_mode = delete;
                    388:       PRAGMA auto_vacuum = off;
                    389:       CREATE TABLE t1(a, b);
                    390:     } $db
                    391:   }
                    392: 
                    393:   list [file size [multiplex_name test.db 0]] [file size [multiplex_name test2.db 0]]
                    394: } {2048 2048}
                    395: 
                    396: do_test multiplex-3.2.1b {
                    397:   sqlite3 db1b test.db
                    398:   sqlite3 db2b test2.db
                    399: } {}
                    400: 
                    401: do_test multiplex-3.2.2 { execsql { INSERT INTO t1 VALUES('x', 'y') } db1a } {}
                    402: do_test multiplex-3.2.3 { execsql { INSERT INTO t1 VALUES('v', 'w') } db1b } {}
                    403: do_test multiplex-3.2.4 { execsql { INSERT INTO t1 VALUES('t', 'u') } db2a } {}
                    404: do_test multiplex-3.2.5 { execsql { INSERT INTO t1 VALUES('r', 's') } db2b } {}
                    405: 
                    406: do_test multiplex-3.2.6 { 
                    407:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a
                    408: } {}
                    409: do_test multiplex-3.2.7 { 
                    410:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b
                    411: } {}
                    412: do_test multiplex-3.2.8 { 
                    413:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
                    414: } {}
                    415: do_test multiplex-3.2.9 { 
                    416:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
                    417: } {}
                    418: 
                    419: do_test multiplex-3.3.1 { 
                    420:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a
                    421:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b
                    422:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
                    423:   execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
                    424: } {}
                    425: 
                    426: do_test multiplex-3.2.X {
                    427:   foreach db {db1a db2a db2b db1b} { catch { $db close } }
                    428: } {}
                    429: 
                    430: #-------------------------------------------------------------------------
                    431: #
                    432: 
                    433: sqlite3_multiplex_initialize "" 1
                    434: multiplex_set db main 32768 16
                    435: 
                    436: # Return a list of all currently defined multiplexs.
                    437: proc multiplex_list {} {
                    438:   set allq {}
                    439:   foreach q [sqlite3_multiplex_dump] {
                    440:     lappend allq [lindex $q 0]
                    441:   }
                    442:   return [lsort $allq]
                    443: }
                    444: 
                    445: do_test multiplex-4.1.6 {
                    446:   multiplex_delete test2.db
                    447:   sqlite3 db test2.db
                    448:   db eval {CREATE TABLE t2(x); INSERT INTO t2 VALUES('tab-t2');}
                    449:   set res [multiplex_list]
                    450:   list [regexp {test2.db} $res]
                    451: } {1}
                    452: do_test multiplex-4.1.6a {
                    453:   sqlite3 db2 test2.db
                    454:   db2 eval {SELECT * FROM t2}
                    455: } {tab-t2}
                    456: do_test multiplex-4.1.7 {
                    457:   execsql {INSERT INTO t2 VALUES(zeroblob(200000))}
                    458: } {}
                    459: do_test multiplex-4.1.8 {
                    460:   sqlite3 db2 test2.db
                    461:   db2 eval {SELECT count(*) FROM t2}
                    462: } {2}
                    463: do_test multiplex-4.1.8a {
                    464:    db2 eval { DELETE FROM t2 WHERE x = 'tab-t2' }
                    465: } {}
                    466: do_test multiplex-4.1.8b {
                    467:   sqlite3 db2 test2.db
                    468:   db2 eval {SELECT count(*) FROM t2}
                    469: } {1}
                    470: 
                    471: 
                    472: do_test multiplex-4.1.9 {
                    473:   execsql {INSERT INTO t2 VALUES(zeroblob(200000))}
                    474: } {}
                    475: do_test multiplex-4.1.10 {
                    476:   set res [multiplex_list]
                    477:   list [regexp {test2.db} $res]
                    478: } {1}
                    479: do_test multiplex-4.1.11 {
                    480:   db2 close
                    481:   set res [multiplex_list]
                    482:   list [regexp {test2.db} $res]
                    483: } {1}
                    484: do_test multiplex-4.1.12 {
                    485:   db close
                    486:   multiplex_list
                    487: } {}
                    488: 
                    489: 
                    490: #-------------------------------------------------------------------------
                    491: # The following tests test that the multiplex VFS handles malloc and IO 
                    492: # errors.
                    493: #
                    494: 
                    495: sqlite3_multiplex_initialize "" 1
                    496: multiplex_set db main 32768 16
                    497: 
                    498: do_faultsim_test multiplex-5.1 -prep {
                    499:   catch {db close}
                    500: } -body {
                    501:   sqlite3 db test2.db
                    502: }
                    503: do_faultsim_test multiplex-5.2 -prep {
                    504:   catch {db close}
                    505: } -body {
                    506:   sqlite3 db test.db
                    507: }
                    508: 
                    509: catch { db close }
                    510: multiplex_delete test.db
                    511: multiplex_delete test2.db
                    512: 
                    513: do_test multiplex-5.3.prep {
                    514:   sqlite3 db test.db
                    515:   execsql {
                    516:     PRAGMA auto_vacuum = 1;
                    517:     PRAGMA page_size = 1024;
                    518:     CREATE TABLE t1(a, b);
                    519:     INSERT INTO t1 VALUES(10, zeroblob(1200));
                    520:   }
                    521:   faultsim_save_and_close
                    522: } {}
                    523: do_faultsim_test multiplex-5.3 -prep {
                    524:   faultsim_restore_and_reopen
                    525: } -body {
                    526:   execsql { DELETE FROM t1 }
                    527: }
                    528: 
                    529: do_test multiplex-5.4.1 {
                    530:   catch { db close }
                    531:   multiplex_delete test.db
                    532:   file mkdir test.db
                    533:   list [catch { sqlite3 db test.db } msg] $msg
                    534: } {1 {unable to open database file}}
                    535: catch { delete_file test.db }
                    536: 
                    537: do_faultsim_test multiplex-5.5 -prep {
                    538:   catch { sqlite3_multiplex_shutdown }
                    539: } -body {
                    540:   sqlite3_multiplex_initialize "" 1
                    541:   multiplex_set db main 32768 16
                    542: }
                    543: 
                    544: #-------------------------------------------------------------------------
                    545: # Test that you can vacuum a multiplex'ed DB.  
                    546: 
                    547: ifcapable vacuum {
                    548: 
                    549: sqlite3_multiplex_shutdown
                    550: do_test multiplex-6.0.0 {
                    551:   multiplex_delete test.db
                    552:   multiplex_delete test.x
                    553:   sqlite3_multiplex_initialize "" 1
                    554:   sqlite3 db test.x
                    555:   multiplex_set db main 4096 16
                    556: } {SQLITE_OK}
                    557: 
                    558: do_test multiplex-6.1.0 {
                    559:   execsql {
                    560:     PRAGMA page_size=1024;
                    561:     PRAGMA journal_mode=DELETE;
                    562:     PRAGMA auto_vacuum=OFF;
                    563:   }
                    564:   execsql {
                    565:     CREATE TABLE t1(a, b);
                    566:     INSERT INTO t1 VALUES(1, randomblob($g_chunk_size));
                    567:     INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
                    568:   }
                    569: } {}
                    570: do_test multiplex-6.2.1 { file size [multiplex_name test.x 0] } [list $g_chunk_size]
                    571: do_test multiplex-6.2.2 { file size [multiplex_name test.x 1] } [list $g_chunk_size]
                    572: 
                    573: do_test multiplex-6.3.0 {
                    574:   execsql { VACUUM }
                    575: } {}
                    576: 
                    577: do_test multiplex-6.99 {
                    578:   db close
                    579:   multiplex_delete test.x
                    580:   sqlite3_multiplex_shutdown
                    581: } {SQLITE_OK}
                    582: 
                    583: }
                    584: 
                    585: 
                    586: catch { sqlite3_multiplex_shutdown }
                    587: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>