Skip to content
This repository
Browse code

Updated test to work with the new thrift and cassandra versions

  • Loading branch information...
commit a919fcdce6344d3a7b91818a4ba9143cba9e09a6 1 parent 65dd94d
Priit Kallas authored
28 Cassandra.php
@@ -34,7 +34,7 @@
34 34 */
35 35
36 36 // set the globals that the thrift library uses
37   -$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/thrift/';
  37 +$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/thrift';
38 38 define('THRIFT_PATH', $GLOBALS['THRIFT_ROOT']);
39 39
40 40 // require thrift packages
@@ -108,7 +108,7 @@ class CassandraConnection {
108 108 /**
109 109 * The low-level cassandra client.
110 110 *
111   - * @var CassandraClient
  111 + * @var cassandra_CassandraClient
112 112 */
113 113 protected $client;
114 114
@@ -159,7 +159,7 @@ public function __construct(
159 159 $this->isOpen = true;
160 160
161 161 $this->protocol = new TBinaryProtocolAccelerated($this->transport);
162   - $this->client = new CassandraClient($this->protocol);
  162 + $this->client = new cassandra_CassandraClient($this->protocol);
163 163 }
164 164
165 165 /**
@@ -196,7 +196,7 @@ public function isOpen() {
196 196 /**
197 197 * Returns the low-level Cassandra client used by the wrapper.
198 198 *
199   - * @return CassandraClient
  199 + * @return cassandra_CassandraClient
200 200 */
201 201 public function getClient() {
202 202 if (!$this->isOpen) {
@@ -631,7 +631,7 @@ class Cassandra {
631 631 * what else is reading and writing, it's possible that they could briefly
632 632 * give conflicting answers.
633 633 */
634   - const CONSISTENCY_ONE = cassandra_ConsistencyLevel::ONE;
  634 + const CONSISTENCY_ONE = ConsistencyLevel::ONE;
635 635
636 636 /**
637 637 * Majority of the nodes holding the data must reply.
@@ -641,7 +641,7 @@ class Cassandra {
641 641 * factor of atleast three for this to work differently from all and should
642 642 * use odd number for replication factor.
643 643 */
644   - const CONSISTENCY_QUORUM = cassandra_ConsistencyLevel::QUORUM;
  644 + const CONSISTENCY_QUORUM = ConsistencyLevel::QUORUM;
645 645
646 646 /**
647 647 * Only meaningful for writes and means as soon as a write is received by
@@ -654,7 +654,7 @@ class Cassandra {
654 654 * you write to node 5, either 6, 7, or 8 have to return success before
655 655 * node 5 returns success.
656 656 */
657   - const CONSISTENCY_ANY = cassandra_ConsistencyLevel::ANY;
  657 + const CONSISTENCY_ANY = ConsistencyLevel::ANY;
658 658
659 659 /**
660 660 * Returns success only if all the nodes holding the data respond.
@@ -664,7 +664,7 @@ class Cassandra {
664 664 * is down, it's not possible to read or write the data as the requirement
665 665 * can not be fulfilled.
666 666 */
667   - const CONSISTENCY_ALL = cassandra_ConsistencyLevel::ALL;
  667 + const CONSISTENCY_ALL = ConsistencyLevel::ALL;
668 668
669 669 /**
670 670 * Standard column type.
@@ -723,27 +723,27 @@ class Cassandra {
723 723 /**
724 724 * Equality comparator used in where queries.
725 725 */
726   - const OP_EQ = cassandra_IndexOperator::EQ;
  726 + const OP_EQ = IndexOperator::EQ;
727 727
728 728 /**
729 729 * Strict less-than comparator.
730 730 */
731   - const OP_LT = cassandra_IndexOperator::LT;
  731 + const OP_LT = IndexOperator::LT;
732 732
733 733 /**
734 734 * Strict greater-than comparator.
735 735 */
736   - const OP_GT = cassandra_IndexOperator::GT;
  736 + const OP_GT = IndexOperator::GT;
737 737
738 738 /**
739 739 * Less-than-equals comparator.
740 740 */
741   - const OP_LTE = cassandra_IndexOperator::LTE;
  741 + const OP_LTE = IndexOperator::LTE;
742 742
743 743 /**
744 744 * Greater-than-equals comparator.
745 745 */
746   - const OP_GTE = cassandra_IndexOperator::GTE;
  746 + const OP_GTE = IndexOperator::GTE;
747 747
748 748 /**
749 749 * Default simple placement strategy not taking network topology into
@@ -898,7 +898,7 @@ public function closeConnections() {
898 898 /**
899 899 * Return the low-level thrift client.
900 900 *
901   - * @return CassandraClient
  901 + * @return cassandra_CassandraClient
902 902 */
903 903 public function getClient() {
904 904 return $this->cluster->getConnection()->getClient();
9 README
@@ -30,6 +30,9 @@ for prettier code.
30 30
31 31 <?php
32 32
  33 +// show all the errors
  34 +error_reporting(E_ALL);
  35 +
33 36 // the only file that needs including into your project
34 37 require_once 'Cassandra.php';
35 38
@@ -122,11 +125,11 @@ $cassandra->createSuperColumnFamily(
122 125 // lets fetch and display the schema of created keyspace
123 126 $schema = $cassandra->getKeyspaceSchema('CassandraExample');
124 127 echo 'Schema: <pre>'.print_r($schema, true).'</pre><hr/>';
125   -
  128 +/*
126 129 // should we need to, we can access the low-level client directly
127 130 $version = $cassandra->getConnection()->getClient()->describe_version();
128 131 echo 'Version directly: <pre>'.print_r($version, true).'</pre><hr/>';
129   -
  132 +*/
130 133 // if implemented, use the wrapped methods as these are smarter - can retry etc
131 134 $version = $cassandra->getVersion();
132 135 echo 'Version through wrapper: <pre>'.print_r($version, true).'</pre><hr/>';
@@ -223,6 +226,7 @@ echo 'Users at age 24: <pre>'.print_r($aged24->getAll(), true).'</pre><hr/>';
223 226 $chuckAndJohn = $cassandra->cf('user')->getMultiple(array('chuck', 'john'));
224 227 echo 'Users "chuck" and "john": <pre>'.print_r($chuckAndJohn, true).'</pre><hr/>';
225 228
  229 +/* Uncomment this when using order preserving partitioner
226 230 // we can fetch a range of keys but this is predictable only if using an
227 231 // order preserving partitioner, Cassandra defaults to random one
228 232 // again as there may be more results than it's reasonable to fetch in a single
@@ -230,6 +234,7 @@ echo 'Users "chuck" and "john": <pre>'.print_r($chuckAndJohn, true).'</pre><hr/>
230 234 // as the data is iterated
231 235 $usersAZ = $cassandra->cf('user')->getKeyRange('a', 'z');
232 236 echo 'Users with keys in range a-z: <pre>'.print_r($usersAZ->getAll(), true).'</pre><hr/>';
  237 +*/
233 238
234 239 // find the number of columns a key has, we could also request for ranges
235 240 $chuckColumnCount = $cassandra->cf('user')->getColumnCount('chuck');
9 example.php
... ... @@ -1,5 +1,8 @@
1 1 <?php
2 2
  3 +// show all the errors
  4 +error_reporting(E_ALL);
  5 +
3 6 // the only file that needs including into your project
4 7 require_once 'Cassandra.php';
5 8
@@ -92,11 +95,11 @@
92 95 // lets fetch and display the schema of created keyspace
93 96 $schema = $cassandra->getKeyspaceSchema('CassandraExample');
94 97 echo 'Schema: <pre>'.print_r($schema, true).'</pre><hr/>';
95   -
  98 +/*
96 99 // should we need to, we can access the low-level client directly
97 100 $version = $cassandra->getConnection()->getClient()->describe_version();
98 101 echo 'Version directly: <pre>'.print_r($version, true).'</pre><hr/>';
99   -
  102 +*/
100 103 // if implemented, use the wrapped methods as these are smarter - can retry etc
101 104 $version = $cassandra->getVersion();
102 105 echo 'Version through wrapper: <pre>'.print_r($version, true).'</pre><hr/>';
@@ -193,6 +196,7 @@
193 196 $chuckAndJohn = $cassandra->cf('user')->getMultiple(array('chuck', 'john'));
194 197 echo 'Users "chuck" and "john": <pre>'.print_r($chuckAndJohn, true).'</pre><hr/>';
195 198
  199 +/* Uncomment this when using order preserving partitioner
196 200 // we can fetch a range of keys but this is predictable only if using an
197 201 // order preserving partitioner, Cassandra defaults to random one
198 202 // again as there may be more results than it's reasonable to fetch in a single
@@ -200,6 +204,7 @@
200 204 // as the data is iterated
201 205 $usersAZ = $cassandra->cf('user')->getKeyRange('a', 'z');
202 206 echo 'Users with keys in range a-z: <pre>'.print_r($usersAZ->getAll(), true).'</pre><hr/>';
  207 +*/
203 208
204 209 // find the number of columns a key has, we could also request for ranges
205 210 $chuckColumnCount = $cassandra->cf('user')->getColumnCount('chuck');
2  test/CassandraTest.php
@@ -144,7 +144,7 @@ public function testGetClientThrowsExceptionIfConnectionClosed() {
144 144 $connection = $this->cassandra->getConnection();
145 145 $client = $connection->getClient();
146 146
147   - if (!($client instanceof CassandraClient)) {
  147 + if (!($client instanceof cassandra_CassandraClient)) {
148 148 $this->fail('Instance of CassandraClient expected');
149 149 }
150 150

0 comments on commit a919fcd

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