jenkins-bot has submitted this change and it was merged.

Change subject: Check response from index create
......................................................................


Check response from index create

Return a fatal status if there was an error when
creating an index, with the error message passed
to the Status.

Change-Id: I182da29e0d49804b3465c1558cc5b2e256e4a2be
---
M includes/Maintenance/IndexCreator.php
M tests/unit/Maintenance/IndexCreatorTest.php
2 files changed, 25 insertions(+), 9 deletions(-)

Approvals:
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  DCausse: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Maintenance/IndexCreator.php 
b/includes/Maintenance/IndexCreator.php
index 93eecf2..e268b9f 100644
--- a/includes/Maintenance/IndexCreator.php
+++ b/includes/Maintenance/IndexCreator.php
@@ -57,7 +57,11 @@
                );
 
                try {
-                       $this->index->create( $args, $rebuild );
+                       $response = $this->index->create( $args, $rebuild );
+
+                       if ( $response->hasError() === true ) {
+                               return Status::newFatal( $response->getError() 
);
+                       }
                } catch ( \Elastica\Exception\InvalidException $ex ) {
                        return Status::newFatal( $ex->getMessage() );
                } catch ( \Elastica\Exception\ResponseException $ex ) {
diff --git a/tests/unit/Maintenance/IndexCreatorTest.php 
b/tests/unit/Maintenance/IndexCreatorTest.php
index 5a6c140..9ef7e4c 100644
--- a/tests/unit/Maintenance/IndexCreatorTest.php
+++ b/tests/unit/Maintenance/IndexCreatorTest.php
@@ -3,6 +3,7 @@
 namespace CirrusSearch\Tests\Maintenance;
 
 use CirrusSearch\Maintenance\IndexCreator;
+use Elastica\Response;
 
 /**
  * This program is free software; you can redistribute it and/or modify
@@ -29,8 +30,8 @@
        /**
         * @dataProvider createIndexProvider
         */
-       public function testCreateIndex( $rebuild, $maxShardsPerNode ) {
-               $index = $this->getIndex();
+       public function testCreateIndex( $rebuild, $maxShardsPerNode, Response 
$response ) {
+               $index = $this->getIndex( $response );
                $analysisConfigBuilder = $this->getAnalysisConfigBuilder();
 
                $indexCreator = new IndexCreator( $index, 
$analysisConfigBuilder );
@@ -49,18 +50,29 @@
        }
 
        public function createIndexProvider() {
+               $successResponse = new Response( array() );
+               $errorResponse = new Response( array( 'error' => 'index 
creation failed' ) );
+
                return array(
-                       array( true, 'unlimited' ),
-                       array( true, 2 ),
-                       array( false, 'unlimited' ),
-                       array( false, 2 )
+                       array( true, 'unlimited', $successResponse ),
+                       array( true, 2, $successResponse ),
+                       array( true, 2, $errorResponse ),
+                       array( false, 'unlimited', $successResponse ),
+                       array( false, 2, $successResponse ),
+                       array( false, 'unlimited', $errorResponse )
                );
        }
 
-       private function getIndex() {
-               return $this->getMockBuilder( 'Elastica\Index' )
+       private function getIndex( $response ) {
+               $index = $this->getMockBuilder( 'Elastica\Index' )
                        ->disableOriginalConstructor()
                        ->getMock();
+
+               $index->expects( $this->any() )
+                       ->method( 'create' )
+                       ->will( $this->returnValue( $response ) );
+
+               return $index;
        }
 
        private function getAnalysisConfigBuilder() {

-- 
To view, visit https://gerrit.wikimedia.org/r/274979
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I182da29e0d49804b3465c1558cc5b2e256e4a2be
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to