Skip to content

Commit

Permalink
Merge pull request #11 from gaobinzhan/master
Browse files Browse the repository at this point in the history
feat: testing
  • Loading branch information
kiss291323003 authored Oct 19, 2020
2 parents d7cdab7 + decf353 commit 09b7a0a
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 20 deletions.
11 changes: 6 additions & 5 deletions tests/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ function test()
{
$bean = new Create();
$time = time();
$bean->setIndex('my-index-'.$time);
$bean->setIndex('my-index-' . $time);
$bean->setType('my-type');
$bean->setId('my-id-'.$time);
$bean->setBody(['test-field' => $time]);
$bean->setId('my-id-' . $time);
$bean->setBody(['test-field' => 'abd']);
$response = $this->getElasticSearch()->client()->create($bean)->getBody();
$response = json_decode($response,true);
$this->assertEquals('created',$response['result']);
$response = json_decode($response, true);
var_dump('------------create', $response);
$this->assertEquals('created', $response['result']);
}
}
11 changes: 11 additions & 0 deletions tests/ExistsSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
namespace EasySwoole\ElasticSearch\Tests;


use EasySwoole\ElasticSearch\RequestBean\Create;
use EasySwoole\ElasticSearch\RequestBean\ExistsSource;

class ExistsSourceTest extends Base
{
public function test()
{

$bean = new Create();
$time = time();
$bean->setIndex('my-index');
$bean->setType('my-type');
$bean->setId('my-id');
$bean->setBody(['test-field' => 'abd']);
$this->getElasticSearch()->client()->create($bean)->getBody();


$bean = new ExistsSource();
$bean->setIndex('my-index');
$bean->setId('my-id');
Expand Down
1 change: 1 addition & 0 deletions tests/GetSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function test()
$bean->setId('my-id');
$response = $this->getElasticSearch()->client()->getSource($bean)->getBody();
$response = json_decode($response, true);
var_dump('--------get source', $response);
$this->assertEquals('abd', $response['test-field']);
}
}
1 change: 1 addition & 0 deletions tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function test()
$bean->setBody(['test-field' => '测试' . $time]);
$response = $this->getElasticSearch()->client()->index($bean)->getBody();
$response = json_decode($response, true);
var_dump('--------index', $response);
$this->assertEquals('created', $response['result']);
}
}
4 changes: 2 additions & 2 deletions tests/Indices/PutSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function test()
$bean->setBody([
'settings' => [
'index.refresh_interval' => '2s',
//"index.blocks.write" => false
// "index.blocks.write" => true
]
]);
$response = $this->getElasticSearch()->client()->indices()->putSettings($bean)->getBody();
$response = json_decode($response, true);
//print_r($response);
var_dump('----------put settings', $response);
$this->assertArrayNotHasKey('error', $response);
}
}
33 changes: 27 additions & 6 deletions tests/Indices/ShrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,47 @@
namespace EasySwoole\ElasticSearch\Tests\Indices;


use EasySwoole\ElasticSearch\RequestBean\Indices\Delete;
use EasySwoole\ElasticSearch\RequestBean\Indices\Create;
use EasySwoole\ElasticSearch\RequestBean\Indices\Shrink;
use EasySwoole\ElasticSearch\Tests\Base;

class ShrinkTest extends Base
{
public function test()
{

$bean = new Delete();
$bean->setIndex('my_source_index');
$this->getElasticSearch()->client()->indices()->delete($bean)->getBody();

$bean = new Create();
$bean->setIndex('my_source_index');
$bean->setBody([
'settings' => [
"index.number_of_shards" => 2,
// "index.number_of_replicas" => 1,
// "index.routing.allocation.require._name" => "shrink_node_name",
"index.blocks.write" => true
]]);
$response = $this->getElasticSearch()->client()->indices()->create($bean)->getBody();
var_dump($response);
$this->assertArrayNotHasKey('error', json_decode($response, true));

$bean = new Shrink();
$bean->setIndex('my-index');
$bean->setTarget('my_target_index');
$bean->setIndex('my_source_index');
$bean->setTarget('my_target_index' . time());
$bean->setBody([
'settings' => [
'index.number_of_replicas' => 1,
'index.number_of_shards' => 1,
'index.codec' => 'best_compression'
"index.number_of_replicas" => 1,
"index.number_of_shards" => 2,
"index.codec" => "best_compression"
]
]);
$response = $this->getElasticSearch()->client()->indices()->shrink($bean)->getBody();
$response = json_decode($response, true);
//print_r($response);
var_dump('------------------shrink test');
var_dump($response);
$this->assertArrayNotHasKey('error', $response);
}
}
32 changes: 28 additions & 4 deletions tests/Indices/SplitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,48 @@
namespace EasySwoole\ElasticSearch\Tests\Indices;


