File: 10-crud.t

package info (click to toggle)
libdbd-cassandra-perl 0.57-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: perl: 286; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use 5.010;
use warnings;
use strict;
use Test::More;

unless ($ENV{CASSANDRA_HOST}) {
    plan skip_all => "CASSANDRA_HOST not set";
}

plan tests => 9;

use DBI;
my $tls= $ENV{CASSANDRA_TLS} // '';
my $port= $ENV{CASSANDRA_PORT} ? ";port=$ENV{CASSANDRA_PORT}" : "";
my $dbh= DBI->connect("dbi:Cassandra:host=$ENV{CASSANDRA_HOST};tls=$tls$port", $ENV{CASSANDRA_USER}, $ENV{CASSANDRA_AUTH}, {RaiseError => 1, Warn => 1, PrintWarn => 0, PrintError => 0});
ok($dbh);

my $keyspace= "dbd_cassandra_tests";

ok(!eval {
    # Invalid: can't use prepared statements here
    $dbh->do('drop keyspace if exists ?', undef, $keyspace);
});

$dbh->do("drop keyspace if exists $keyspace");
$dbh->do("create keyspace $keyspace with replication={'class': 'SimpleStrategy', 'replication_factor': 1}");

ok(!eval {
    # Invalid: no keyspace selected
    $dbh->do("create table test_int (id bigint primary key)");
});

$dbh->do("create table $keyspace.test_int (id bigint primary key)");

my $last_res;
for (1..5) {
    $last_res= $dbh->do("insert into $keyspace.test_int (id) values (?)", undef, $_);
}
is($last_res, '0E0');

for my $row (@{ $dbh->selectall_arrayref("select count(*) from $keyspace.test_int") }) {
    is($row->[0], 5);
}

ok(!eval {
    # Can't have a string in an integer
    $dbh->do("insert into $keyspace.test_int (id) values 'test'");
});

$dbh->do("delete from $keyspace.test_int where id in (?,?,3)", undef, 1, 2);
for my $row (@{ $dbh->selectall_arrayref("select count(*) from $keyspace.test_int") }) {
    is($row->[0], 2);
}

ok($dbh->do("insert into $keyspace.test_int (id) values (6)", { Consistency => 'any' }));
ok(!eval {
    # We have replication_factor=1, 'two' shouldn't work
    $dbh->do("insert into $keyspace.test_int (id) values (5)", { Consistency => 'two' });
});

$dbh->disconnect;