forked from couchbaselabs/php-couchbase-v2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CouchbaseClusterTest.php
90 lines (75 loc) · 2.63 KB
/
CouchbaseClusterTest.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require_once "Couchbase.php";
require_once "test/lib.php";
require_once "PHPUnit/Framework/TestCase.php";
/**
* Couchbase test class for PHPUnit.
*
* @package Couchbase
*/
class CouchbaseTest extends PHPUnit_Framework_TestCase
{
function setUp()
{
$this->cb = new Couchbase;
$this->cb->addCouchbaseServer("localhost", 12001, 9500);
$this->cb->flush();
// $this->cb->couchbase->deleteDb("default", $this->cb);
$this->cb->couchbase->createDb("default", $this->cb);
$this->lib = new Couchbase_Test_Lib($this->cb);
}
function tearDown()
{
$this->cb->flush();
unset($this->cb);
}
function kill_node($node)
{
$cmd = "kill `ps ax | grep beam | grep n_$node | awk '{print $1}'`";
`$cmd`;
}
function test_basic_query()
{
$this->lib->prepare_docs();
$this->lib->prepare_ddoc();
$view = $this->cb->getView("default", "name");
$this->assertInstanceOf("Couchbase_View", $view);
$result = $view->getResult();
$this->assertInstanceOf("Couchbase_ViewResult", $result);
$this->assertEquals(3, count($result->rows));
$this->assertEquals("Ben", $result->rows[0]->key);
$this->assertEquals("James", $result->rows[1]->key);
$this->assertEquals("Simon", $result->rows[2]->key);
}
function test_a_b()
{
$this->cb->set("a", '{"a":1}');
$this->cb->set("b", '{"a":2}');
$view = new Couchbase_View;
$view->setMapFunction("function(doc) { emit(doc.a, 1); }");
$this->cb->addView("default", "cluster", $view);
sleep(10);
$view = $this->cb->getView("default", "cluster");
$result = $view->getResult();
$this->assertInstanceOf("Couchbase_ViewResult", $result);
$this->assertEquals(2, count($result->rows));
$this->assertEquals("1", $result->rows[0]->key);
$this->assertEquals("2", $result->rows[1]->key);
}
function test_a_b_with_dead_node()
{
$this->cb->set("a", '{"a":1}');
$this->cb->set("b", '{"a":2}');
$view = new Couchbase_View;
$view->setMapFunction("function(doc) { emit(doc.a, 1); }");
$this->cb->addView("default", "cluster", $view);
sleep(10);
$this->kill_node(1);
$view = $this->cb->getView("default", "cluster");
$result = $view->getResult();
$this->assertInstanceOf("Couchbase_ViewResult", $result);
$this->assertEquals(2, count($result->rows));
$this->assertEquals("1", $result->rows[0]->key);
$this->assertEquals("2", $result->rows[1]->key);
}
}