File: 04-batch.t

package info (click to toggle)
libcassandra-client-perl 0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 716 kB
  • sloc: perl: 3,898; ansic: 1,767; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 1,138 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
#!perl
use 5.010;
use strict;
use warnings;
use File::Basename qw//; use lib File::Basename::dirname(__FILE__).'/lib';
use Test::More;
use TestCassandra;

plan skip_all => "Missing Cassandra test environment" unless TestCassandra->is_ok;
plan tests => 7;

my $client= TestCassandra->new;
$client->connect();

my $db= 'perl_cassandra_client_tests';
$client->execute("drop keyspace if exists $db");
$client->execute("create keyspace $db with replication={'class':'SimpleStrategy', 'replication_factor': 1}");
$client->execute("create table $db.test_int (id int primary key, value int)");
$client->batch([
    [ "insert into $db.test_int (id, value) values (?, ?)", [5, 6] ],
    [ "insert into $db.test_int (id, value) values (?, ?)", [6, 6] ],
    [ "insert into $db.test_int (id, value) values (?, ?)", [7, 6] ],
]);
{
    my ($result)= $client->execute("select id, value from $db.test_int where id in (5, 6, 7, 8)");
    my $rows= $result->rows;
    ok(@$rows == 3);
    ok($rows->[0][0] == 5);
    ok($rows->[0][1] == 6);
    ok($rows->[1][0] == 6);
    ok($rows->[1][1] == 6);
    ok($rows->[2][0] == 7);
    ok($rows->[2][1] == 6);
}