Skip to content

Commit

Permalink
Replace IndexAlreadyExistsException with ResourceAlreadyExistsExcepti…
Browse files Browse the repository at this point in the history
…on (#1350)
  • Loading branch information
p365labs authored and ruflin committed Aug 17, 2017
1 parent 00be0b8 commit 10f705a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ All notable changes to this project will be documented in this file based on the
- In ES6 only [strict type boolean](https://github.com/elastic/elasticsearch/pull/22200) are accepted. [On ES6 docs](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/boolean.html)
- removed analyzed/not_analyzed on [indices mapping](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/mapping-index.html)
- [store](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/mapping-store.html) field only accepts boolean

- Replace IndexAlreadyExistsException with [ResourceAlreadyExistsException](https://github.com/elastic/elasticsearch/pull/21494) [#1350](https://github.com/ruflin/Elastica/pull/1350)

### Bugfixes

### Added
Expand Down
6 changes: 3 additions & 3 deletions test/Elastica/Exception/ResponseExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class ResponseExceptionTest extends AbstractExceptionTest
*/
public function testCreateExistingIndex()
{
$this->markTestSkipped('ES6 update: looks like now ES6 returns a different exception --> resource_already_exists_exception ');

$this->_createIndex('woo', true);

try {
$this->_createIndex('woo', false);
$this->fail('Index created when it should fail');
} catch (ResponseException $ex) {
$error = $ex->getResponse()->getFullError();
$this->assertEquals('index_already_exists_exception', $error['type']);

$this->assertNotEquals('index_already_exists_exception', $error['type']);
$this->assertEquals('resource_already_exists_exception', $error['type']);
$this->assertEquals(400, $ex->getResponse()->getStatus());
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/Elastica/IndexTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Elastica\Test;

use Elastica\Client;
use Elastica\Exception\ResponseException;
use Elastica\IndexTemplate;
use Elastica\Request;
use Elastica\Response;
Expand Down Expand Up @@ -107,4 +108,29 @@ public function testCreateTemplate()
$indexTemplate->delete();
$this->assertFalse($indexTemplate->exists());
}

/**
* @group functional
*/
public function testCreateAlreadyExistsTemplateException()
{
$template = [
'template' => 'te*',
'settings' => [
'number_of_shards' => 1,
],
];
$name = 'index_template1';
$indexTemplate = new IndexTemplate($this->_getClient(), $name);
$indexTemplate->create($template);
try {
$indexTemplate->create($template);
} catch (ResponseException $ex) {
$error = $ex->getResponse()->getFullError();

$this->assertNotEquals('index_template_already_exists_exception', $error['type']);
$this->assertEquals('resource_already_exists_exception', $error['type']);
$this->assertEquals(400, $ex->getResponse()->getStatus());
}
}
}

0 comments on commit 10f705a

Please sign in to comment.