| 1 |
use Test::More tests => 5; |
|---|
| 2 |
|
|---|
| 3 |
use Carp; |
|---|
| 4 |
use Data::Dump qw( dump ); |
|---|
| 5 |
|
|---|
| 6 |
use_ok('SWISH::Prog::Indexer::Native'); |
|---|
| 7 |
|
|---|
| 8 |
# we use Rose::DBx::TestDB just for devel testing. |
|---|
| 9 |
# don't expect normal users to have it. |
|---|
| 10 |
SKIP: { |
|---|
| 11 |
eval "use SWISH::Prog::Aggregator::DBI"; |
|---|
| 12 |
if ($@) { |
|---|
| 13 |
skip "DBI tests require DBI", 4; |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
eval "use Rose::DBx::TestDB"; |
|---|
| 17 |
if ($@) { |
|---|
| 18 |
skip "Rose::DBx::TestDB not installed", 4; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
# is executable present? |
|---|
| 22 |
my $indexer = SWISH::Prog::Indexer::Native->new; |
|---|
| 23 |
if ( !$indexer->swish_check ) { |
|---|
| 24 |
skip "swish-e not installed", 4; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
# create db. |
|---|
| 28 |
my $db = Rose::DBx::TestDB->new; |
|---|
| 29 |
|
|---|
| 30 |
my $dbh = $db->retain_dbh; |
|---|
| 31 |
|
|---|
| 32 |
# put some data in it. |
|---|
| 33 |
$dbh->do( " |
|---|
| 34 |
CREATE TABLE foo ( |
|---|
| 35 |
id integer primary key autoincrement, |
|---|
| 36 |
myint integer not null default 0, |
|---|
| 37 |
mychar varchar(16), |
|---|
| 38 |
mydate integer not null default 1 |
|---|
| 39 |
); |
|---|
| 40 |
" ) |
|---|
| 41 |
or croak "create failed: " . $dbh->errstr; |
|---|
| 42 |
|
|---|
| 43 |
$dbh->do( " |
|---|
| 44 |
INSERT INTO foo (myint, mychar, mydate) VALUES (100, 'hello', 1000000); |
|---|
| 45 |
" ) or croak "insert failed: " . $dbh->errstr; |
|---|
| 46 |
|
|---|
| 47 |
my $sth = $dbh->prepare("SELECT * from foo"); |
|---|
| 48 |
$sth->execute; |
|---|
| 49 |
|
|---|
| 50 |
# index it |
|---|
| 51 |
ok( my $aggr = SWISH::Prog::Aggregator::DBI->new( |
|---|
| 52 |
db => $dbh, |
|---|
| 53 |
indexer => SWISH::Prog::Indexer::Native->new( |
|---|
| 54 |
invindex => 't/dbi_index', |
|---|
| 55 |
), |
|---|
| 56 |
schema => { |
|---|
| 57 |
foo => { |
|---|
| 58 |
id => { type => 'int' }, |
|---|
| 59 |
myint => { type => 'int', bias => 10 }, |
|---|
| 60 |
mychar => { type => 'char' }, |
|---|
| 61 |
mydate => { type => 'date' }, |
|---|
| 62 |
} |
|---|
| 63 |
}, |
|---|
| 64 |
), |
|---|
| 65 |
"new aggregator" |
|---|
| 66 |
); |
|---|
| 67 |
|
|---|
| 68 |
ok( $aggr->indexer->start, "indexer started" ); |
|---|
| 69 |
|
|---|
| 70 |
is( $aggr->crawl(), 1, "row data indexed" ); |
|---|
| 71 |
|
|---|
| 72 |
ok( $aggr->indexer->finish, "indexer finished" ); |
|---|
| 73 |
|
|---|
| 74 |
} |
|---|