Skip to content

Commit 99dc72d

Browse files
authored
test: PHP-144 - Async connection with no hosts available
1 parent 8604fb4 commit 99dc72d

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/integration/Cassandra/BasicIntegrationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ abstract class BasicIntegrationTest extends \PHPUnit_Framework_TestCase {
6363
* @var int
6464
*/
6565
protected $replicationFactor = -1;
66+
/**
67+
* Established cluster configuration.
68+
*
69+
* @var \Cassandra\Cluster
70+
*/
71+
protected $cluster;
6672
/**
6773
* Connected database session.
6874
*
@@ -116,6 +122,7 @@ protected function setUp() {
116122
$this->replicationFactor, $this->isClientAuthentication,
117123
$this->isSSL, $this->isUserDefinedAggregatesFunctions);
118124
$this->ccm = $this->integration->ccm;
125+
$this->cluster = $this->integration->cluster;
119126
$this->session = $this->integration->session;
120127
$this->serverVersion = $this->integration->serverVersion;
121128

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2015-2017 DataStax, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace Cassandra;
20+
21+
/**
22+
* Session integration tests
23+
*/
24+
class SessionIntegrationTest extends BasicIntegrationTest {
25+
26+
/**
27+
* Ensure the driver does not crash connecting to a non-existent server
28+
*
29+
* This test will ensure that when attempting to connect to a non-existent
30+
* server instance asynchronously, the driver will not crash.
31+
*
32+
* @jira_ticket PHP-144
33+
* @test_category connection
34+
* @since 1.3.0
35+
* @excpected_result Driver will not connect and continue to function
36+
*/
37+
public function testAsyncConnectionNoHost() {
38+
// Stop the server instance (no hosts are required)
39+
$this->ccm->stop();
40+
41+
// Create and close sessions asynchronously
42+
$connect_future = $this->cluster->connectAsync();
43+
try {
44+
$connect_future->get();
45+
$this->fail("Connection established");
46+
} catch (Exception\RuntimeException $re) {
47+
$this->assertTrue(true);
48+
}
49+
50+
// Restart the server instance
51+
$this->ccm->start();
52+
53+
}
54+
}

0 commit comments

Comments
 (0)