Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IndexAlreadyExistsException with ResourceAlreadyExistsException #1350

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}