]> gitweb.factorcode.org Git - factor.git/blob - basis/db/tester/tester.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / db / tester / tester.factor
1 ! Copyright (C) 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: concurrency.combinators db.pools db.sqlite db.tuples
4 db.types kernel math random threads tools.test db sequences
5 io prettyprint ;
6 IN: db.tester
7
8 TUPLE: test-1 id a b c ;
9
10 test-1 "TEST1" {
11    { "id" "ID" INTEGER +db-assigned-id+ }
12    { "a" "A" { VARCHAR 256 } +not-null+ }
13    { "b" "B" { VARCHAR 256 } +not-null+ }
14    { "c" "C" { VARCHAR 256 } +not-null+ }
15 } define-persistent
16
17 TUPLE: test-2 id x y z ;
18
19 test-2 "TEST2" {
20    { "id" "ID" INTEGER +db-assigned-id+ }
21    { "x" "X" { VARCHAR 256 } +not-null+ }
22    { "y" "Y" { VARCHAR 256 } +not-null+ }
23    { "z" "Z" { VARCHAR 256 } +not-null+ }
24 } define-persistent
25
26 : sqlite-test-db ( -- db ) "test.db" <sqlite-db> ;
27 : test-db ( -- db ) "test.db" <sqlite-db> ;
28
29 : db-tester ( test-db -- )
30     [
31         [
32             test-1 ensure-table
33             test-2 ensure-table
34         ] with-db
35     ] [
36         10 [
37             drop
38             10 [
39                 dup [
40                     f 100 random 100 random 100 random test-1 boa
41                     insert-tuple yield
42                 ] with-db
43             ] times
44         ] with parallel-each
45     ] bi ;
46
47 : db-tester2 ( test-db -- )
48     [
49         [ test-1 recreate-table ] with-db
50     ] [
51         [
52             2 [
53                     10 random 100 random 100 random 100 random test-1 boa
54                     insert-tuple yield
55             ] parallel-each
56         ] with-db
57     ] bi ;