1<?php 2 3declare(strict_types = 1); 4 5namespace Elasticsearch\Tests\ConnectionPool; 6 7use Elasticsearch; 8 9/** 10 * Class StaticConnectionPoolIntegrationTest 11 * 12 * @category Tests 13 * @package Elasticsearch 14 * @subpackage Tests/StaticConnectionPoolTest 15 * @author Zachary Tong <zachary.tong@elasticsearch.com> 16 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 17 * @link http://elasticsearch.org 18 */ 19class StaticConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase 20{ 21 public function setUp() 22 { 23 if (empty(getenv('ES_TEST_HOST'))) { 24 $this->markTestSkipped( 25 'Elasticsearch is not configured. Check the ES_TEST_HOST env in your phpunit.xml file.' 26 ); 27 } 28 } 29 30 // Issue #636 31 public function test404Liveness() 32 { 33 $client = \Elasticsearch\ClientBuilder::create() 34 ->setHosts([getenv('ES_TEST_HOST')]) 35 ->setConnectionPool(\Elasticsearch\ConnectionPool\StaticConnectionPool::class) 36 ->build(); 37 38 $connection = $client->transport->getConnection(); 39 40 // Ensure connection is dead 41 $connection->markDead(); 42 43 // The index doesn't exist, but the server is up so this will return a 404 44 $this->assertFalse($client->indices()->exists(['index' => 'not_existing_index'])); 45 46 // But the node should be marked as alive since the server responded 47 $this->assertTrue($connection->isAlive()); 48 } 49} 50