Skip to content

Commit b13017e

Browse files
committed
Remove integration test listener in favor of clean up singleton
1 parent 3302cbd commit b13017e

File tree

4 files changed

+37
-150
lines changed

4 files changed

+37
-150
lines changed

phpunit.xml.dist

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
</testsuite>
1111
</testsuites>
1212

13-
<listeners>
14-
<listener class="TestSuiteListener" file="./tests/listener.php"></listener>
15-
</listeners>
16-
1713
<filter>
1814
<whitelist>
1915
<directory suffix=".php">./src/</directory>

tests/integration/Cassandra/BasicIntegrationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ protected function setUp() {
111111
protected function tearDown() {
112112
unset($this->integration);
113113
unset($this->ccm);
114+
unset($this->session);
114115
}
115116
}

tests/integration/Cassandra/Integration.php

+36-20
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,22 @@ public function __construct($className,
148148
$query = sprintf(Integration::SIMPLE_KEYSPACE_FORMAT, $this->keyspaceName, $replicationStrategy);
149149

150150
// Create the session and keyspace for the integration test
151-
try {
152-
// Create the session and integration test keypspace
153-
$this->cluster = \Cassandra::cluster()
154-
->withContactPoints($this->getContactPoints(Integration::IP_ADDRESS, ($numberDC1Nodes + $numberDC2Nodes)))
155-
->build();
156-
$this->session = $this->cluster->connect();
157-
$statement = new SimpleStatement($query);
158-
$this->session->execute($statement);
151+
$this->cluster = \Cassandra::cluster()
152+
->withContactPoints($this->getContactPoints(Integration::IP_ADDRESS, ($numberDC1Nodes + $numberDC2Nodes)))
153+
->withPersistentSessions(false)
154+
->build();
155+
$this->session = $this->cluster->connect();
156+
$statement = new SimpleStatement($query);
157+
$this->session->execute($statement);
159158

160-
// Update the session to use the new keyspace by default
161-
$statement = new SimpleStatement("USE " . $this->keyspaceName);
162-
$this->session->execute($statement);
159+
// Update the session to use the new keyspace by default
160+
$statement = new SimpleStatement("USE " . $this->keyspaceName);
161+
$this->session->execute($statement);
163162

164-
// Get the server version the session is connected to
165-
$statement = new SimpleStatement(self::SELECT_SERVER_VERSION);
166-
$rows = $this->session->execute($statement);
167-
$this->serverVersion = $rows->first()["release_version"];
168-
169-
} catch (Exception $e) {
170-
printf("Error Creating CCM Cluster: %s" . PHP_EOL . "%s" . PHP_EOL,
171-
$e->getMessage(), $e->getTraceAsString());
172-
}
163+
// Get the server version the session is connected to
164+
$statement = new SimpleStatement(self::SELECT_SERVER_VERSION);
165+
$rows = $this->session->execute($statement);
166+
$this->serverVersion = $rows->first()["release_version"];
173167
}
174168

175169
public function __destruct() {
@@ -255,3 +249,25 @@ public static function disconnect() {
255249
unset(self::$instance);
256250
}
257251
}
252+
253+
class IntegrationRemoveAllClusters {
254+
private $ccm;
255+
private static $instance;
256+
257+
function __construct() {
258+
$this->ccm = new \CCM(\CCM::DEFAULT_CASSANDRA_VERSION, true);
259+
$this->ccm->removeAllClusters();
260+
}
261+
262+
function __destruct() {
263+
$this->ccm->removeAllClusters();
264+
}
265+
266+
public static function cleanup() {
267+
if (!isset($instance)) {
268+
self::$instance = new IntegrationRemoveAllClusters();
269+
}
270+
}
271+
}
272+
273+
IntegrationRemoveAllClusters::cleanup();

tests/listener.php

-126
This file was deleted.

0 commit comments

Comments
 (0)