Skip to content

Commit

Permalink
update some tests that created two mapping type, and removed referenc…
Browse files Browse the repository at this point in the history
…e to include_in_all removed in ES6 (#1362)
  • Loading branch information
p365labs authored and ruflin committed Aug 30, 2017
1 parent ac70945 commit f28072d
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 208 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ All notable changes to this project will be documented in this file based on the
- In QueryString is not allowed to use fields parameters in conjunction with default_field parameter. This is not well documented, it's possibile to understand from [Elasticsearch tests : QueryStringQueryBuilderTests.java](https://github.com/elastic/elasticsearch/blob/6.0/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java#L917) [#1352](https://github.com/ruflin/Elastica/pull/1352)
- Index mapping field of type [*'string'*](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/string.html) has been removed from Elasticsearch 6.0 codebase [#1353](https://github.com/ruflin/Elastica/pull/1353)
- The [created and found](https://github.com/elastic/elasticsearch/pull/25516) fields in index and delete responses became obsolete after the introduction of the result field in index, update and delete responses [#1354](https://github.com/ruflin/Elastica/pull/1354)

### Bugfixes
- Enforce [Content-Type requirement on the layer Rest](https://github.com/elastic/elasticsearch/pull/23146), a [PR on Elastica #1301](https://github.com/ruflin/Elastica/issues/1301) solved it (it has been implemented only in the HTTP Transport), but it was not implemented in the Guzzle Transport. [#1349](https://github.com/ruflin/Elastica/pull/1349)
- Scroll no longer does an extra iteration both on an empty result and on searches where the last page has a significantly smaller number of results than the pages before it.
Expand Down
2 changes: 1 addition & 1 deletion test/Elastica/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _checkScriptInlineSetting()
$nodes = $this->_getClient()->getCluster()->getNodes();
$scriptInline = $nodes[0]->getInfo()->get('settings', 'script', 'inline');

if ($scriptInline != 'true' && $this->_getVersion() < 6) {
if ($this->_getVersion() < 6 && $scriptInline != 'true') {
$this->markTestSkipped('script.inline is not enabled. This is required for this test');
}
}
Expand Down
8 changes: 5 additions & 3 deletions test/Elastica/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class BulkTest extends BaseTest
*/
public function testSend()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');
$index = $this->_createIndex();
$index2 = $this->_createIndex();
$indexName = $index->getName();
$type = $index->getType('bulk_test');
$type2 = $index->getType('bulk_test2');
$type2 = $index2->getType('bulk_test2');
$client = $index->getClient();

$newDocument1 = $type->createDocument(1, ['name' => 'Mister Fantastic']);
Expand Down Expand Up @@ -125,6 +125,7 @@ public function testSend()
$bulk->send();

$type->getIndex()->refresh();
$type2->getIndex()->refresh();

$this->assertEquals(2, $type->count());

Expand All @@ -142,8 +143,9 @@ public function testSend()
public function testUnicodeBulkSend()
{
$index = $this->_createIndex();
$index2 = $this->_createIndex();
$type = $index->getType('bulk_test');
$type2 = $index->getType('bulk_test2');
$type2 = $index2->getType('bulk_test2');
$client = $index->getClient();

$newDocument1 = $type->createDocument(1, ['name' => 'Сегодня, я вижу, особенно грустен твой взгляд,']);
Expand Down
8 changes: 4 additions & 4 deletions test/Elastica/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1309,18 +1309,18 @@ public function testDateMathEscapingWithEscapedPath()
*/
public function testEndpointParamsRequest()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');
$index = $this->_createIndex();
$index2 = $this->_createIndex();
$client = $index->getClient();
$type = $index->getType('test');
$doc = new Document(null, ['foo' => 'bar']);
$doc->setRouting('first_routing');
$type->addDocument($doc);

$type2 = $index->getType('foobar');
$doc = new Document(null, ['foo2' => 'bar2']);
$type2 = $index2->getType('foobar');
$doc2 = new Document(null, ['foo2' => 'bar2']);
$doc->setRouting('second_routing');
$type2->addDocument($doc);
$type2->addDocument($doc2);

$index->refresh();

Expand Down
45 changes: 9 additions & 36 deletions test/Elastica/Index/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ public function testDeleteAliasWithException()
*/
public function testSetGetNumberOfReplicas()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);
$settings = $index->getSettings();

Expand All @@ -118,10 +115,7 @@ public function testSetGetNumberOfReplicas()
*/
public function testGetNumberOfReplicas()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

$settings = $index->getSettings();
Expand All @@ -138,10 +132,7 @@ public function testGetNumberOfReplicas()
*/
public function testGetNumberOfShards()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create(['index' => ['number_of_shards' => 1]], true);

$settings = $index->getSettings();
Expand All @@ -158,10 +149,7 @@ public function testGetNumberOfShards()
*/
public function testGetDefaultNumberOfShards()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

$settings = $index->getSettings();
Expand All @@ -178,10 +166,7 @@ public function testGetDefaultNumberOfShards()
*/
public function testSetRefreshInterval()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

$settings = $index->getSettings();
Expand All @@ -202,10 +187,7 @@ public function testSetRefreshInterval()
*/
public function testGetRefreshInterval()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

$settings = $index->getSettings();
Expand All @@ -226,10 +208,7 @@ public function testGetRefreshInterval()
*/
public function testSetMergePolicy()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);
//wait for the shards to be allocated
$this->_waitForAllocation($index);
Expand All @@ -250,10 +229,7 @@ public function testSetMergePolicy()
*/
public function testSetMaxMergeAtOnce()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

//wait for the shards to be allocated
Expand Down Expand Up @@ -412,10 +388,7 @@ public function testNotFoundIndex()
*/
public function testSetMultiple()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index = $this->_createIndex();
$index->create([], true);

$settings = $index->getSettings();
Expand Down
95 changes: 55 additions & 40 deletions test/Elastica/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,17 @@ public function testCount()
*/
public function testDeleteByQueryWithQueryString()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');

$index = $this->_createIndex();
$type1 = new Type($index, 'test1');
$type1->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type1->addDocument(new Document(2, ['name' => 'ruflin']));
$type2 = new Type($index, 'test2');
$type2->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type2->addDocument(new Document(2, ['name' => 'ruflin']));
$index->refresh();

$response = $index->search('ruflin*');
$this->assertEquals(4, $response->count());
$this->assertEquals(2, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

// Delete first document
$response = $index->deleteByQuery('nicolas');
Expand All @@ -381,7 +376,7 @@ public function testDeleteByQueryWithQueryString()

// Makes sure, document is deleted
$response = $index->search('ruflin*');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(0, $response->count());
Expand All @@ -392,22 +387,17 @@ public function testDeleteByQueryWithQueryString()
*/
public function testDeleteByQueryWithQuery()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');

$index = $this->_createIndex();
$type1 = new Type($index, 'test1');
$type1->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type1->addDocument(new Document(2, ['name' => 'ruflin']));
$type2 = new Type($index, 'test2');
$type2->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type2->addDocument(new Document(2, ['name' => 'ruflin']));
$index->refresh();

$response = $index->search('ruflin*');
$this->assertEquals(4, $response->count());
$this->assertEquals(2, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

// Delete first document
$response = $index->deleteByQuery(new SimpleQueryString('nicolas'));
Expand All @@ -417,7 +407,7 @@ public function testDeleteByQueryWithQuery()

// Makes sure, document is deleted
$response = $index->search('ruflin*');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(0, $response->count());
Expand All @@ -428,22 +418,17 @@ public function testDeleteByQueryWithQuery()
*/
public function testDeleteByQueryWithArrayQuery()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');

$index = $this->_createIndex();
$type1 = new Type($index, 'test1');
$type1->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type1->addDocument(new Document(2, ['name' => 'ruflin']));
$type2 = new Type($index, 'test2');
$type2->addDocument(new Document(1, ['name' => 'ruflin nicolas']));
$type2->addDocument(new Document(2, ['name' => 'ruflin']));
$index->refresh();

$response = $index->search('ruflin*');
$this->assertEquals(4, $response->count());
$this->assertEquals(2, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

// Delete first document
$response = $index->deleteByQuery(['query' => ['query_string' => ['query' => 'nicolas']]]);
Expand All @@ -453,7 +438,7 @@ public function testDeleteByQueryWithArrayQuery()

// Makes sure, document is deleted
$response = $index->search('ruflin*');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(0, $response->count());
Expand All @@ -464,59 +449,89 @@ public function testDeleteByQueryWithArrayQuery()
*/
public function testDeleteByQueryWithQueryAndOptions()
{
$this->markTestSkipped('ES6 update: the final mapping would have more than 1 type');

$index = $this->_createIndex(null, true, 2);
$index2 = $this->_createIndex(null, true, 2);

$routing1 = 'first_routing';
$routing2 = 'second_routing';

for ($i = 1; $i <= 2; ++$i) {
$type = new Type($index, 'test'.$i);
$doc = new Document(1, ['name' => 'ruflin nicolas']);
$doc->setRouting($routing1);
$type->addDocument($doc);

$doc = new Document(2, ['name' => 'ruflin']);
$doc->setRouting($routing1);
$type->addDocument($doc);
}
$type = new Type($index, 'test');
$doc = new Document(1, ['name' => 'ruflin nicolas']);
$doc->setRouting($routing1);
$type->addDocument($doc);

$doc = new Document(2, ['name' => 'ruflin']);
$doc->setRouting($routing1);
$type->addDocument($doc);

$type = new Type($index2, 'test');
$doc = new Document(1, ['name' => 'ruflin nicolas']);
$doc->setRouting($routing1);
$type->addDocument($doc);

$doc = new Document(2, ['name' => 'ruflin']);
$doc->setRouting($routing1);
$type->addDocument($doc);

$index->refresh();
$index2->refresh();

$response = $index->search('ruflin*');
$this->assertEquals(4, $response->count());
$this->assertEquals(2, $response->count());
$response = $index2->search('ruflin*');
$this->assertEquals(2, $response->count());

$response = $index->search('ruflin*', ['routing' => $routing2]);
$this->assertEquals(0, $response->count());
$response = $index2->search('ruflin*', ['routing' => $routing2]);
$this->assertEquals(0, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());
$response = $index2->search('nicolas');
$this->assertEquals(1, $response->count());

// Route to the wrong document id; should not delete
$response = $index->deleteByQuery(new SimpleQueryString('nicolas'), ['routing' => $routing2]);
$this->assertTrue($response->isOk());

// Route to the wrong document id; should not delete
$response = $index2->deleteByQuery(new SimpleQueryString('nicolas'), ['routing' => $routing2]);
$this->assertTrue($response->isOk());

$index->refresh();
$index2->refresh();

$response = $index->search('ruflin*');
$this->assertEquals(4, $response->count());
$this->assertEquals(2, $response->count());
$response = $index2->search('ruflin*');
$this->assertEquals(2, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());
$response = $index2->search('nicolas');
$this->assertEquals(1, $response->count());

// Delete first document
$response = $index->deleteByQuery(new SimpleQueryString('nicolas'), ['routing' => $routing1]);
$this->assertTrue($response->isOk());
$response = $index2->deleteByQuery(new SimpleQueryString('nicolas'), ['routing' => $routing1]);
$this->assertTrue($response->isOk());

$index->refresh();
$index2->refresh();

// Makes sure, document is deleted
$response = $index->search('ruflin*');
$this->assertEquals(2, $response->count());
$this->assertEquals(1, $response->count());
$response = $index2->search('ruflin*');
$this->assertEquals(1, $response->count());

$response = $index->search('nicolas');
$this->assertEquals(0, $response->count());
$response = $index2->search('nicolas');
$this->assertEquals(0, $response->count());
}

/**
Expand Down
Loading

0 comments on commit f28072d

Please sign in to comment.