Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 1ebe4a85491b14b5afb95dcc806769edff2131a5 @wdavidw wdavidw committed Jan 28, 2010
2 .gitignore
@@ -0,0 +1,2 @@
+.*
+!.gitignore
86 src/PopHbase.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Central class around HBase server access.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbase{
+
+ public $options;
+
+ public function __construct($options){
+ $this->options = $options;
+ }
+
+ /**
+ * Detruct current instance, its potential circular references and close the HBase connection if opened.
+ */
+ public function __destruct(){
+
+ }
+
+ public function __get($property){
+ switch($property){
+ case 'connection':
+ return $this->connection = new PopHbaseConnectionSock($this->options);
+ break;
+ case 'tables':
+ return $this->getTables();
+ break;
+ case 'request':
+ return new PopHbaseRequest($this);
+ break;
+ }
+ }
+
+ public function __call($method,$args){
+ switch($method){
+ case 'tables':
+ return call_user_func_array(array($this,'getTables'),$args);
+ }
+ }
+
+ /**
+ * Shortcut to the PHP Magick destruct method.
+ */
+ public function destruct(){
+
+ }
+
+ /**
+ * Retrieve the list of all databases in HBase.
+ */
+ public function getTables(){
+ if(isset($this->tables)) return $this->tables;
+ return $this->tables = new PopHbaseTables($this);
+ }
+
+ /**
+ * Return the Stargate connection version information
+ */
+ public function getVersion(){
+ return $this->request->get('version')->getBody();
+ }
+
+ /**
+ * Return the Stargate version cluster information
+ */
+ public function getVersionCluster(){
+ return $this->request->get('version/cluster')->getBody();
+ }
+
+ /**
+ * Return the Stargate satus cluster information
+ */
+ public function getStatusCluster(){
+ return $this->request->get('status/cluster')->getBody();
+ }
+
+}
56 src/PopHbaseConnection.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Wrap a HBase server connection.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+interface PopHbaseConnection{
+
+ /**
+ * Connection constructor with its related information.
+ *
+ * Options may include:
+ * - *host*
+ * Hbase server host, default to "localhost"
+ * - *port*
+ * Hbase server port, default to "5984"
+ *
+ * @param $options
+ * @return unknown_type
+ */
+ public function __construct(array $options = array());
+
+ /**
+ * Open the connection to the HBase server.
+ *
+ * @return PopHbaseConnection Current connection instance
+ */
+ public function connect();
+
+ /**
+ * Destruct the current instance and close its connection if opened.
+ */
+ public function destruct();
+
+ /**
+ * Close the connection to the HBase server.
+ *
+ * @return PopHbaseConnection Current connection instance
+ */
+ public function disconnect();
+
+ /**
+ * Send HTTP REST command.
+ *
+ * @return PopHbaseResponse Response object parsing the HTTP HBase response.
+ */
+ public function execute($method,$url,$data=null,$raw=false);
+
+}
206 src/PopHbaseConnectionSock.php
@@ -0,0 +1,206 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Socket implementation of an HBase server connection.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseConnectionSock implements PopHbaseConnection{
+
+ public $options;
+
+ /**
+ * Connection constructor with its related information.
+ *
+ * Options may include:
+ * - *host*
+ * Hbase server host, default to "localhost"
+ * - *port*
+ * Hbase server port, default to "5984"
+ *
+ * @param $options
+ * @return unknown_type
+ */
+ public function __construct(array $options = array()){
+ if(!isset($options['host'])){
+ $options['host'] = 'localhost';
+ }
+ if(!isset($options['port'])){
+ $options['port'] = 5984;
+ }
+ if(!isset($options['alive'])){
+ $options['alive'] = 1;
+ }
+ // todo, this suggest that password may be empty like with MySql, need to check this
+ if(!empty($this->options['username'])&&!isset($this->options['password'])){
+ $this->options['password'] = '';
+ }
+ $this->options = $options;
+ }
+
+ public function __destruct(){
+ if(isset($this->options['sock'])){
+ $this->disconnect();
+ }
+ }
+
+ /**
+ * Magick method used to retrieve connected related information
+ */
+ public function __get($property){
+ switch($property){
+ case 'sock':
+ if(!isset($this->options['sock'])){
+ $this->connect();
+ }
+ default:
+ return $this->options[$property];
+ }
+ }
+
+ /**
+ * Open the connection to the HBase server.
+ *
+ * @return PopHbaseConnection Current connection instance
+ */
+ public function connect() {
+ if(isset($this->options['sock'])){
+ $this->disconnect();
+ }
+ $this->options['sock'] = fsockopen($this->options['host'], $this->options['port'], $errNum, $errString);
+ if(!$this->options['sock']) {
+ throw new PopHbaseException('Failed connecting to '.(!empty($this->options['username'])?$this->options['username'].'@':'').$this->options['host'].':'.$this->options['port'].' ('.$errString.')');
+ }
+ return $this;
+ }
+
+ /**
+ * Destruct the current instance and close its connection if opened.
+ */
+ public function destruct() {
+ $this->__destruct();
+ }
+
+ /**
+ * Close the connection to the HBase server.
+ *
+ * @return PopHbaseConnection Current connection instance
+ */
+ public function disconnect() {
+ if(!isset($this->options['sock'])){
+ // nothing to do
+ return $this;
+ }
+ fclose($this->options['sock']);
+ unset($this->options['sock']);
+ return $this;
+ }
+
+ /**
+ * Send HTTP REST command.
+ *
+ * @return PopHbaseResponse Response object parsing the HTTP HBase response.
+ */
+ public function execute($method,$url,$data=null,$raw=false) {
+ $url = (substr($url, 0, 1) == '/' ? $url : '/'.$url);
+ $request = $method.' '.$url.' HTTP/1.1'."\r\n";
+ $request .= 'Host: '.$this->options['host'].':'.$this->options['port']."\r\n";
+ // Add authentication only if username is provided and not empty
+ if(!empty($this->options['username'])){
+ $request .= 'Authorization: Basic '.base64_encode($this->options['username'].':'.$this->options['password'])."\r\n";
+ }
+ $request .= 'Accept: application/json'."\r\n";
+ // Set keep-alive header, which helps to keep to connection
+ // initilization costs low, especially when the database server is not
+ // available in the locale net.
+ $request .= 'Connection: ' . ( $this->options['alive'] ? 'Keep-Alive' : 'Close' ) . "\r\n";
+ // Add request data and related headers if needed
+ // otherwise add closing mark of the request header section.
+ if($data) {
+ if(is_array($data)){
+ $data = json_encode($data);
+ }
+ $request .= 'Content-Length: '.strlen($data)."\r\n";
+ $request .= 'Content-Type: application/json'."\r\n\r\n";
+ $request .= $data."\r\n";
+ } else {
+ $request .= "\r\n";
+ }
+// echo $request."\n\n";
+ fwrite($this->sock, $request);
+// $response = '';
+// while(!feof($this->sock)) {
+// $response .= fgets($this->sock);
+// }
+
+ $raw = '';
+ $headers = '';
+ $body = '';
+ // Extract HTTP response headers
+ while ( ( ( $line = fgets( $this->sock ) ) !== false ) &&
+ ( ( $line = rtrim( $line ) ) !== '' ) ){
+ // Extract HTTP version and response code
+ // as well as other headers
+ if ( preg_match( '(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $line, $matches ) ) {
+ $headers['version'] = $matches['version'];
+ $headers['status'] = (int) $matches['status'];
+ } else {
+ list( $key, $value ) = explode( ':', $line, 2 );
+ $headers[strtolower( $key )] = ltrim( $value );
+ }
+ }
+ // Extract HTTP response body
+ $body = '';
+ if ( !isset( $headers['transfer-encoding'] ) ||
+ ( $headers['transfer-encoding'] !== 'chunked' ) ) {
+ // HTTP 1.1 supports chunked transfer encoding, if the according
+ // header is not set, just read the specified amount of bytes.
+ $bytesToRead = (int) ( isset( $headers['content-length'] ) ? $headers['content-length'] : 0 );
+ // Read body only as specified by chunk sizes, everything else
+ // are just footnotes, which are not relevant for us.
+ if($this->options['alive']||$bytesToRead){
+ while ( $bytesToRead > 0 ) {
+ $body .= $read = fgets( $this->sock, $bytesToRead + 1 );
+ $bytesToRead -= strlen( $read );
+ }
+ }else{
+ while ( ( ( $line = fgets( $this->sock, 1024 ) ) !== false ) ){
+ $body .= $line;
+ }
+ }
+ } else {
+ // When transfer-encoding=chunked has been specified in the
+ // response headers, read all chunks and sum them up to the body,
+ // until the server has finished. Ignore all additional HTTP
+ // options after that.
+ while ($chunk_length = hexdec(fgets($this->sock))){
+ $responseContentChunk = '';
+ $read_length = 0;
+ while ($read_length < $chunk_length){
+ $responseContentChunk .= fread($this->sock, $chunk_length - $read_length);
+ $read_length = strlen($responseContentChunk);
+ }
+ $body.= $responseContentChunk;
+ fgets($this->sock);
+ }
+ }
+ // Reset the connection if the server asks for it.
+ if ( isset($headers['connection']) && $headers['connection'] !== 'Keep-Alive' ) {
+ $this->disconnect();
+ }
+ //$this->disconnect();
+// echo '------------------------'."\n";
+// print_r($headers);
+// echo '------------------------'."\n";
+// print_r($body);
+// echo '------------------------'."\n";
+ return new PopHbaseResponse($headers,$body,$raw);
+ }
+
+}
16 src/PopHbaseException.php
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Exception class for HBase related exceptions.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseException extends Exception{
+
+}
100 src/PopHbaseIterator.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Abstract HBase iterator implementing the PHP Iteractor and Countable interfaces.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+abstract class PopHbaseIterator implements Countable, Iterator{
+
+
+ //public $data = array();
+
+ /**
+ * Implement the "current" method of the PHP native Iterator interface.
+ *
+ * @return mixed Returns current value.
+ */
+ public function current(){
+ $this->load();
+ return current($this->__data['data']);
+ }
+
+ /**
+ * Return the key of the current element.
+ *
+ * Implement the "key" method of the PHP native Iterator interface.
+ *
+ * @return mixed Returns scalar on success, integer 0 on failure.
+ */
+ public function key(){
+ $this->load();
+ return key($this->__data['data']);
+ }
+
+ /**
+ * Move forward to next element.
+ *
+ * Implement the "next" method of the PHP native Iterator interface.
+ *
+ * @return mixed Returns next value.
+ */
+ public function next(){
+ $this->load();
+ return next($this->__data['data']);
+ }
+
+ /**
+ * Move backward to previous element.
+ *
+ * Note, this method is not part the PHP navite Iterator interface.
+ *
+ * @return mixed Returns previous value.
+ */
+ public function prev(){
+ $this->load();
+ return prev($this->__data['data']);
+ }
+
+ /**
+ * Rewind the Iterator to the first element.
+ *
+ * Implement the "rewind" method of the PHP native Iterator interface.
+ *
+ * @return mixed The value of the first array element, or FALSE if the array is empty.
+ */
+ public function rewind(){
+ $this->load();
+ return reset($this->__data['data']);
+ }
+
+ /**
+ * Checks if current position is valid.
+ *
+ * Implement the "valid" method of the PHP native Iterator interface.
+ *
+ * @return boolean Wether the iterated array is in a valid state or not.
+ */
+ public function valid(){
+ return (bool) $this->current();
+ }
+
+ /**
+ * Count the number of stored elements.
+ *
+ * Implement the "count" method of the PHP native Countable interface.
+ *
+ * return integer Number of stored elements.
+ */
+ public function count(){
+ $this->load();
+ return count($this->__data['data']);
+ }
+
+}
43 src/PopHbaseRequest.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Wrap an Hbase request
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseRequest{
+
+ public $hbase;
+
+ /**
+ * Request constructor.
+ *
+ * @param PopHbaseConnection required $connection
+ */
+ function __construct(PopHbase $hbase){
+ $this->hbase = $hbase;
+ }
+
+ public function delete($url){
+ return $this->hbase->connection->execute('DELETE',$url);
+ }
+
+ public function get($url){
+ return $this->hbase->connection->execute('GET',$url);
+ }
+
+ public function post($url,$data){
+ return $this->hbase->connection->execute('POST',$url,$data);
+ }
+
+ public function put($url,$data=null){
+ return $this->hbase->connection->execute('PUT',$url,$data);
+ }
+
+}
55 src/PopHbaseResponse.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Wrap a HBase response
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseResponse{
+
+ public function __construct($headers,$body,$raw=false) {
+ $this->headers = $headers;
+ $this->body = $raw?$body:json_decode($body,true);
+ $this->raw = $raw;
+// preg_match('/^(\d{3})/',trim($this->headers['status']),$matches);
+// echo $this->headers['status'].' - '.$matches[1]."\n";
+// $status = $matches[1];
+// switch($status){
+// case '500':
+// throw new PopHbaseException(constant('PurHTTP::CODE_'.$status));
+// }
+ }
+
+// public function __get($property){
+// switch($property){
+// case 'body':
+// return $this->getBody();
+// }
+// }
+
+ public function __call($method,$args) {
+ switch($method){
+ case 'body':
+ return call_user_func_array(array($this,'getBody'),$args);
+ }
+ }
+
+ public function getRaw() {
+ return $this->raw;
+ }
+
+ function getHeaders() {
+ return $this->headers;
+ }
+
+ function getBody() {
+ return $this->body;
+ }
+
+}
31 src/PopHbaseTable.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Wrap an Hbase table
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseTable{
+
+ public $hbase;
+ public $name;
+
+ public function __construct(PopHbase $hbase,$name){
+ $this->hbase = $hbase;
+ $this->name = $name;
+ }
+
+ public function delete(){
+ $body = $this->hbase->request->delete('/'.$this->name)->body;
+// $this->hbase->tables->reload();
+// unset($this->hbase->tables->{$this->name});
+ return $this;
+ }
+
+}
156 src/PopHbaseTables.php
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_hbase/license.html
+ */
+
+/**
+ * Hold a list of tables.
+ *
+ * @author David Worms info(at)adaltas.com
+ */
+class PopHbaseTables extends PopHbaseIterator{
+
+ public $hbase;
+
+ public function __construct(PopHbase $hbase){
+ $this->hbase = $hbase;
+ $this->__data = array();
+ }
+
+// public function __unset($property){
+// unset($this->__data['data'][$property]);
+// echo '__unset__ '.count($this->__data['data']).' '.$this->key()."\n";
+// }
+
+ public function add($table){
+ $body = $this->hbase->request->put('/'.$table)->body;
+ $this->reload();
+ return $this;
+ }
+
+ public function delete($table){
+ $body = $this->hbase->request->delete($table.'/schema');
+ $this->reload();
+ return $this;
+ }
+
+ public function reload(){
+ echo 'reload'."\n";
+ unset($this->__data['data']);
+ }
+
+ public function load(){
+ if(isset($this->__data['data'])){
+ return $this;
+ }
+ $tables = $this->hbase->request->get('/')->body;
+ $this->__data['data'] = array();
+ if(is_null($tables)){ // No table
+ return $this;
+ }
+ foreach($tables['table'] as $table){
+ $this->__data['data'][$table['name']] = new PopHbaseTable($this->hbase,$table['name']);
+ }
+ return $this;
+ }
+
+ /**
+ * Create a new table and associated column families schema.
+ *
+ * The first argument is expected to be the column name while the following
+ * arguments describle column families.
+ *
+ * Usage
+ * $hbase->tables->add(
+ * 'table_name',
+ * 'column_1',
+ * array('name'=>'column_2'),
+ * array('NAME'=>'column_3'),
+ * array('@NAME'=>'column_4',...);
+ */
+ public function create($table){
+ $args = func_get_args();
+ if(count($args)===0){
+ throw new InvalidArgumentException('Missing table schema definition');
+ }
+ $table = array_shift($args);
+ switch(gettype($table)){
+ case 'string':
+ $schema = array('name' => $table);
+ break;
+ case 'array':
+ // name is required
+ // other keys include IS_META and IS_ROOT
+ $schema = array();
+ foreach($table as $k=>$v){
+ if(substr($k,0,1)!='@'){
+ $k = substr($k,1);
+ }
+ if($k=='NAME'){
+ $k = 'name';
+ }else{
+ $k = strtoupper($k);
+ }
+ $schema[$k] = $v;
+ }
+ if(!isset($schema['name'])){
+ throw new InvalidArgumentException('Table schema definition not correctly defined "'.PurLang::toString($table).'"');
+ }
+ break;
+ default:
+ throw new InvalidArgumentException('Table schema definition not correctly defined: "'.PurLang::toString($table).'"');
+ }
+ $schema['ColumnSchema'] = array();
+ foreach($args as $arg){
+ switch(gettype($arg)){
+ case 'string':
+ $schema['ColumnSchema'][] = array('name' => $arg);
+ break;
+ case 'array':
+ // name is required
+ // other keys include BLOCKSIZE, BLOOMFILTER,
+ // BLOCKCACHE, COMPRESSION, LENGTH, VERSIONS,
+ // TTL, and IN_MEMORY
+ $columnSchema = array();
+ foreach($arg as $k=>$v){
+ if(substr($k,0,1)=='@'){
+ $k = substr($k,1);
+ }
+ if($k=='NAME'){
+ $k = 'name';
+ }else{
+ $k = strtoupper($k);
+ }
+ $columnSchema[$k] = $v;
+ }
+ if(!isset($columnSchema['name'])){
+ throw new InvalidArgumentException('Column schema definition not correctly defined "'.PurLang::toString($table).'"');
+ }
+ $schema['ColumnSchema'][] = $columnSchema;
+ break;
+ default:
+ throw new InvalidArgumentException('Column schema definition not correctly defined: "'.PurLang::toString($table).'"');
+ }
+ }
+ //echo json_encode($schema)."\n";
+ echo '----------------------------- start'."\n";
+ $this->hbase->request->put($schema['name'].'/schema',$schema);
+ if($this->hbase->options['alive']){
+ echo '-- 1 '."\n";
+ // For some reason, connection need to be reset
+ // for count to return correct number of tables
+// sleep(2);
+ //$this->hbase->connection->disconnect();
+// $this->hbase->connection->disconnect();
+// $this->hbase->connection->disconnect();
+ echo '-- 2 '."\n";
+ }
+// $this->hbase->connection->disconnect();
+ echo '----------------------------- stop'."\n";
+ $this->reload();
+ }
+
+}
17 src/pop_hbase.inc.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * This code is provided as a conveniency if you want to use this project
+ * outside of Pop. In a Pop environment, you won't need to include classes
+ * since it would be handled by Pop Loader.
+ */
+
+require(dirname(__File__).'/PopHbase.php');
+require(dirname(__File__).'/PopHbaseConnection.php');
+require(dirname(__File__).'/PopHbaseConnectionSock.php');
+require(dirname(__File__).'/PopHbaseException.php');
+require(dirname(__File__).'/PopHbaseIterator.php');
+require(dirname(__File__).'/PopHbaseRequest.php');
+require(dirname(__File__).'/PopHbaseResponse.php');
+require(dirname(__File__).'/PopHbaseTable.php');
+require(dirname(__File__).'/PopHbaseTables.php');
59 tests/PopHbaseTestCase.php
@@ -0,0 +1,59 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/porte/license.html
+ */
+
+/**
+ * BasicTest
+ *
+ * @author David Worms info(at)adaltas.com
+ * @copyright 2008-2009 Adaltas
+ */
+
+require_once 'PHPUnit/Framework.php';
+
+error_reporting(E_ALL | E_STRICT);
+require dirname(__FILE__).'/../src/pop_hbase.inc.php';
+require(dirname(__File__).'/../../pur/src/pur.inc.php');
+
+abstract class PopHbaseTestCase extends PHPUnit_Framework_TestCase{
+ public function __get($key){
+ switch($key){
+ case 'config':
+ return $this->config();
+ break;
+ case 'hbase':
+ return $this->hbase();
+ }
+ }
+ public function config(){
+ $config = dirname(__FILE__).'/user.properties';
+ if(file_exists($config)){
+ $config = PurProperties::stringToArray(PurFile::read($config));
+ }else{
+ echo 'First running the test?'.PHP_EOL;
+ echo 'A new file user.properties was created in tests directory.'.PHP_EOL;
+ echo 'Modify it to feet your HBase installation, then the tests again.'.PHP_EOL;
+ exit;
+ }
+ return $config;
+ }
+ public function hbase(){
+ if(isset($this->hbase)) return $this->hbase;
+ return $this->hbase = new PopHbase($this->config);
+ }
+ public function setUp(){
+// foreach($this->hbase->tables as $table){
+// if(substr($table->name,0,9)=='pop_hbase'){
+// $table->delete();
+// }
+// }
+// $this->hbase->tables->reload();
+ }
+ public function tearDown(){
+ }
+}
+?>
26 tests/connection/ConnectionConnectTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class ConnectionConnectTest extends PopHbaseTestCase{
+ public function testReturn(){
+ $connection = new PopHbaseConnectionSock($this->config);
+ $this->assertSame($connection,$connection->connect());
+ $version = $connection->execute('get','version')->getBody();
+ $this->assertTrue(is_array($version));
+ $this->assertSame(array('Stargate','Server','OS','JVM','Jersey'),array_keys($version));
+
+ }
+}
26 tests/connection/ConnectionDisconnectTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class ConnectionDisconnectTest extends PopHbaseTestCase{
+ public function testReturn(){
+ $connection = new PopHbaseConnectionSock($this->config);
+ // When not connected
+ $this->assertSame($connection,$connection->disconnect());
+ // When connected
+ $connection->connect();
+ $this->assertSame($connection,$connection->disconnect());
+ }
+}
23 tests/hbase/HbaseGetStatusClusterTest.php
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class HbaseGetStatusClusterTest extends PopHbaseTestCase{
+ public function testReturn(){
+ $hbase = new PopHbase($this->config);
+ $statusCluster = $hbase->getStatusCluster();
+ $this->assertSame(array('requests','regions','averageLoad','DeadNodes','LiveNodes'),array_keys($statusCluster));
+ }
+}
23 tests/hbase/HbaseGetVersionClusterTest.php
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class HbaseGetVersionClusterTest extends PopHbaseTestCase{
+ public function testReturn(){
+ $hbase = new PopHbase($this->config);
+ $versionCluster = $hbase->getVersionCluster();
+ $this->assertTrue((boolean)preg_match('/^\d[\d\.]+/',$versionCluster));
+ }
+}
23 tests/hbase/HbaseGetVersionTest.php
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class HbaseGetVersionTest extends PopHbaseTestCase{
+ public function testReturn(){
+ $hbase = new PopHbase($this->config);
+ $version = $hbase->getVersion();
+ $this->assertSame(array('Stargate','Server','OS','JVM','Jersey'),array_keys($version));
+ }
+}
29 tests/tables/TablesCountableTest.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class TablesCountableTest extends PopHbaseTestCase{
+ public function testCount(){
+ $hbase = $this->hbase;
+ // Test with no database
+ $tables = $hbase->tables();
+ $this->assertSame(0,count($tables));
+ // Test with one database
+// $hbase->tables->create('pop_hbase');
+// $this->assertSame(1,count($tables));
+// $this->assertTrue($tables->current() instanceof PopHbaseTable);
+// $hbase->tables->delete('pop_hbase');
+ }
+}
30 tests/tables/TablesCreateTest.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas & EDF. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class TablesCreateTest extends PopHbaseTestCase{
+ public function testCount(){
+ $hbase = $this->hbase;
+ // Test with no database
+ $tables = $hbase->tables();
+ $this->assertSame(0,count($tables));
+ // Test with one database
+ $hbase->tables->create('pop_hbase','my_column');
+ //$hbase->connection->disconnect();
+ $this->assertSame(1,count($tables));
+ $this->assertTrue($tables->current() instanceof PopHbaseTable);
+ $hbase->tables->delete('pop_hbase');
+ }
+}
28 tests/tables/TablesDeleteTest.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the add method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class TablesDeleteTest extends PopHbaseTestCase{
+ public function testCount(){
+ $hbase = $this->hbase;
+ // Test with no database
+ $tables = $hbase->tables();
+ $this->assertSame(1,count($tables));
+ // Test with one database
+ $hbase->tables->delete('pop_hbase','my_column');
+ $this->assertSame(0,count($tables));
+ $this->assertFalse($tables->current());
+ }
+}
9 tests/user.properties
@@ -0,0 +1,9 @@
+
+# Host default to "localhost"
+host = localhost
+
+# Port default to "8080"
+port = 8080
+
+# Http keep alive connection default to false
+alive = 1
9 tests/user.properties.sample
@@ -0,0 +1,9 @@
+
+# Host default to "localhost"
+host = localhost
+
+# Port default to "8080"
+port = 8080
+
+# Http keep alive connection default to false
+alive =

0 comments on commit 1ebe4a8

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