Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
FROM php:8.2
FROM php:8.4
WORKDIR /tmp/cassandra-php-driver

RUN apt update -y \
&& apt install python3 pip cmake unzip mlocate build-essential git libuv1-dev libssl-dev libgmp-dev openssl zlib1g-dev libpcre3-dev openjdk-11-jre openjdk-11-jdk -y \
&& pip install git+https://github.com/riptano/ccm.git@master
&& apt install python3 pip cmake unzip plocate build-essential git libuv1-dev libssl-dev libgmp-dev openssl zlib1g-dev libpcre2-dev -y \
&& pip install --break-system-packages setuptools git+https://github.com/apache/cassandra-ccm \
&& apt-get install -y wget gnupg ca-certificates \
&& mkdir -p /etc/apt/keyrings \
&& wget -O /etc/apt/keyrings/adoptium.gpg https://packages.adoptium.net/artifactory/api/gpg/key/public \
&& echo "deb [signed-by=/etc/apt/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb bookworm main" > /etc/apt/sources.list.d/adoptium.list \
&& apt-get update \
&& apt-get install -y temurin-11-jdk \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p ~/.ccm && echo '[repositories]\ncassandra = https://dlcdn.apache.org/cassandra' > ~/.ccm/config

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin
RUN docker-php-source extract \
Expand All @@ -17,7 +26,7 @@ RUN cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCASS_BUILD_STATIC=OFF -DCASS_BUILD_SHARED=
RUN docker-php-source extract

COPY ext ext
ENV NO_INTERACTION true
ENV NO_INTERACTION=true
RUN cd ext \
&& phpize \
&& LDFLAGS="-L/usr/local/lib" LIBS="-lssl -lz -luv -lm -lgmp -lstdc++" ./configure --with-cassandra=/usr/local \
Expand All @@ -38,10 +47,9 @@ ENV CI=$CI
COPY support support
COPY tests tests
COPY phpunit.xml .
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
ENV JAVA_HOME=/usr
RUN bin/phpunit --stop-on-error --stop-on-failure --testsuite unit
RUN bin/phpunit --stop-on-error --stop-on-failure --testsuite integration --exclude-group flaky
RUN bash -c "for i in {1..10}; do bin/phpunit --stop-on-error --stop-on-failure --testsuite integration --group flaky && exit 0 || sleep 1; done; exit 1;"
RUN bin/phpunit --stop-on-error --stop-on-failure --testsuite integration

COPY features features
COPY behat.yml .
Expand Down
2 changes: 1 addition & 1 deletion behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default:
tags: "~@cassandra-version-less-2.1&&~@cassandra-version-only-2.0&&~@broken"
contexts:
- FeatureContext:
cassandra_version: "4.1.0"
cassandra_version: "4.1.10"

