forked from couchbaselabs/php-couchbase-v2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Couchbase 2.0 Developer Preview comaptiblity.
Make E_STRICT aware.
- Loading branch information
Showing
11 changed files
with
373 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Interface to the Couchbase 2.0 HTTP API. | ||
* | ||
* @package Couchbase | ||
*/ | ||
|
||
class Couchbase_Internal extends Couchbase_CouchDB | ||
{ | ||
function deleteDb($name, $cb) | ||
{ | ||
$result = $this->send("DELETE", "/pools/default/buckets/$name"); | ||
if(empty($result)) { // some error deleting, don't wait. | ||
$this->waitForBucket($cb, Memcached::RES_UNKNOWN_READ_FAILURE); | ||
} | ||
return $result; | ||
} | ||
|
||
function createDb($name, $cb) | ||
{ | ||
$result = $this->send( | ||
"POST", "/pools/default/buckets", | ||
"name=$name&ramQuotaMB=100&authType=sasl&replicaNumber=0&proxyPort=11215", | ||
"application/x-www-form-urlencoded" | ||
); | ||
$this->waitForBucket($cb); | ||
return $result; | ||
} | ||
|
||
/** | ||
* bucket creation is async, for the time being, we need to poll until | ||
* it is there. | ||
*/ | ||
function waitForBucket($cb, $resultCode = Memcached::RES_SUCCESS) | ||
{ | ||
// var_dump("--waitForBucket"); | ||
do { | ||
$cb->set("f", 1); | ||
usleep(500000); // 1/2 second | ||
// var_dump($cb->getResultMessage()); | ||
} while($cb->getResultCode() !== $resultCode); | ||
$cb->delete("f"); | ||
// var_dump("--done waiting"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
Oops, something went wrong.