Paste: testcase

Author: slava
Mode: factor
Date: Wed, 17 Dec 2008 22:48:27
Plain Text |
USING: concurrency.combinators db.pools db.sqlite db.tuples
db.types kernel math random threads ;
IN: db-tester

TUPLE: test-1 id a b c ;

test-1 "TEST1" {
    { "id" "ID" INTEGER +db-assigned-id+ }
    { "a" "A" { VARCHAR 256 } +not-null+ }
    { "b" "B" { VARCHAR 256 } +not-null+ }
    { "c" "C" { VARCHAR 256 } +not-null+ }
} define-persistent

TUPLE: test-2 id x y z ;

test-2 "TEST2" {
    { "id" "ID" INTEGER +db-assigned-id+ }
    { "x" "X" { VARCHAR 256 } +not-null+ }
    { "y" "Y" { VARCHAR 256 } +not-null+ }
    { "z" "Z" { VARCHAR 256 } +not-null+ }
} define-persistent

: test-db ( -- db ) "test.db" <sqlite-db> ;

: db-tester ( -- )
    test-db <db-pool> [
        [
            test-1 ensure-table
            test-2 ensure-table
        ] with-pooled-db
    ] [
        10 [
            drop
            100 [
                dup [
                    f 100 random 100 random 100 random test-1 boa insert-tuple
                    yield
                    f 100 random 100 random 100 random test-2 boa insert-tuple
                    yield
                ] with-pooled-db
            ] times
        ] with parallel-each
    ] bi ;

New Annotation

Summary:
Author:
Mode:
Body: