Skip to content

Commit

Permalink
Updated test to work with the new thrift and cassandra versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kallaspriit committed Dec 4, 2011
1 parent 65dd94d commit a919fcd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
28 changes: 14 additions & 14 deletions Cassandra.php
Expand Up @@ -34,7 +34,7 @@
*/

// set the globals that the thrift library uses
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/thrift/';
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/thrift';
define('THRIFT_PATH', $GLOBALS['THRIFT_ROOT']);

// require thrift packages
Expand Down Expand Up @@ -108,7 +108,7 @@ class CassandraConnection {
/**
* The low-level cassandra client.
*
* @var CassandraClient
* @var cassandra_CassandraClient
*/
protected $client;

Expand Down Expand Up @@ -159,7 +159,7 @@ public function __construct(
$this->isOpen = true;

$this->protocol = new TBinaryProtocolAccelerated($this->transport);
$this->client = new CassandraClient($this->protocol);
$this->client = new cassandra_CassandraClient($this->protocol);
}

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ public function isOpen() {
/**
* Returns the low-level Cassandra client used by the wrapper.
*
* @return CassandraClient
* @return cassandra_CassandraClient
*/
public function getClient() {
if (!$this->isOpen) {
Expand Down Expand Up @@ -631,7 +631,7 @@ class Cassandra {
* what else is reading and writing, it's possible that they could briefly
* give conflicting answers.
*/
const CONSISTENCY_ONE = cassandra_ConsistencyLevel::ONE;
const CONSISTENCY_ONE = ConsistencyLevel::ONE;

/**
* Majority of the nodes holding the data must reply.
Expand All @@ -641,7 +641,7 @@ class Cassandra {
* factor of atleast three for this to work differently from all and should
* use odd number for replication factor.
*/
const CONSISTENCY_QUORUM = cassandra_ConsistencyLevel::QUORUM;
const CONSISTENCY_QUORUM = ConsistencyLevel::QUORUM;

/**
* Only meaningful for writes and means as soon as a write is received by
Expand All @@ -654,7 +654,7 @@ class Cassandra {
* you write to node 5, either 6, 7, or 8 have to return success before
* node 5 returns success.
*/
const CONSISTENCY_ANY = cassandra_ConsistencyLevel::ANY;
const CONSISTENCY_ANY = ConsistencyLevel::ANY;

/**
* Returns success only if all the nodes holding the data respond.
Expand All @@ -664,7 +664,7 @@ class Cassandra {
* is down, it's not possible to read or write the data as the requirement
* can not be fulfilled.
*/
const CONSISTENCY_ALL = cassandra_ConsistencyLevel::ALL;
const CONSISTENCY_ALL = ConsistencyLevel::ALL;

/**
* Standard column type.
Expand Down Expand Up @@ -723,27 +723,27 @@ class Cassandra {
/**
* Equality comparator used in where queries.
*/
const OP_EQ = cassandra_IndexOperator::EQ;
const OP_EQ = IndexOperator::EQ;

/**
* Strict less-than comparator.
*/
const OP_LT = cassandra_IndexOperator::LT;
const OP_LT = IndexOperator::LT;

/**
* Strict greater-than comparator.
*/
const OP_GT = cassandra_IndexOperator::GT;
const OP_GT = IndexOperator::GT;

/**
* Less-than-equals comparator.
*/
const OP_LTE = cassandra_IndexOperator::LTE;
const OP_LTE = IndexOperator::LTE;

/**
* Greater-than-equals comparator.
*/
const OP_GTE = cassandra_IndexOperator::GTE;
const OP_GTE = IndexOperator::GTE;

/**
* Default simple placement strategy not taking network topology into
Expand Down Expand Up @@ -898,7 +898,7 @@ public function closeConnections() {
/**
* Return the low-level thrift client.
*
* @return CassandraClient
* @return cassandra_CassandraClient
*/
public function getClient() {
return $this->cluster->getConnection()->getClient();
Expand Down
9 changes: 7 additions & 2 deletions README
Expand Up @@ -30,6 +30,9 @@ for prettier code.

<?php

// show all the errors
error_reporting(E_ALL);

// the only file that needs including into your project
require_once 'Cassandra.php';

Expand Down Expand Up @@ -122,11 +125,11 @@ $cassandra->createSuperColumnFamily(
// lets fetch and display the schema of created keyspace
$schema = $cassandra->getKeyspaceSchema('CassandraExample');
echo 'Schema: <pre>'.print_r($schema, true).'</pre><hr/>';

/*
// should we need to, we can access the low-level client directly
$version = $cassandra->getConnection()->getClient()->describe_version();
echo 'Version directly: <pre>'.print_r($version, true).'</pre><hr/>';

*/
// if implemented, use the wrapped methods as these are smarter - can retry etc
$version = $cassandra->getVersion();
echo 'Version through wrapper: <pre>'.print_r($version, true).'</pre><hr/>';
Expand Down Expand Up @@ -223,13 +226,15 @@ echo 'Users at age 24: <pre>'.print_r($aged24->getAll(), true).'</pre><hr/>';
$chuckAndJohn = $cassandra->cf('user')->getMultiple(array('chuck', 'john'));
echo 'Users "chuck" and "john": <pre>'.print_r($chuckAndJohn, true).'</pre><hr/>';

/* Uncomment this when using order preserving partitioner
// we can fetch a range of keys but this is predictable only if using an
// order preserving partitioner, Cassandra defaults to random one
// again as there may be more results than it's reasonable to fetch in a single
// query, an iterator is returned that can make several smaller range queries
// as the data is iterated
$usersAZ = $cassandra->cf('user')->getKeyRange('a', 'z');
echo 'Users with keys in range a-z: <pre>'.print_r($usersAZ->getAll(), true).'</pre><hr/>';
*/

// find the number of columns a key has, we could also request for ranges
$chuckColumnCount = $cassandra->cf('user')->getColumnCount('chuck');
Expand Down
9 changes: 7 additions & 2 deletions example.php
@@ -1,5 +1,8 @@
<?php

// show all the errors
error_reporting(E_ALL);

// the only file that needs including into your project
require_once 'Cassandra.php';

Expand Down Expand Up @@ -92,11 +95,11 @@
// lets fetch and display the schema of created keyspace
$schema = $cassandra->getKeyspaceSchema('CassandraExample');
echo 'Schema: <pre>'.print_r($schema, true).'</pre><hr/>';

/*
// should we need to, we can access the low-level client directly
$version = $cassandra->getConnection()->getClient()->describe_version();
echo 'Version directly: <pre>'.print_r($version, true).'</pre><hr/>';

*/
// if implemented, use the wrapped methods as these are smarter - can retry etc
$version = $cassandra->getVersion();
echo 'Version through wrapper: <pre>'.print_r($version, true).'</pre><hr/>';
Expand Down Expand Up @@ -193,13 +196,15 @@
$chuckAndJohn = $cassandra->cf('user')->getMultiple(array('chuck', 'john'));
echo 'Users "chuck" and "john": <pre>'.print_r($chuckAndJohn, true).'</pre><hr/>';

/* Uncomment this when using order preserving partitioner
// we can fetch a range of keys but this is predictable only if using an
// order preserving partitioner, Cassandra defaults to random one
// again as there may be more results than it's reasonable to fetch in a single
// query, an iterator is returned that can make several smaller range queries
// as the data is iterated
$usersAZ = $cassandra->cf('user')->getKeyRange('a', 'z');
echo 'Users with keys in range a-z: <pre>'.print_r($usersAZ->getAll(), true).'</pre><hr/>';
*/

// find the number of columns a key has, we could also request for ranges
$chuckColumnCount = $cassandra->cf('user')->getColumnCount('chuck');
Expand Down
2 changes: 1 addition & 1 deletion test/CassandraTest.php
Expand Up @@ -144,7 +144,7 @@ public function testGetClientThrowsExceptionIfConnectionClosed() {
$connection = $this->cassandra->getConnection();
$client = $connection->getClient();

if (!($client instanceof CassandraClient)) {
if (!($client instanceof cassandra_CassandraClient)) {
$this->fail('Instance of CassandraClient expected');
}

Expand Down

0 comments on commit a919fcd

Please sign in to comment.