diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster')
4 files changed, 493 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/IndexTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/IndexTest.php new file mode 100644 index 00000000..00a121fc --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/IndexTest.php @@ -0,0 +1,144 @@ +<?php +namespace Elastica\Test\Cluster\Health; + +use Elastica\Cluster\Health\Index as HealthIndex; +use Elastica\Test\Base as BaseTest; + +class IndexTest extends BaseTest +{ + /** + * @var \Elastica\Cluster\Health\Index + */ + protected $_index; + + public function setUp() + { + parent::setUp(); + + $data = array( + 'status' => 'yellow', + 'number_of_shards' => 1, + 'number_of_replicas' => 2, + 'active_primary_shards' => 3, + 'active_shards' => 4, + 'relocating_shards' => 5, + 'initializing_shards' => 6, + 'unassigned_shards' => 7, + 'shards' => array( + '0' => array( + 'status' => 'yellow', + 'primary_active' => false, + 'active_shards' => 0, + 'relocating_shards' => 1, + 'initializing_shards' => 0, + 'unassigned_shards' => 1, + ), + '1' => array( + 'status' => 'yellow', + 'primary_active' => true, + 'active_shards' => 1, + 'relocating_shards' => 0, + 'initializing_shards' => 0, + 'unassigned_shards' => 1, + ), + '2' => array( + 'status' => 'green', + 'primary_active' => true, + 'active_shards' => 1, + 'relocating_shards' => 0, + 'initializing_shards' => 0, + 'unassigned_shards' => 0, + ), + ), + ); + + $this->_index = new HealthIndex('test', $data); + } + + /** + * @group unit + */ + public function testGetName() + { + $this->assertEquals('test', $this->_index->getName()); + } + + /** + * @group unit + */ + public function testGetStatus() + { + $this->assertEquals('yellow', $this->_index->getStatus()); + } + + /** + * @group unit + */ + public function testGetNumberOfShards() + { + $this->assertEquals(1, $this->_index->getNumberOfShards()); + } + + /** + * @group unit + */ + public function testGetNumberOfReplicas() + { + $this->assertEquals(2, $this->_index->getNumberOfReplicas()); + } + + /** + * @group unit + */ + public function testGetActivePrimaryShards() + { + $this->assertEquals(3, $this->_index->getActivePrimaryShards()); + } + + /** + * @group unit + */ + public function testGetActiveShards() + { + $this->assertEquals(4, $this->_index->getActiveShards()); + } + + /** + * @group unit + */ + public function testGetRelocatingShards() + { + $this->assertEquals(5, $this->_index->getRelocatingShards()); + } + + /** + * @group unit + */ + public function testGetInitializingShards() + { + $this->assertEquals(6, $this->_index->getInitializingShards()); + } + + /** + * @group unit + */ + public function testGetUnassignedShards() + { + $this->assertEquals(7, $this->_index->getUnassignedShards()); + } + + /** + * @group unit + */ + public function testGetShards() + { + $shards = $this->_index->getShards(); + + $this->assertInternalType('array', $shards); + $this->assertEquals(3, count($shards)); + + foreach ($shards as $shard) { + $this->assertInstanceOf('Elastica\Cluster\Health\Shard', $shard); + } + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/ShardTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/ShardTest.php new file mode 100644 index 00000000..5a436623 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/ShardTest.php @@ -0,0 +1,85 @@ +<?php +namespace Elastica\Test\Cluster\Health; + +use Elastica\Cluster\Health\Shard as HealthShard; +use Elastica\Test\Base as BaseTest; + +class ShardTest extends BaseTest +{ + /** + * @var \Elastica\Cluster\Health\Shard + */ + protected $_shard; + + public function setUp() + { + parent::setUp(); + + $shardData = array( + 'status' => 'red', + 'primary_active' => true, + 'active_shards' => 1, + 'relocating_shards' => 0, + 'initializing_shards' => 0, + 'unassigned_shards' => 1, + ); + + $this->_shard = new HealthShard(2, $shardData); + } + + /** + * @group unit + */ + public function testGetShardNumber() + { + $this->assertEquals(2, $this->_shard->getShardNumber()); + } + + /** + * @group unit + */ + public function testGetStatus() + { + $this->assertEquals('red', $this->_shard->getStatus()); + } + + /** + * @group unit + */ + public function testisPrimaryActive() + { + $this->assertTrue($this->_shard->isPrimaryActive()); + } + + /** + * @group unit + */ + public function testIsActive() + { + $this->assertTrue($this->_shard->isActive()); + } + + /** + * @group unit + */ + public function testIsRelocating() + { + $this->assertFalse($this->_shard->isRelocating()); + } + + /** + * @group unit + */ + public function testIsInitialized() + { + $this->assertFalse($this->_shard->isInitialized()); + } + + /** + * @group unit + */ + public function testIsUnassigned() + { + $this->assertTrue($this->_shard->isUnassigned()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/HealthTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/HealthTest.php new file mode 100644 index 00000000..bb3e82ec --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/HealthTest.php @@ -0,0 +1,147 @@ +<?php +namespace Elastica\Test\Cluster; + +use Elastica\Test\Base as BaseTest; + +class HealthTest extends BaseTest +{ + /** + * @var \Elastica\Cluster\Health + */ + protected $_health; + + protected function setUp() + { + parent::setUp(); + + $data = array( + 'cluster_name' => 'test_cluster', + 'status' => 'green', + 'timed_out' => false, + 'number_of_nodes' => 10, + 'number_of_data_nodes' => 8, + 'active_primary_shards' => 3, + 'active_shards' => 4, + 'relocating_shards' => 2, + 'initializing_shards' => 7, + 'unassigned_shards' => 5, + 'indices' => array( + 'index_one' => array( + ), + 'index_two' => array( + ), + ), + ); + + $health = $this + ->getMockBuilder('Elastica\Cluster\Health') + ->setConstructorArgs(array($this->_getClient())) + ->setMethods(array('_retrieveHealthData')) + ->getMock(); + + $health + ->expects($this->any()) + ->method('_retrieveHealthData') + ->will($this->returnValue($data)); + + // need to explicitly refresh because the mocking won't refresh the data in the constructor + $health->refresh(); + + $this->_health = $health; + } + + /** + * @group unit + */ + public function testGetClusterName() + { + $this->assertEquals('test_cluster', $this->_health->getClusterName()); + } + + /** + * @group unit + */ + public function testGetStatus() + { + $this->assertEquals('green', $this->_health->getStatus()); + } + + /** + * @group unit + */ + public function testGetTimedOut() + { + $this->assertFalse($this->_health->getTimedOut()); + } + + /** + * @group unit + */ + public function testGetNumberOfNodes() + { + $this->assertEquals(10, $this->_health->getNumberOfNodes()); + } + + /** + * @group unit + */ + public function testGetNumberOfDataNodes() + { + $this->assertEquals(8, $this->_health->getNumberOfDataNodes()); + } + + /** + * @group unit + */ + public function testGetActivePrimaryShards() + { + $this->assertEquals(3, $this->_health->getActivePrimaryShards()); + } + + /** + * @group unit + */ + public function testGetActiveShards() + { + $this->assertEquals(4, $this->_health->getActiveShards()); + } + + /** + * @group unit + */ + public function testGetRelocatingShards() + { + $this->assertEquals(2, $this->_health->getRelocatingShards()); + } + + /** + * @group unit + */ + public function testGetInitializingShards() + { + $this->assertEquals(7, $this->_health->getInitializingShards()); + } + + /** + * @group unit + */ + public function testGetUnassignedShards() + { + $this->assertEquals(5, $this->_health->getUnassignedShards()); + } + + /** + * @group unit + */ + public function testGetIndices() + { + $indices = $this->_health->getIndices(); + + $this->assertInternalType('array', $indices); + $this->assertEquals(2, count($indices)); + + foreach ($indices as $index) { + $this->assertInstanceOf('Elastica\Cluster\Health\Index', $index); + } + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/SettingsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/SettingsTest.php new file mode 100644 index 00000000..2a52fc8f --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/SettingsTest.php @@ -0,0 +1,117 @@ +<?php +namespace Elastica\Test\Cluster; + +use Elastica\Cluster\Settings; +use Elastica\Document; +use Elastica\Exception\ResponseException; +use Elastica\Test\Base as BaseTest; + +class SettingsTest extends BaseTest +{ + /** + * @group functional + */ + public function testSetTransient() + { + $index = $this->_createIndex(); + + if (count($index->getClient()->getCluster()->getNodes()) < 2) { + $this->markTestSkipped('At least two master nodes have to be running for this test'); + } + + $settings = new Settings($index->getClient()); + + $settings->setTransient('discovery.zen.minimum_master_nodes', 2); + $data = $settings->get(); + $this->assertEquals(2, $data['transient']['discovery']['zen']['minimum_master_nodes']); + + $settings->setTransient('discovery.zen.minimum_master_nodes', 1); + $data = $settings->get(); + $this->assertEquals(1, $data['transient']['discovery']['zen']['minimum_master_nodes']); + } + + /** + * @group functional + */ + public function testSetPersistent() + { + $index = $this->_createIndex(); + + if (count($index->getClient()->getCluster()->getNodes()) < 2) { + $this->markTestSkipped('At least two master nodes have to be running for this test'); + } + + $settings = new Settings($index->getClient()); + + $settings->setPersistent('discovery.zen.minimum_master_nodes', 2); + $data = $settings->get(); + $this->assertEquals(2, $data['persistent']['discovery']['zen']['minimum_master_nodes']); + + $settings->setPersistent('discovery.zen.minimum_master_nodes', 1); + $data = $settings->get(); + $this->assertEquals(1, $data['persistent']['discovery']['zen']['minimum_master_nodes']); + } + + /** + * @group functional + */ + public function testSetReadOnly() + { + // Create two indices to check that the complete cluster is read only + $settings = new Settings($this->_getClient()); + $settings->setReadOnly(false); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); + + $doc1 = new Document(null, array('hello' => 'world')); + $doc2 = new Document(null, array('hello' => 'world')); + $doc3 = new Document(null, array('hello' => 'world')); + $doc4 = new Document(null, array('hello' => 'world')); + $doc5 = new Document(null, array('hello' => 'world')); + $doc6 = new Document(null, array('hello' => 'world')); + + // Check that adding documents work + $index1->getType('test')->addDocument($doc1); + $index2->getType('test')->addDocument($doc2); + + $response = $settings->setReadOnly(true); + $this->assertFalse($response->hasError()); + $setting = $settings->getTransient('cluster.blocks.read_only'); + $this->assertEquals('true', $setting); + + // Make sure both index are read only + try { + $index1->getType('test')->addDocument($doc3); + $this->fail('should throw read only exception'); + } catch (ResponseException $e) { + $message = $e->getMessage(); + $this->assertContains('ClusterBlockException', $message); + $this->assertContains('cluster read-only', $message); + } + + try { + $index2->getType('test')->addDocument($doc4); + $this->fail('should throw read only exception'); + } catch (ResponseException $e) { + $message = $e->getMessage(); + $this->assertContains('ClusterBlockException', $message); + $this->assertContains('cluster read-only', $message); + } + + $response = $settings->setReadOnly(false); + $this->assertFalse($response->hasError()); + $setting = $settings->getTransient('cluster.blocks.read_only'); + $this->assertEquals('false', $setting); + + // Check that adding documents works again + $index1->getType('test')->addDocument($doc5); + $index2->getType('test')->addDocument($doc6); + + $index1->refresh(); + $index2->refresh(); + + // 2 docs should be in each index + $this->assertEquals(2, $index1->count()); + $this->assertEquals(2, $index2->count()); + } +} |