summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php181
1 files changed, 131 insertions, 50 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php
index 3396fe86..c3ff15bc 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/BulkTest.php
@@ -1,24 +1,24 @@
<?php
-
namespace Elastica\Test;
use Elastica\Bulk;
use Elastica\Bulk\Action;
-use Elastica\Client;
+use Elastica\Bulk\Action\AbstractDocument;
use Elastica\Document;
use Elastica\Exception\Bulk\ResponseException;
-use Elastica\Exception\InvalidException;
use Elastica\Exception\NotFoundException;
-use Elastica\Test\Base as BaseTest;
-use Elastica\Bulk\Action\AbstractDocument;
use Elastica\Filter\Script;
+use Elastica\Test\Base as BaseTest;
class BulkTest extends BaseTest
{
-
+ /**
+ * @group functional
+ */
public function testSend()
{
$index = $this->_createIndex();
+ $indexName = $index->getName();
$type = $index->getType('bulk_test');
$type2 = $index->getType('bulk_test2');
$client = $index->getClient();
@@ -28,14 +28,13 @@ class BulkTest extends BaseTest
$newDocument3 = $type->createDocument(3, array('name' => 'The Human Torch'));
$newDocument4 = $type->createDocument(null, array('name' => 'The Thing'));
- $newDocument1->setPercolate('*');
$newDocument3->setOpType(Document::OP_TYPE_CREATE);
$documents = array(
$newDocument1,
$newDocument2,
$newDocument3,
- $newDocument4
+ $newDocument4,
);
$bulk = new Bulk($client);
@@ -63,29 +62,29 @@ class BulkTest extends BaseTest
$data = $bulk->toArray();
$expected = array(
- array('index' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 1, '_percolate' => '*')),
+ array('index' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 1)),
array('name' => 'Mister Fantastic'),
array('index' => array('_id' => 2)),
array('name' => 'Invisible Woman'),
- array('create' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 3)),
+ array('create' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 3)),
array('name' => 'The Human Torch'),
- array('index' => array('_index' => 'elastica_test', '_type' => 'bulk_test')),
+ array('index' => array('_index' => $indexName, '_type' => 'bulk_test')),
array('name' => 'The Thing'),
);
$this->assertEquals($expected, $data);
- $expected = '{"index":{"_index":"elastica_test","_type":"bulk_test","_id":1,"_percolate":"*"}}
+ $expected = '{"index":{"_index":"'.$indexName.'","_type":"bulk_test","_id":1}}
{"name":"Mister Fantastic"}
{"index":{"_id":2}}
{"name":"Invisible Woman"}
-{"create":{"_index":"elastica_test","_type":"bulk_test","_id":3}}
+{"create":{"_index":"'.$indexName.'","_type":"bulk_test","_id":3}}
{"name":"The Human Torch"}
-{"index":{"_index":"elastica_test","_type":"bulk_test"}}
+{"index":{"_index":"'.$indexName.'","_type":"bulk_test"}}
{"name":"The Thing"}
';
$expected = str_replace(PHP_EOL, "\n", $expected);
- $this->assertEquals($expected, (string)str_replace(PHP_EOL, "\n", (string)$bulk));
+ $this->assertEquals($expected, (string) str_replace(PHP_EOL, "\n", (string) $bulk));
$response = $bulk->send();
@@ -107,14 +106,13 @@ class BulkTest extends BaseTest
$this->assertEquals(3, $type->count());
$this->assertEquals(1, $type2->count());
-
$bulk = new Bulk($client);
$bulk->addDocument($newDocument3, Action::OP_TYPE_DELETE);
$data = $bulk->toArray();
$expected = array(
- array('delete' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 3)),
+ array('delete' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 3)),
);
$this->assertEquals($expected, $data);
@@ -132,6 +130,9 @@ class BulkTest extends BaseTest
}
}
+ /**
+ * @group functional
+ */
public function testUnicodeBulkSend()
{
$index = $this->_createIndex();
@@ -146,7 +147,7 @@ class BulkTest extends BaseTest
$documents = array(
$newDocument1,
$newDocument2,
- $newDocument3
+ $newDocument3,
);
$bulk = new Bulk($client);
@@ -160,9 +161,12 @@ class BulkTest extends BaseTest
$this->assertSame($newDocument3, $actions[2]->getDocument());
}
+ /**
+ * @group functional
+ */
public function testSetIndexType()
{
- $client = new Client();
+ $client = $this->_getClient();
$index = $client->getIndex('index');
$type = $index->getType('type');
@@ -198,9 +202,12 @@ class BulkTest extends BaseTest
$this->assertEquals('type', $bulk->getType());
}
+ /**
+ * @group unit
+ */
public function testAddActions()
{
- $client = new Client();
+ $client = $this->_getClient();
$bulk = new Bulk($client);
$action1 = new Action(Action::OP_TYPE_DELETE);
@@ -216,7 +223,7 @@ class BulkTest extends BaseTest
$actions = array(
$action1,
- $action2
+ $action2,
);
$bulk->addActions($actions);
@@ -227,6 +234,9 @@ class BulkTest extends BaseTest
$this->assertSame($action2, $getActions[1]);
}
+ /**
+ * @group unit
+ */
public function testAddRawData()
{
$bulk = new Bulk($this->_getClient());
@@ -277,6 +287,7 @@ class BulkTest extends BaseTest
}
/**
+ * @group unit
* @dataProvider invalidRawDataProvider
* @expectedException \Elastica\Exception\InvalidException
*/
@@ -298,7 +309,7 @@ class BulkTest extends BaseTest
array('user' => array('name' => 'hans')),
array('user' => array('name' => 'mans')),
),
- 'Two sources for one action'
+ 'Two sources for one action',
),
array(
array(
@@ -306,29 +317,32 @@ class BulkTest extends BaseTest
array('user' => array('name' => 'hans')),
array('upsert' => array('_index' => 'test', '_type' => 'user', '_id' => '2')),
),
- 'Invalid optype for action'
+ 'Invalid optype for action',
),
array(
array(
array('user' => array('name' => 'mans')),
),
- 'Source without action'
+ 'Source without action',
),
array(
array(
array(),
),
- 'Empty array'
+ 'Empty array',
),
array(
array(
'dummy',
),
- 'String as data'
- )
+ 'String as data',
+ ),
);
}
+ /**
+ * @group unit
+ */
public function testCreateAbstractDocumentWithInvalidData()
{
//Wrong class type
@@ -350,6 +364,9 @@ class BulkTest extends BaseTest
}
}
+ /**
+ * @group functional
+ */
public function testErrorRequest()
{
$index = $this->_createIndex();
@@ -379,6 +396,9 @@ class BulkTest extends BaseTest
}
}
+ /**
+ * @group functional
+ */
public function testRawDocumentDataRequest()
{
$index = $this->_createIndex();
@@ -413,13 +433,14 @@ class BulkTest extends BaseTest
$response = $type->search();
$this->assertEquals(3, $response->count());
- foreach (array("Mister", "Invisible", "Torch") as $name) {
+ foreach (array('Mister', 'Invisible', 'Torch') as $name) {
$result = $type->search($name);
$this->assertEquals(1, count($result->getResults()));
}
}
/**
+ * @group functional
* @dataProvider udpDataProvider
*/
public function testUdp($clientConfig, $host, $port, $shouldFail = false)
@@ -427,7 +448,7 @@ class BulkTest extends BaseTest
if (!function_exists('socket_create')) {
$this->markTestSkipped('Function socket_create() does not exist.');
}
- $client = new Client($clientConfig);
+ $client = $this->_getClient($clientConfig);
$index = $client->getIndex('elastica_test');
$index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
$type = $index->getType('udp_test');
@@ -467,6 +488,9 @@ class BulkTest extends BaseTest
}
}
+ /**
+ * @group functional
+ */
public function testUpdate()
{
$index = $this->_createIndex();
@@ -599,6 +623,9 @@ class BulkTest extends BaseTest
$index->delete();
}
+ /**
+ * @group unit
+ */
public function testGetPath()
{
$client = $this->_getClient();
@@ -609,13 +636,16 @@ class BulkTest extends BaseTest
$indexName = 'testIndex';
$bulk->setIndex($indexName);
- $this->assertEquals($indexName . '/_bulk', $bulk->getPath());
+ $this->assertEquals($indexName.'/_bulk', $bulk->getPath());
$typeName = 'testType';
$bulk->setType($typeName);
- $this->assertEquals($indexName . '/' . $typeName . '/_bulk', $bulk->getPath());
+ $this->assertEquals($indexName.'/'.$typeName.'/_bulk', $bulk->getPath());
}
+ /**
+ * @group functional
+ */
public function testRetry()
{
$index = $this->_createIndex();
@@ -634,7 +664,7 @@ class BulkTest extends BaseTest
$metadata = $actions[0]->getMetadata();
$this->assertEquals(5, $metadata[ '_retry_on_conflict' ]);
- $script = new \Elastica\Script( '' );
+ $script = new \Elastica\Script('');
$script->setRetryOnConflict(5);
$bulk = new Bulk($client);
@@ -646,65 +676,116 @@ class BulkTest extends BaseTest
$this->assertEquals(5, $metadata[ '_retry_on_conflict' ]);
}
+ /**
+ * @group unit
+ */
+ public function testSetShardTimeout()
+ {
+ $bulk = new Bulk($this->_getClient());
+ $this->assertInstanceOf('Elastica\Bulk', $bulk->setShardTimeout(10));
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetRequestParam()
+ {
+ $bulk = new Bulk($this->_getClient());
+ $this->assertInstanceOf('Elastica\Bulk', $bulk->setRequestParam('key', 'value'));
+ }
+
+ /**
+ * @group benchmark
+ */
+ public function testMemoryUsage()
+ {
+ $type = $this->_createIndex()->getType('test');
+
+ $data = array(
+ 'text1' => 'Very long text for a string',
+ 'text2' => 'But this is not very long',
+ 'text3' => 'random or not random?',
+ );
+
+ $startMemory = memory_get_usage();
+
+ for ($n = 1; $n < 10; $n++) {
+ $docs = array();
+
+ for ($i = 1; $i <= 3000; $i++) {
+ $docs[] = new Document(uniqid(), $data);
+ }
+
+ $type->addDocuments($docs);
+ $docs = array();
+ }
+
+ unset($docs);
+
+ $endMemory = memory_get_usage();
+
+ $this->assertLessThan(1.3, $endMemory / $startMemory);
+ }
+
public function udpDataProvider()
{
return array(
array(
array(),
null,
- null
+ null,
),
array(
array(),
- 'localhost',
- null
+ $this->_getHost(),
+ null,
),
array(
array(),
null,
- 9700
+ 9700,
),
array(
array(),
- 'localhost',
- 9700
+ $this->_getHost(),
+ 9700,
),
array(
array(
'udp' => array(
- 'host' => 'localhost',
+ 'host' => $this->_getHost(),
'port' => 9700,
- )
+ ),
),
null,
- null
+ null,
),
array(
array(
'udp' => array(
- 'host' => 'localhost',
+ 'host' => $this->_getHost(),
'port' => 9800,
- )
+ ),
),
- 'localhost',
- 9700
+ $this->_getHost(),
+ 9700,
),
array(
array(
'udp' => array(
- 'host' => 'localhost',
+ 'host' => $this->_getHost(),
'port' => 9800,
- )
+ ),
),
null,
null,
- true
+ true,
),
array(
array(),
- 'localhost',
+ $this->_getHost(),
9800,
- true
+ true,
),
);
}