Beispiel #1
0
 /**
  * @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) {
         $error = $e->getResponse()->getError();
         $this->assertContains('cluster_block_exception', $error['type']);
         $this->assertContains('cluster read-only', $error['reason']);
     }
     try {
         $index2->getType('test')->addDocument($doc4);
         $this->fail('should throw read only exception');
     } catch (ResponseException $e) {
         $error = $e->getResponse()->getError();
         $this->assertContains('cluster_block_exception', $error['type']);
         $this->assertContains('cluster read-only', $error['reason']);
     }
     $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());
 }