use EasySwoole\ElasticSearch\RequestBean\Indices\Create;
use EasySwoole\ElasticSearch\RequestBean\Indices\Delete;
use EasySwoole\ElasticSearch\RequestBean\Indices\Split;
use EasySwoole\ElasticSearch\Tests\Base;

class SplitTest extends Base
{
public function test()
{

$bean = new Delete();
$bean->setIndex('my_source_index');
$this->getElasticSearch()->client()->indices()->delete($bean)->getBody();

$bean = new Create();
$bean->setIndex('my_source_index');
$bean->setBody([
'settings' => [
"index.number_of_shards" => 1,
// "index.number_of_replicas" => 1,
// "index.routing.allocation.require._name" => "shrink_node_name",
"index.blocks.write" => true
]]);
$response = $this->getElasticSearch()->client()->indices()->create($bean)->getBody();
var_dump($response);
$this->assertArrayNotHasKey('error', json_decode($response, true));

$bean = new Split();
$bean->setIndex('my-index');
$bean->setTarget('my-target-index-1');
$bean->setIndex('my_source_index');
$bean->setTarget('my-target-index-' . time());
$bean->setBody([
"settings" => [
"index.number_of_shards" => 3
"index.number_of_shards" => 2,
// "index.blocks.write" => true
]
]);


$response = $this->getElasticSearch()->client()->indices()->split($bean)->getBody();
$response = json_decode($response, true);
//print_r($response);
var_dump('--------------split');
var_dump($response);
$this->assertArrayNotHasKey('error', $response);
}
}
11 changes: 10 additions & 1 deletion tests/Indices/UpdateAliasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
namespace EasySwoole\ElasticSearch\Tests\Indices;


use EasySwoole\ElasticSearch\RequestBean\Create;
use EasySwoole\ElasticSearch\RequestBean\Indices\UpdateAliases;
use EasySwoole\ElasticSearch\Tests\Base;

class UpdateAliasesTest extends Base
{
public function test()
{

$bean = new Create();
$bean->setIndex('my-index-1');
$bean->setType('my-type');
$bean->setId('my-id-1');
$bean->setBody(['test-field' => 'abd']);
$this->getElasticSearch()->client()->create($bean)->getBody();

$bean = new UpdateAliases();
$bean->setBody(
[
Expand All @@ -26,7 +35,7 @@ public function test()
);
$response = $this->getElasticSearch()->client()->indices()->updateAliases($bean)->getBody();
$response = json_decode($response, true);
//print_r($response);
var_dump('-----------update alias', $response);
$this->assertArrayNotHasKey('error', $response);
}
}
14 changes: 12 additions & 2 deletions tests/Ingest/SimulateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ public function test()
{
$bean = new Simulate();
$bean->setId('my-pipeline-id');
$response=$this->getElasticSearch()->client()->ingest()->simulate($bean)->getBody();
print_r($response);
$bean->setBody([
'pipeline' => [
'description' => '_description'
],
'docs' => [
['_index' => 'my-index', '_id' => 'id', '_source' => ['foo' => 'bar']]
]
]);
$response = $this->getElasticSearch()->client()->ingest()->simulate($bean)->getBody();
$response = json_decode($response, true);
var_dump('-----------simulate');
var_dump($response);
$this->assertArrayNotHasKey('error', $response);
}
}
2 changes: 2 additions & 0 deletions tests/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use EasySwoole\ElasticSearch\RequestBean\Update;

//参考文档
//https://www.elastic.co/guide/cn/elasticsearch/guide/current/partial-updates.html
class UpdateTest extends Base
Expand All @@ -27,6 +28,7 @@ public function test()
]);
$response = $this->getElasticSearch()->client()->update($bean)->getBody();
$response = json_decode($response, true);
var_dump('--------update', $response);
$this->assertIsArray($response);
$this->assertArrayHasKey('_shards', $response);
}
Expand Down

0 comments on commit 09b7a0a

Please sign in to comment.