Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated tests, dual-mode for testing on real cluster, too

  • Loading branch information...
commit 6892af58ede10003d7529c643f8f6f01a7b38c03 1 parent b4de233
M. Nunberg authored
3  .gitmodules
... ...
@@ -0,0 +1,3 @@
  1
+[submodule "Config"]
  2
+	path = Config
  3
+	url = file://Config
1  Config
... ...
@@ -0,0 +1 @@
  1
+Subproject commit d746ddff0d7e449a86712531ccf8f66f355b57ca
7  PLCB_Config.pm
... ...
@@ -1,8 +1,11 @@
  1
+package PLCB_Config;
  2
+use strict;
  3
+use warnings;
1 4
 #this perl 'hash' contains configuration information necessary
2 5
 #to bootstrap and/or configure the perl couchbase client and run
3 6
 #necessary tests.
4 7
 
5  
-{
  8
+my $params = {
6 9
     COUCHBASE_INCLUDE_PATH  => "/sources/libcouchbase/include",
7 10
     COUCHBASE_LIBRARY_PATH  => "/sources/libcouchbase/.libs",
8 11
 
@@ -12,3 +15,5 @@
12 15
         "CouchbaseMock/0.5-SNAPSHOT/CouchbaseMock-0.5-20120202.071818-12.jar",
13 16
 };
14 17
 
  18
+
  19
+return $params; #return value
49  README.pod
Source Rendered
@@ -31,6 +31,19 @@ etc. client for Couchbase.
31 31
 
32 32
 Interface to the Java C<CouchbaseMock.jar>. This is a work in progress.
33 33
 
  34
+=head2 Extra Components
  35
+
  36
+=head3 Couchbase::Config - REST API module
  37
+
  38
+This module will probably be a dependency for full testing, but will not necessarily
  39
+be part of this distribution. It's currently available as a separate repository
  40
+on github.
  41
+
  42
+=head3 Couchbase::VBucket - VBucket server mapping module
  43
+
  44
+Just a little utility module. May be useful for testing.
  45
+
  46
+
34 47
 =head1 Installing
35 48
 
36 49
 I will be focusing on installing and configuring C<libcouchbase> itself, the C
@@ -128,4 +141,38 @@ run
128 141
 There are some top-level scripts. Some have meaning to only the author, some might
129 142
 be useful.
130 143
 
131  
-Also, check out the runnable modules in the C<t/> directory
  144
+Also, check out the runnable modules in the C<t/> directory
  145
+
  146
+=head2 Testing
  147
+
  148
+The tests in this module require java to run. Some tests furthermore will only
  149
+work on a real cluster, due to some of the limitations in the Java client.
  150
+
  151
+To run the tests on a real cluster, you can make use of the
  152
+C<PLCB_TEST_REAL_SERVER> environment variable.
  153
+
  154
+When set, it should/can contain something like this:
  155
+
  156
+    PLCB_TEST_REAL_SERVER='bucket=my_bucket,username=secret,memd_port=11212'
  157
+    
  158
+The keys available are
  159
+
  160
+=over
  161
+
  162
+=item username, password
  163
+
  164
+Authentication information
  165
+
  166
+=item bucket
  167
+
  168
+Which bucket to use (default is C<default>)
  169
+
  170
+=item server
  171
+
  172
+Which server to connect to (default is C<localhost:8091>)
  173
+
  174
+=item memd_port
  175
+
  176
+Required for some tests. This is the authless port for memcached client access.
  177
+
  178
+=back
10  lib/Couchbase/Test/Async.pm
@@ -42,7 +42,10 @@ sub _run_poe {
42 42
 
43 43
 sub cb_result_single {
44 44
     my ($key,$return,$errnum) = @_;
45  
-    is($return->errnum, $errnum, "Got return for key $key ($errnum)");
  45
+    if($errnum >= 0) {
  46
+        is($return->errnum, $errnum,
  47
+           "Got return for key $key (expected=$errnum)");
  48
+    }
46 49
     $Return = $return;
47 50
 }
48 51
 
@@ -81,11 +84,12 @@ sub T12_get :Test(no_plan) {
81 84
     is($ret->value, $self->k2v($key), "Got expected value");
82 85
 }
83 86
 
84  
-sub T13_arith_ext :Test(no_plan) {
  87
+sub T14_arith_ext :Test(no_plan) {
85 88
     my $self = shift;
86  
-    my $key = "arith";
  89
+    my $key = "async_key";
87 90
     
88 91
     my $ret;
  92
+    $self->post_to_loop(remove => [$key], -1);
89 93
     
90 94
     $ret = $self->post_to_loop(
91 95
         arithmetic => [ $key, 42, undef ], COUCHBASE_KEY_ENOENT);
3  lib/Couchbase/Test/Async/Loop.pm
@@ -303,7 +303,8 @@ sub _arith_basic :Event(incr, decr) {
303 303
     $_[HEAP]->_numop_common($key, $delta, undef, $expiry, $cb_params);
304 304
 }
305 305
 
306  
-sub _keyop :Event(touch, remove, delete) {
  306
+sub _keyop :Event(touch, remove)
  307
+{
307 308
     my ($op_params, $cb_params) = @_[ARG0,ARG1];
308 309
     my ($key,$expiry,$cas);
309 310
     my $command;
38  lib/Couchbase/Test/Common.pm
@@ -7,7 +7,8 @@ use Couchbase::MockServer;
7 7
 use Data::Dumper;
8 8
 
9 9
 our $Mock;
10  
-
  10
+our $RealServer = $ENV{PLCB_TEST_REAL_SERVER};
  11
+our $MemdPort = $ENV{PLCB_TEST_MEMD_PORT};
11 12
 sub mock_init
12 13
 {
13 14
     my $self = shift;
@@ -21,6 +22,11 @@ sub mock { $_[0]->{mock} }
21 22
 
22 23
 sub common_options {
23 24
     my $self = shift;
  25
+    
  26
+    if($RealServer) {
  27
+        return { %$RealServer };
  28
+    }
  29
+    
24 30
     my $opthash = {};
25 31
     my $defbucket = $self->mock->buckets->[0];
26 32
     
@@ -33,6 +39,17 @@ sub common_options {
33 39
     return $opthash;
34 40
 }
35 41
 
  42
+sub memd_options {
  43
+    if(!$MemdPort) {
  44
+        die("Cannot find Memcached port");
  45
+    }
  46
+    my ($hostname) = split(/:/, $RealServer->{server});
  47
+    $hostname .= ":$MemdPort";
  48
+    return {
  49
+        servers => [ $hostname ]
  50
+    };
  51
+}
  52
+
36 53
 sub k2v {
37 54
     my ($self,$k) = @_;
38 55
     reverse($k);
@@ -43,10 +60,23 @@ sub v2k {
43 60
     reverse($v);
44 61
 }
45 62
 
46  
-
47 63
 sub Initialize {
48 64
     my ($cls,%opts) = @_;
49  
-    $Mock = Couchbase::MockServer->new(%opts);
50  
-    return $Mock;
  65
+    if($RealServer && (!ref $RealServer) ) {
  66
+        warn("Using real server..");
  67
+        my @kvpairs = split(/,/, $RealServer);
  68
+        $RealServer = {};
  69
+        foreach my $pair (@kvpairs) {
  70
+            my ($k,$v) = split(/=/, $pair);
  71
+            $RealServer->{$k} = $v if $k =~ /server|bucket|username|password|memd_port/;
  72
+        }
  73
+        $RealServer->{server} ||= "localhost:8091";
  74
+        $RealServer->{bucket} ||= "default";
  75
+        $MemdPort ||= delete $RealServer->{memd_port};
  76
+        $Mock = 1;
  77
+    } else {
  78
+        $Mock = Couchbase::MockServer->new(%opts);
  79
+        return $Mock;
  80
+    }
51 81
 }
52 82
 1;
91  lib/Couchbase/Test/Interop.pm
@@ -6,31 +6,39 @@ use Test::More;
6 6
 use Couchbase::Client::Errors;
7 7
 use Data::Dumper;
8 8
 use Class::XSAccessor {
9  
-    accessors => [qw(cbo memds confua vbconf)]
  9
+    accessors => [qw(cbo memds memd confua vbconf)]
10 10
 };
11 11
 
12 12
 my $MEMD_CLASS;
13 13
 my $have_memcached = 
14 14
 eval {
  15
+    require Cache::Memcached::Fast;
  16
+    $MEMD_CLASS = "Cache::Memcached::Fast";
  17
+} ||
  18
+eval {
  19
+    require Cache::Memcached;
  20
+    $MEMD_CLASS = "Cache::Memcached";
  21
+} ||
  22
+eval {
15 23
     require Cache::Memcached::libmemcached;
16  
-    $MEMD_CLASS = "Cache::Memcached::libmemcached";
  24
+    $MEMD_CLASS = "Cache::Memcaced::libmemcached";
17 25
 };
18 26
 
19  
-my $have_libvbucket = eval 'use Couchbase::VBucket; 1;';
20  
-my $have_couchconf = eval 'use Couchbase::Config::UA; 1;';
21  
-
22  
-if(!$have_memcached) {
23  
-    __PACKAGE__->SKIP_ALL("Need Cache::Memcached::libmemcached");
24  
-}
25  
-if(!$have_libvbucket) {
26  
-    __PACKAGE__->SKIP_ALL("Need Couchbase::VBucket");
27  
-}
28  
-if(!$have_couchconf) {
29  
-    __PACKAGE__->SKIP_ALL("Need Couchbase::Config::UA");
30  
-}
31 27
 
32 28
 sub setup_client :Test(startup) {
33 29
     my $self = shift;
  30
+    if(!$have_memcached) {
  31
+        $self->SKIP_ALL("Need Cache::Memcached::libmemcached");
  32
+    }
  33
+    
  34
+    if(!$Couchbase::Test::Common::RealServer) {
  35
+        $self->SKIP_ALL("Need connection to real cluster");
  36
+    }
  37
+    
  38
+    if(!$Couchbase::Test::Common::MemdPort) {
  39
+        $self->SKIP_ALL("Need dedicated memcached proxy port");
  40
+    }
  41
+
34 42
     $self->mock_init();
35 43
     my $server = $self->common_options->{server};
36 44
     
@@ -43,35 +51,13 @@ sub setup_client :Test(startup) {
43 51
     
44 52
     $self->cbo($cbo);
45 53
     
46  
-    my $confua = Couchbase::Config::UA->new(
47  
-        $server, username => $username, password => $password);
48  
-    
49  
-    #Get the actual memcached ports:
50  
-    my $default_pool = $confua->list_pools();
51  
-    my $pool_info = $confua->pool_info($default_pool);
52  
-    my $buckets = $confua->list_buckets($pool_info);
53  
-    
54  
-    my $selected_bucket = (grep($_->name eq $self->common_options->{bucket},
55  
-                               @$buckets))[0];
56  
-    
57  
-    die("Cannot find selected bucket") unless defined $selected_bucket;
58  
-    my $vbconf = $selected_bucket->vbconf();
59  
-    $self->vbconf($vbconf);
60  
-    $self->memds({});
  54
+    my $memd = $MEMD_CLASS->new($self->memd_options);
  55
+    $self->memd($memd);
61 56
 }
62 57
 
63 58
 sub memd_for_key {
64 59
     my ($self,$key) = @_;
65  
-    my $server = $self->vbconf->map($key);
66  
-    die("Couldn't map key!") unless $server;
67  
-    my $memd = $self->memds->{$server};
68  
-    if(!$memd) {
69  
-        $memd = $MEMD_CLASS->new({servers => [$server] } );
70  
-        eval { $memd->set_binary_protocol(1) };
71  
-        $self->memds->{$server} = $memd;
72  
-        note "Created new memcached object for $server";
73  
-    }
74  
-    return $memd;
  60
+    return $self->memd;
75 61
 }
76 62
 
77 63
 sub T30_interop_init :Test(no_plan)
@@ -80,7 +66,7 @@ sub T30_interop_init :Test(no_plan)
80 66
     my $key = "Foo";
81 67
     my $value = "foo_value";
82 68
     
83  
-    my $memd = $self->memd_for_key($key);
  69
+    my $memd = $self->memd;
84 70
     
85 71
     ok($memd->set($key, $value), "Set value OK");
86 72
     is($memd->get($key), $value, "Got back our value");
@@ -88,7 +74,30 @@ sub T30_interop_init :Test(no_plan)
88 74
     my $ret = $self->cbo->get($key);
89 75
     ok($ret->is_ok, "Found value for memcached key");
90 76
     is($ret->value, $value, "Got back same value");
91  
-    #print Dumper($ret);
  77
+    
  78
+    $key = "bar";
  79
+    $value = "bar_value";
  80
+    
  81
+    ok($self->cbo->set($key,$value)->is_ok, "set via cbc");
  82
+    is($memd->get($key), $value, "get via memd");
  83
+}
  84
+
  85
+sub T31_interop_serialization :Test(no_plan) {
  86
+    my $self = shift;
  87
+    my $key = "Serialized";
  88
+    my $value = [ qw(foo bar baz), { "this is" => "a hash" } ];
  89
+    my $memd = $self->memd_for_key($key);
  90
+    
  91
+    ok($memd->set($key, $value), "Set serialized structure");
  92
+    my $ret;
  93
+    $ret = $self->cbo->get($key);
  94
+    ok($ret->is_ok, "Got ok result");
  95
+    is_deeply($ret->value, $value, "Compared identical perl structures");
  96
+    is_deeply($memd->get($key), $ret->value,"even deeper comparison");
  97
+}
  98
+
  99
+sub T32_interop_compression :Test(no_plan) {
  100
+    
92 101
 }
93 102
 
94 103
 1;
73  lib/Couchbase/Test/Settings.pm
... ...
@@ -0,0 +1,73 @@
  1
+package Couchbase::Test::Settings;
  2
+use strict;
  3
+use warnings;
  4
+use base qw(Couchbase::Test::Common);
  5
+use Test::More;
  6
+use Couchbase::Client::Errors;
  7
+use Data::Dumper;
  8
+
  9
+use Class::XSAccessor {
  10
+    accessors => [qw(cbo)]
  11
+};
  12
+
  13
+sub setup_client :Test(startup)
  14
+{
  15
+    my $self = shift;
  16
+    $self->mock_init();
  17
+    
  18
+    my %options = (
  19
+        %{$self->common_options},
  20
+        compress_threshold => 100
  21
+    );
  22
+    
  23
+    my $o = Couchbase::Client->new(\%options);
  24
+    
  25
+    $self->cbo( $o );
  26
+}
  27
+
  28
+sub T20_settings_connect :Test(no_plan)
  29
+{
  30
+    my $self = shift;
  31
+    
  32
+    my $client = Couchbase::Client->new({
  33
+        username => "bad",
  34
+        password => "12345",
  35
+        bucket => "nonexistent",
  36
+        no_init_connect => 1,
  37
+        server => '127.0.0.1:0'
  38
+    });
  39
+    is(scalar @{$client->get_errors()}, 0,
  40
+       "No error on initial connect with no_init_connect => 1");
  41
+    
  42
+    my $ret = $client->set("Foo", "Bar");
  43
+    is($ret->errnum, COUCHBASE_ETMPFAIL, "Got ETMPFAIL on non-connected server");
  44
+    
  45
+    ok(!$client->connect, "Failure to connect to nonexistent host");
  46
+    my $errors = $client->get_errors;
  47
+    ok(scalar @$errors, "Have error");
  48
+    is($errors->[0]->[0], COUCHBASE_NETWORK_ERROR, "Got NETWORK_ERROR");
  49
+    
  50
+    $client = Couchbase::Client->new({
  51
+        %{$self->common_options},
  52
+        bucket => 'nonexist'
  53
+    });
  54
+    $errors = $client->get_errors();
  55
+    ok(scalar @$errors, "Have error for nonexistent bucket");
  56
+    is($errors->[0]->[0], COUCHBASE_BUCKET_ENOENT,
  57
+       "Got BUCKET_ENOENT for nonexistent bucket");
  58
+}
  59
+
  60
+
  61
+sub T21_compress_settings :Test(no_plan)
  62
+{
  63
+    my $self = shift;
  64
+    my $v;
  65
+    
  66
+    $v = $self->cbo->enable_compress();
  67
+    ok($v, "Compression enabled by default");
  68
+    
  69
+    $v = $self->cbo->enable_compress(0);
  70
+    is($self->cbo->enable_compress, 0, "Compression disabled via setter");
  71
+}
  72
+
  73
+1;
4  t/01-main.t
@@ -19,11 +19,11 @@ Couchbase::Test::Common->Initialize(
19 19
 use Couchbase::Test::ClientSync;
20 20
 use Couchbase::Test::Async;
21 21
 use Couchbase::Test::Settings;
22  
-#use Couchbase::Test::Interop;
  22
+use Couchbase::Test::Interop;
23 23
 
24 24
 Couchbase::Test::ClientSync->runtests();
25 25
 Couchbase::Test::Async->runtests();
26 26
 Couchbase::Test::Settings->runtests();
27  
-#Couchbase::Test::Interop->runtests();
  27
+Couchbase::Test::Interop->runtests();
28 28
 
29 29
 #Test::Class->runtests();

0 notes on commit 6892af5

Please sign in to comment.
Something went wrong with that request. Please try again.