Skip to content

Commit 8e76f7d

Browse files
committed
Merge pull request #52 from datastax/php-22-test
[PHP-22] Schema Metadata Feature and Miscellaneous Windows Fixes
2 parents b60c452 + 3f8f4d1 commit 8e76f7d

File tree

5 files changed

+267
-8
lines changed

5 files changed

+267
-8
lines changed

behat.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ default:
33
pretty: true
44
suites:
55
default:
6+
filters:
7+
68
contexts:
79
- FeatureContext:
810
cluster_name: php-driver-2.1-cluster
9-
cassandra_version: 2.1.8
11+
cassandra_version: 2.1.9
1012

1113
cassandra-version-2.0:
1214
formatters:
1315
pretty: true
1416
suites:
1517
default:
16-
filters: "[email protected]"
18+
filters:
19+
1720
contexts:
1821
- FeatureContext:
1922
cluster_name: php-driver-2.0-cluster
@@ -25,7 +28,7 @@ cassandra-version-1.2:
2528
suites:
2629
default:
2730
filters:
28-
31+
2932
contexts:
3033
- FeatureContext:
3134
cluster_name: php-driver-1.2-cluster

ext/util/types.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,13 @@ next_token(const char* str, size_t len,
258258
const char** str_out, size_t* len_out)
259259
{
260260
enum token_type type;
261+
unsigned int i = 0;
262+
char c = str[i];
261263

262264
if (len == 0) {
263265
return TOKEN_END;
264266
}
265267

266-
unsigned int i = 0;
267-
char c = str[i];
268-
269268
if (isalpha(c)) {
270269
type = TOKEN_NAME;
271270
while (i < len) {

ext/vc_build.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,13 @@ IF !ENABLE_BUILD_PACKAGES! EQU !FALSE! (
752752
ECHO done.
753753
IF EXIST bin\behat.bat (
754754
RENAME bin\behat.bat behat.bak
755-
ECHO @ECHO %%PATH%% ^| FIND /C /I ^"!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!^"^>NULL ^|^| @SET ^"PATH=!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!;%%PATH%%^" > bin\behat.bat
755+
ECHO @ECHO %%PATH%% ^| FIND /C /I ^"!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!^"^>NUL ^|^| @SET ^"PATH=!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!;%%PATH%%^" > bin\behat.bat
756756
TYPE bin\behat.bak >> bin\behat.bat
757757
ERASE bin\behat.bak
758758
)
759759
IF EXIST bin\phpunit.bat (
760760
RENAME bin\phpunit.bat phpunit.bak
761-
ECHO @ECHO %%PATH%% ^| FIND /C /I ^"!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!^"^>NULL ^|^| @SET ^"PATH=!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!;%%PATH%%^" > bin\phpunit.bat
761+
ECHO @ECHO %%PATH%% ^| FIND /C /I ^"!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!^"^>NUL ^|^| @SET ^"PATH=!ABSOLUTE_DRIVER_LIBRARY_DIRECTORY!;%%PATH%%^" > bin\phpunit.bat
762762
TYPE bin\phpunit.bak >> bin\phpunit.bat
763763
ERASE bin\phpunit.bak
764764
)

features/bootstrap/FeatureContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ private function startWebServer()
305305
{
306306
$this->webServerURL = 'http://127.0.0.1:10000';
307307
$command = sprintf('exec %s -S "%s"', $this->phpBin, '127.0.0.1:10000');
308+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
309+
$command = sprintf('%s -S "%s"', $this->phpBin, '127.0.0.1:10000');
310+
}
308311
if ($this->phpBinOptions) {
309312
$command = sprintf("%s %s", $command, $this->phpBinOptions);
310313
}

features/schema_metadata.feature

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
Feature: Schema Metadata
2+
3+
PHP Driver exposes the Cassandra Schema Metadata for keyspaces, tables, and
4+
columns.
5+
6+
Background:
7+
Given a running Cassandra cluster
8+
And the following schema:
9+
"""cql
10+
CREATE KEYSPACE simplex WITH replication = {
11+
'class': 'SimpleStrategy',
12+
'replication_factor': 1
13+
} AND DURABLE_WRITES = false;
14+
USE simplex;
15+
CREATE TABLE values (
16+
id int PRIMARY KEY,
17+
bigint_value bigint,
18+
decimal_value decimal,
19+
double_value double,
20+
float_value float,
21+
int_value int,
22+
varint_value varint,
23+
ascii_value ascii,
24+
text_value text,
25+
varchar_value varchar,
26+
timestamp_value timestamp,
27+
blob_value blob,
28+
uuid_value uuid,
29+
timeuuid_value timeuuid,
30+
inet_value inet,
31+
list_value List<text>,
32+
map_value Map<timestamp, double>,
33+
set_value Set<float>
34+
) WITH
35+
bloom_filter_fp_chance=0.5 AND
36+
caching='ALL' AND
37+
comment='Schema Metadata Feature' AND
38+
compaction={'class': 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 37} AND
39+
compression={'sstable_compression': 'DeflateCompressor'} AND
40+
dclocal_read_repair_chance=0.25 AND
41+
gc_grace_seconds=3600 AND
42+
populate_io_cache_on_flush='true' AND
43+
read_repair_chance=0.75 AND
44+
replicate_on_write='false';
45+
"""
46+
47+
Scenario: Getting keyspace metadata
48+
Given the following example:
49+
"""php
50+
<?php
51+
$cluster = Cassandra::cluster()
52+
->withContactPoints('127.0.0.1')
53+
->build();
54+
$session = $cluster->connect("simplex");
55+
56+
$schema = $session->schema();
57+
$keyspace = $schema->keyspace("simplex");
58+
59+
echo "Name: " . $keyspace->name() . "\n";
60+
echo "Replication Class: " . $keyspace->replicationClassName() . "\n";
61+
foreach ($keyspace->replicationOptions() as $key => $value) {
62+
echo " " . $key . ":" . $value . "\n";
63+
}
64+
echo "Has Durable Writes: " . ($keyspace->hasDurableWrites() ? "True" : "False" ). "\n";
65+
"""
66+
When it is executed
67+
Then its output should contain:
68+
"""
69+
Name: simplex
70+
Replication Class: org.apache.cassandra.locator.SimpleStrategy
71+
replication_factor:1
72+
Has Durable Writes: False
73+
"""
74+
75+
Scenario: Getting table metadata
76+
Given the following example:
77+
"""php
78+
<?php
79+
$cluster = Cassandra::cluster()
80+
->withContactPoints('127.0.0.1')
81+
->build();
82+
$session = $cluster->connect("simplex");
83+
84+
$schema = $session->schema();
85+
$table = $schema->keyspace("simplex")->table("values");
86+
87+
echo "Name: " . $table->name() . "\n";
88+
echo "Bloom Filter: " . $table->bloomFilterFPChance() . "\n";
89+
$patterns = array('/{/', '/"/', '/:/', '/keys/');
90+
$table_caching = explode(",", $table->caching());
91+
echo "Caching: " . preg_replace($patterns, "", $table_caching[0]) . "\n";
92+
echo "Comment: " . $table->comment() . "\n";
93+
echo "Compaction Class: " . $table->compactionStrategyClassName() . "\n";
94+
foreach ($table->compactionStrategyOptions() as $key => $value) {
95+
echo " " . $key . ":" . $value . "\n";
96+
}
97+
foreach ($table->compressionParameters() as $key => $value) {
98+
echo " " . $key . ":" . $value . "\n";
99+
}
100+
echo "DC/Local Read Repair Chance: " . $table->localReadRepairChance() . "\n";
101+
echo "Garbage Collection Grace Seconds: " . $table->gcGraceSeconds() . "\n";
102+
echo "Read Repair Chance: " . $table->readRepairChance() . "\n";
103+
"""
104+
When it is executed
105+
Then its output should contain:
106+
"""
107+
Name: values
108+
Bloom Filter: 0.5
109+
Caching: ALL
110+
Comment: Schema Metadata Feature
111+
Compaction Class: org.apache.cassandra.db.compaction.LeveledCompactionStrategy
112+
sstable_size_in_mb:37
113+
sstable_compression:org.apache.cassandra.io.compress.DeflateCompressor
114+
DC/Local Read Repair Chance: 0.25
115+
Garbage Collection Grace Seconds: 3600
116+
Read Repair Chance: 0.75
117+
"""
118+
119+
@cassandra-version-less-2.1
120+
Scenario: Getting table metadata for io cache and replicate on write
121+
Given the following example:
122+
"""php
123+
<?php
124+
$cluster = Cassandra::cluster()
125+
->withContactPoints('127.0.0.1')
126+
->build();
127+
$session = $cluster->connect("simplex");
128+
129+
$schema = $session->schema();
130+
$table = $schema->keyspace("simplex")->table("values");
131+
132+
echo "Populate I/O Cache on Flush: " . ($table->populateIOCacheOnFlush() ? "True" : "False") . "\n";
133+
echo "Replicate on Write: " . ($table->replicateOnWrite() ? "True" : "False") . "\n";
134+
"""
135+
When it is executed
136+
Then its output should contain:
137+
"""
138+
Populate I/O Cache on Flush: True
139+
Replicate on Write: False
140+
"""
141+
142+
@cassandra-version-only-2.0
143+
Scenario: Getting table metadata for index interval
144+
Given the following example:
145+
"""php
146+
<?php
147+
$cluster = Cassandra::cluster()
148+
->withContactPoints('127.0.0.1')
149+
->build();
150+
$session = $cluster->connect("simplex");
151+
$cql = "ALTER TABLE values WITH index_interval = '512'";
152+
$session->execute(new Cassandra\SimpleStatement($cql));
153+
$schema = $session->schema();
154+
$table = $schema->keyspace("simplex")->table("values");
155+
156+
echo "Index Interval: " . $table->indexInterval() . "\n";
157+
"""
158+
When it is executed
159+
Then its output should contain:
160+
"""
161+
Index Interval: 512
162+
"""
163+
164+
@cassandra-version-2.0
165+
Scenario: Getting table metadata for default TTL, memtable flush period and
166+
speculative retry
167+
Given the following example:
168+
"""php
169+
<?php
170+
$cluster = Cassandra::cluster()
171+
->withContactPoints('127.0.0.1')
172+
->build();
173+
$session = $cluster->connect("simplex");
174+
$cql = "ALTER TABLE values WITH default_time_to_live = '10000' AND "
175+
. "memtable_flush_period_in_ms = '100' AND "
176+
. "speculative_retry = '10ms'";
177+
$session->execute(new Cassandra\SimpleStatement($cql));
178+
$schema = $session->schema();
179+
$table = $schema->keyspace("simplex")->table("values");
180+
181+
echo "Default TTL: " . $table->defaultTTL() . "\n";
182+
echo "Memtable Flush Period: " . $table->memtableFlushPeriodMs() . "\n";
183+
echo "Speculative Retry: " . intval($table->speculativeRetry()) . "\n";
184+
"""
185+
When it is executed
186+
Then its output should contain:
187+
"""
188+
Default TTL: 10000
189+
Memtable Flush Period: 100
190+
Speculative Retry: 10
191+
"""
192+
193+
@cassandra-version-2.1
194+
Scenario: Getting table metadata for max and min index intervals
195+
Given the following example:
196+
"""php
197+
<?php
198+
$cluster = Cassandra::cluster()
199+
->withContactPoints('127.0.0.1')
200+
->build();
201+
$session = $cluster->connect("simplex");
202+
$cql = "ALTER TABLE values WITH max_index_interval = '16' AND "
203+
. "min_index_interval = '4'";
204+
$session->execute(new Cassandra\SimpleStatement($cql));
205+
$schema = $session->schema();
206+
$table = $schema->keyspace("simplex")->table("values");
207+
208+
echo "Maximum Index Interval: " . $table->maxIndexInterval() . "\n";
209+
echo "Minimum Index Interval: " . $table->minIndexInterval() . "\n";
210+
"""
211+
When it is executed
212+
Then its output should contain:
213+
"""
214+
Maximum Index Interval: 16
215+
Minimum Index Interval: 4
216+
"""
217+
218+
@cassandra-version-2.0
219+
Scenario: Getting metadata for column and types
220+
Given the following example:
221+
"""php
222+
<?php
223+
$cluster = Cassandra::cluster()
224+
->withContactPoints('127.0.0.1')
225+
->build();
226+
$session = $cluster->connect("simplex");
227+
$schema = $session->schema();
228+
$table = $schema->keyspace("simplex")->table("values");
229+
foreach ($table->columns() as $column) {
230+
echo $column->name() . ': ' . $column->type() . "\n";
231+
}
232+
"""
233+
When it is executed
234+
Then its output should contain:
235+
"""
236+
ascii_value: ascii
237+
bigint_value: bigint
238+
blob_value: blob
239+
decimal_value: decimal
240+
double_value: double
241+
float_value: float
242+
id: int
243+
inet_value: inet
244+
int_value: int
245+
list_value: list<varchar>
246+
map_value: map<timestamp, double>
247+
set_value: set<float>
248+
text_value: varchar
249+
timestamp_value: timestamp
250+
timeuuid_value: timeuuid
251+
uuid_value: uuid
252+
varchar_value: varchar
253+
varint_value: varint
254+
"""

0 commit comments

Comments
 (0)