cassandra-version-3.11:
formatters:
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datastax/php-driver",
"type": "library",
"type": "php-ext",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"description": "DataStax PHP Driver for Apache Cassandra",
"keywords": [
"cassandra",
Expand All @@ -26,6 +26,9 @@
"require": {
"php": ">=8.1"
},
"php-ext": {
"extension-name": "cassandra"
},
"require-dev": {
"behat/behat": "^3.7",
"phpunit/php-code-coverage": "^7.0",
Expand Down
7 changes: 5 additions & 2 deletions ext/doc/generate_doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ function isAlreadyImplementedByBase($current, $implemented) {
function replaceKeyword($string) {
if ($string == "Function") {
return "Function_";
} else if ($string == "function") {
return "function_";
} else if ($string == "Float") {
return "Float_";
}
Expand Down Expand Up @@ -383,6 +381,7 @@ function writeMethod($doc, $file, $class, $method, &$singleEOL) {
fwrite($file, "...\$params");
} else {
$parameterType = parseDocMetadata($doc, $className, $methodName, $parameterName);
$defaultValue = NULL;
if ($parameter->isOptional()) {
$defaultValue = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;
if (empty($defaultValue)) {
Expand All @@ -397,6 +396,10 @@ function writeMethod($doc, $file, $class, $method, &$singleEOL) {
}
$parameterName = "$parameterName = $defaultValue";
}
// https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated
if ($parameterType && rtrim($parameterType) !== 'mixed' && $defaultValue === 'null') {
$parameterType = "?$parameterType";
}
fwrite($file, "$parameterType\$$parameterName");
}
$first = false;
Expand Down
15 changes: 12 additions & 3 deletions ext/src/Column.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ Column:
comment: Type of the column
type: \Cassandra\Type
isReversed:
comment: Returns whether the column is in descending or ascending order.
comment: |-
Returns whether the column is in descending or ascending order.

@deprecated
return:
comment: Whether the column is stored in descending order.
type: bool
Expand All @@ -28,12 +31,18 @@ Column:
comment: Whether the column is frozen
type: bool
indexName:
comment: Returns name of the index if defined.
comment: |-
Returns name of the index if defined.

@deprecated
return:
comment: Name of the index if defined or null
type: string
indexOptions:
comment: Returns index options if present.
comment: |-
Returns index options if present.

@deprecated
return:
comment: Index options if present or null
type: string
Expand Down
2 changes: 1 addition & 1 deletion ext/src/Keyspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Keyspace:
type: string
return:
comment: Table instance or null
type: \Cassandra\Table|null
type: \Cassandra\DefaultTable|null
tables:
comment: Returns all tables defined in this keyspace
return:
Expand Down
2 changes: 1 addition & 1 deletion ext/src/Schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Schema:
type: string
return:
comment: Keyspace instance or null
type: \Cassandra\Keyspace
type: \Cassandra\DefaultKeyspace
keyspaces:
comment: Returns all keyspaces defined in the schema.
return:
Expand Down
2 changes: 1 addition & 1 deletion ext/src/Session.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Session:
comment: Get a snapshot of the cluster's current schema.
return:
comment: A snapshot of the cluster's schema.
type: \Cassandra\Schema
type: \Cassandra\DefaultSchema
metrics:
comment: Get performance and diagnostic metrics.
return:
Expand Down
2 changes: 1 addition & 1 deletion ext/util/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ php_driver_value_compare(zval* zvalue1, zval* zvalue2 TSRMLS_DC) {
return 1;
}

int php_driver_data_compare(const void* a, const void* b TSRMLS_DC) {
int php_driver_data_compare(Bucket* a, Bucket* b TSRMLS_DC) {
Bucket *f, *s;
zval *first, *second;

Expand Down
2 changes: 1 addition & 1 deletion ext/util/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct php_driver_set_entry_ {

unsigned php_driver_value_hash(zval* zvalue TSRMLS_DC);
int php_driver_value_compare(zval* zvalue1, zval* zvalue2 TSRMLS_DC);
int php_driver_data_compare(const void* a, const void* b TSRMLS_DC);
int php_driver_data_compare(Bucket* a, Bucket* b TSRMLS_DC);

unsigned php_driver_mpz_hash(unsigned seed, mpz_t n);

Expand Down
19 changes: 14 additions & 5 deletions support/ccm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class CCM
{
const DEFAULT_CLUSTER_PREFIX = "php-driver";
const DEFAULT_CASSANDRA_VERSION = "4.1.0";
const DEFAULT_CASSANDRA_VERSION = "4.1.10";
const PROCESS_TIMEOUT_IN_SECONDS = 480;
private $clusterPrefix;
private $isSilent;
Expand Down Expand Up @@ -179,7 +179,7 @@ private function internalSetup($dataCenterOneNodes, $dataCenterTwoNodes)
$this->run('create', '-v', 'binary:' . $this->version, '-b', $clusterName);

$params = array(
'updateconf', '--rt', '1000', 'read_request_timeout_in_ms: 1000',
'updateconf', 'read_request_timeout_in_ms: 1000',
'write_request_timeout_in_ms: 1000', 'request_timeout_in_ms: 1000',
'phi_convict_threshold: 16', 'hinted_handoff_enabled: false',
'dynamic_snitch_update_interval_in_ms: 1000',
Expand Down Expand Up @@ -212,22 +212,31 @@ private function internalSetup($dataCenterOneNodes, $dataCenterTwoNodes)
}

if (version_compare($this->version, "2.2.0", ">=")) {
$this->run('updateconf', 'enable_user_defined_functions: true');
$params[] = 'enable_user_defined_functions: true';
}

if (version_compare($this->version, "3.0.0", ">=")) {
$this->run('updateconf', 'enable_scripted_user_defined_functions: true');
$params[] = 'enable_scripted_user_defined_functions: true';
}

if (version_compare($this->version, "3.0.0", ">=")) {
$this->run('updateconf', 'enable_materialized_views: true');
$params[] = 'enable_materialized_views: true';
}

$params[] = 'key_cache_size_in_mb: 0';
$params[] = 'key_cache_save_period: 0';
$params[] = 'memtable_flush_writers: 1';
$params[] = 'max_hints_delivery_threads: 1';

// https://cassandra.apache.org/_/blog/Apache-Cassandra-4.1-Configuration-Standardization.html
if (version_compare($this->version, '4.1.0', '>=')) {
$params = \preg_replace(
['/_in_ms: (\d+)/m', '/_in_mb: (\d+)/m', '/_mb_per_sec: (\d+)/m', '/^enable_(\w+)/m'],
[': \1ms', ': \1MiB', ': \1MiB/s', '\1_enabled'],
$params
);
}

call_user_func_array(array($this, 'run'), $params);
$this->run('populate', '-n', $dataCenterOneNodes.':'.$dataCenterTwoNodes, '-i', '127.0.0.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cassandra/BasicIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class BasicIntegrationTest extends TestCase {
*/
protected function setUp(): void {
// Initialize the database and establish a connection
$this->integration = new Integration(get_class(), $this->getName(false),
$this->integration = new Integration(get_class($this), $this->getName(false),
$this->numberDC1Nodes, $this->numberDC2Nodes,
$this->replicationFactor, $this->isClientAuthentication,
$this->isSSL, $this->isUserDefinedAggregatesFunctions);
Expand Down
1 change: 1 addition & 0 deletions tests/integration/Cassandra/ConsistencyIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ConsistencyIntegrationTest extends BasicIntegrationTest {
public function testDefaultConsistencyLevel() {
// Create a new table
$this->session->execute("CREATE TABLE {$this->tableNamePrefix} (key int PRIMARY KEY)");
usleep(200000);

// Enable tracing
$this->ccm->enableTracing(true);
Expand Down
17 changes: 13 additions & 4 deletions tests/integration/Cassandra/SchemaMetadataIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

/**
* Schema metadata integration tests.
*
* @group flaky
*/
class SchemaMetadataIntegrationTest extends BasicIntegrationTest {
/**
Expand Down Expand Up @@ -70,7 +68,8 @@ protected function createKeyspaceWithSchema($keyspaceName, $tableSchemas) {
array_filter(array_keys($tableSchema),
function ($columnName) { return strpos($columnName, "key") === 0; }))
);
$this->session->execute($query);
$this->session->execute($query)->count();
usleep(200000);
}
}

Expand All @@ -82,20 +81,23 @@ protected function createTableForSecondaryIndexes() {
"CREATE TABLE {$this->tableNamePrefix} " .
"(key1 text, value1 int, value2 map<text, text>, PRIMARY KEY(key1))"
);
usleep(200000);
}

/**
* Create the simple secondary index using the table
*/
protected function createSimpleSecondaryIndex() {
$this->session->execute("CREATE INDEX simple ON {$this->tableNamePrefix} (value1)");
sleep(1);
}

/**
* Create the collections secondary index using the table
*/
protected function createCollectionSecondaryIndex() {
$this->session->execute("CREATE INDEX collection ON {$this->tableNamePrefix} (KEYS(value2))");
sleep(1);
}

/**
Expand Down Expand Up @@ -134,6 +136,7 @@ protected function createTablesForMaterializedViews() {
"CREATE TABLE {$this->tableNamePrefix}_2 " .
"(key1 text, key2 int, value1 int, PRIMARY KEY(key1, key2))"
);
usleep(200000);
}

/**
Expand All @@ -146,6 +149,7 @@ protected function createSimpleMaterializedView() {
"SELECT $column FROM {$this->tableNamePrefix}_1 WHERE value1 IS NOT NULL AND key1 IS NOT NULL " .
"PRIMARY KEY(value1, key1)"
);
usleep(200000);
}

/**
Expand Down Expand Up @@ -506,6 +510,7 @@ public function testEnumerateKeyspaces() {
if (strpos($keyspaceName, "system") === 0) continue;
$this->createKeyspace($keyspaceName);
}
usleep(200000);

$count = 0;
foreach ($this->session->schema()->keyspaces() as $keyspace) {
Expand Down Expand Up @@ -631,6 +636,7 @@ public function testGetColumnIndexOptions() {
"CREATE TABLE {$this->tableNamePrefix}_with_index " .
"(key int PRIMARY KEY, value map<text, frozen<map<int, int>>>)"
);
usleep(200000);

$keyspace = $this->session->schema()->keyspace($this->keyspaceName);
$this->assertNotNull($keyspace);
Expand All @@ -644,7 +650,7 @@ public function testGetColumnIndexOptions() {
$this->assertNull($indexOptions);

$this->session->execute("CREATE INDEX ON {$this->tableNamePrefix}_with_index (value)");
sleep(10);
sleep(1);

$keyspace = $this->session->schema()->keyspace($this->keyspaceName);
$this->assertNotNull($keyspace);
Expand Down Expand Up @@ -676,6 +682,7 @@ public function testSchemaMetadataWithNullFields() {
"CREATE TABLE {$this->tableNamePrefix}_null_comment " .
"(key int PRIMARY KEY, value int)"
);
usleep(200000);

$keyspace = $this->session->schema()->keyspace($this->keyspaceName);
$table = $keyspace->table("{$this->tableNamePrefix}_null_comment");
Expand Down Expand Up @@ -714,6 +721,7 @@ public function testSchemaMetadataWithNestedColumnTypes() {
"CREATE TABLE {$this->tableNamePrefix}_nested3 " .
"(key int PRIMARY KEY, value list<frozen<map<int, frozen<set<int>>>>>)"
);
usleep(200000);

$keyspace = $this->session->schema()->keyspace($this->keyspaceName);

Expand Down Expand Up @@ -1280,6 +1288,7 @@ public function testSingleQuoteCustomValue() {
. "key TEXT PRIMARY KEY,"
. "value 'org.apache.cassandra.db.marshal.LexicalUUIDType')"
);
usleep(200000);

// Get the schema from the session
$schema = $this->session->schema();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cassandra/UserTypeIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function generateAddressValue() {
* value
* (DEFAULT: self::generateAddressValue())
*/
public static function assertAddressValue(UserTypeValue $address, UserTypeValue $expected = null) {
public static function assertAddressValue(UserTypeValue $address, ?UserTypeValue $expected = null) {
// Determine if the expected value should be defaulted
if (is_null($expected)) {
$expected = self::generateAddressValue();
Expand Down