PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/test/lib/Elastica/Test/BulkTest.php

http://github.com/ruflin/Elastica
PHP | 708 lines | 510 code | 134 blank | 64 comment | 2 complexity | 8f8049f2ec65e409c6a4da5995f8e0ee MD5 | raw file
  1. <?php
  2. namespace Elastica\Test;
  3. use Elastica\Bulk;
  4. use Elastica\Bulk\Action;
  5. use Elastica\Bulk\Action\AbstractDocument;
  6. use Elastica\Document;
  7. use Elastica\Exception\Bulk\ResponseException;
  8. use Elastica\Exception\NotFoundException;
  9. use Elastica\Filter\Script;
  10. use Elastica\Test\Base as BaseTest;
  11. class BulkTest extends BaseTest
  12. {
  13. /**
  14. * @group functional
  15. */
  16. public function testSend()
  17. {
  18. $index = $this->_createIndex();
  19. $indexName = $index->getName();
  20. $type = $index->getType('bulk_test');
  21. $type2 = $index->getType('bulk_test2');
  22. $client = $index->getClient();
  23. $newDocument1 = $type->createDocument(1, ['name' => 'Mister Fantastic']);
  24. $newDocument2 = new Document(2, ['name' => 'Invisible Woman']);
  25. $newDocument3 = $type->createDocument(3, ['name' => 'The Human Torch']);
  26. $newDocument4 = $type->createDocument(null, ['name' => 'The Thing']);
  27. $newDocument3->setOpType(Document::OP_TYPE_CREATE);
  28. $documents = [
  29. $newDocument1,
  30. $newDocument2,
  31. $newDocument3,
  32. $newDocument4,
  33. ];
  34. $bulk = new Bulk($client);
  35. $bulk->setType($type2);
  36. $bulk->addDocuments($documents);
  37. $actions = $bulk->getActions();
  38. $this->assertInstanceOf('Elastica\Bulk\Action\IndexDocument', $actions[0]);
  39. $this->assertEquals('index', $actions[0]->getOpType());
  40. $this->assertSame($newDocument1, $actions[0]->getDocument());
  41. $this->assertInstanceOf('Elastica\Bulk\Action\IndexDocument', $actions[1]);
  42. $this->assertEquals('index', $actions[1]->getOpType());
  43. $this->assertSame($newDocument2, $actions[1]->getDocument());
  44. $this->assertInstanceOf('Elastica\Bulk\Action\CreateDocument', $actions[2]);
  45. $this->assertEquals('create', $actions[2]->getOpType());
  46. $this->assertSame($newDocument3, $actions[2]->getDocument());
  47. $this->assertInstanceOf('Elastica\Bulk\Action\IndexDocument', $actions[3]);
  48. $this->assertEquals('index', $actions[3]->getOpType());
  49. $this->assertSame($newDocument4, $actions[3]->getDocument());
  50. $data = $bulk->toArray();
  51. $expected = [
  52. ['index' => ['_index' => $indexName, '_type' => 'bulk_test', '_id' => 1]],
  53. ['name' => 'Mister Fantastic'],
  54. ['index' => ['_id' => 2]],
  55. ['name' => 'Invisible Woman'],
  56. ['create' => ['_index' => $indexName, '_type' => 'bulk_test', '_id' => 3]],
  57. ['name' => 'The Human Torch'],
  58. ['index' => ['_index' => $indexName, '_type' => 'bulk_test']],
  59. ['name' => 'The Thing'],
  60. ];
  61. $this->assertEquals($expected, $data);
  62. $expected = '{"index":{"_index":"'.$indexName.'","_type":"bulk_test","_id":1}}
  63. {"name":"Mister Fantastic"}
  64. {"index":{"_id":2}}
  65. {"name":"Invisible Woman"}
  66. {"create":{"_index":"'.$indexName.'","_type":"bulk_test","_id":3}}
  67. {"name":"The Human Torch"}
  68. {"index":{"_index":"'.$indexName.'","_type":"bulk_test"}}
  69. {"name":"The Thing"}
  70. ';
  71. $expected = str_replace(PHP_EOL, "\n", $expected);
  72. $this->assertEquals($expected, (string) str_replace(PHP_EOL, "\n", (string) $bulk));
  73. $response = $bulk->send();
  74. $this->assertInstanceOf('Elastica\Bulk\ResponseSet', $response);
  75. $this->assertTrue($response->isOk());
  76. $this->assertFalse($response->hasError());
  77. foreach ($response as $i => $bulkResponse) {
  78. $this->assertInstanceOf('Elastica\Bulk\Response', $bulkResponse);
  79. $this->assertTrue($bulkResponse->isOk());
  80. $this->assertFalse($bulkResponse->hasError());
  81. $this->assertSame($actions[$i], $bulkResponse->getAction());
  82. }
  83. $type->getIndex()->refresh();
  84. $type2->getIndex()->refresh();
  85. $this->assertEquals(3, $type->count());
  86. $this->assertEquals(1, $type2->count());
  87. $bulk = new Bulk($client);
  88. $bulk->addDocument($newDocument3, Action::OP_TYPE_DELETE);
  89. $data = $bulk->toArray();
  90. $expected = [
  91. ['delete' => ['_index' => $indexName, '_type' => 'bulk_test', '_id' => 3]],
  92. ];
  93. $this->assertEquals($expected, $data);
  94. $bulk->send();
  95. $type->getIndex()->refresh();
  96. $this->assertEquals(2, $type->count());
  97. try {
  98. $type->getDocument(3);
  99. $this->fail('Document #3 should be deleted');
  100. } catch (NotFoundException $e) {
  101. $this->assertTrue(true);
  102. }
  103. }
  104. /**
  105. * @group functional
  106. */
  107. public function testUnicodeBulkSend()
  108. {
  109. $index = $this->_createIndex();
  110. $type = $index->getType('bulk_test');
  111. $type2 = $index->getType('bulk_test2');
  112. $client = $index->getClient();
  113. $newDocument1 = $type->createDocument(1, ['name' => 'Сегодня, я вижу, особенно грустен твой взгляд,']);
  114. $newDocument2 = new Document(2, ['name' => 'И руки особенно тонки, колени обняв.']);
  115. $newDocument3 = $type->createDocument(3, ['name' => 'Послушай: далеко, далеко, на озере Чад / Изысканный бродит жираф.']);
  116. $documents = [
  117. $newDocument1,
  118. $newDocument2,
  119. $newDocument3,
  120. ];
  121. $bulk = new Bulk($client);
  122. $bulk->setType($type2);
  123. $bulk->addDocuments($documents);
  124. $actions = $bulk->getActions();
  125. $this->assertSame($newDocument1, $actions[0]->getDocument());
  126. $this->assertSame($newDocument2, $actions[1]->getDocument());
  127. $this->assertSame($newDocument3, $actions[2]->getDocument());
  128. }
  129. /**
  130. * @group functional
  131. */
  132. public function testSetIndexType()
  133. {
  134. $client = $this->_getClient();
  135. $index = $client->getIndex('index');
  136. $type = $index->getType('type');
  137. $index2 = $client->getIndex('index2');
  138. $type2 = $index2->getType('type2');
  139. $bulk = new Bulk($client);
  140. $this->assertFalse($bulk->hasIndex());
  141. $this->assertFalse($bulk->hasType());
  142. $bulk->setIndex($index);
  143. $this->assertTrue($bulk->hasIndex());
  144. $this->assertFalse($bulk->hasType());
  145. $this->assertEquals('index', $bulk->getIndex());
  146. $bulk->setType($type2);
  147. $this->assertTrue($bulk->hasIndex());
  148. $this->assertTrue($bulk->hasType());
  149. $this->assertEquals('index2', $bulk->getIndex());
  150. $this->assertEquals('type2', $bulk->getType());
  151. $bulk->setType($type);
  152. $this->assertTrue($bulk->hasIndex());
  153. $this->assertTrue($bulk->hasType());
  154. $this->assertEquals('index', $bulk->getIndex());
  155. $this->assertEquals('type', $bulk->getType());
  156. $bulk->setIndex($index2);
  157. $this->assertTrue($bulk->hasIndex());
  158. $this->assertTrue($bulk->hasType());
  159. $this->assertEquals('index2', $bulk->getIndex());
  160. $this->assertEquals('type', $bulk->getType());
  161. }
  162. /**
  163. * @group unit
  164. */
  165. public function testAddActions()
  166. {
  167. $client = $this->_getClient();
  168. $bulk = new Bulk($client);
  169. $action1 = new Action(Action::OP_TYPE_DELETE);
  170. $action1->setIndex('index');
  171. $action1->setType('type');
  172. $action1->setId(1);
  173. $action2 = new Action(Action::OP_TYPE_INDEX);
  174. $action2->setIndex('index');
  175. $action2->setType('type');
  176. $action2->setId(1);
  177. $action2->setSource(['name' => 'Batman']);
  178. $actions = [
  179. $action1,
  180. $action2,
  181. ];
  182. $bulk->addActions($actions);
  183. $getActions = $bulk->getActions();
  184. $this->assertSame($action1, $getActions[0]);
  185. $this->assertSame($action2, $getActions[1]);
  186. }
  187. /**
  188. * @group unit
  189. */
  190. public function testAddRawData()
  191. {
  192. $bulk = new Bulk($this->_getClient());
  193. $rawData = [
  194. ['index' => ['_index' => 'test', '_type' => 'user', '_id' => '1']],
  195. ['user' => ['name' => 'hans']],
  196. ['delete' => ['_index' => 'test', '_type' => 'user', '_id' => '2']],
  197. ['delete' => ['_index' => 'test', '_type' => 'user', '_id' => '3']],
  198. ['create' => ['_index' => 'test', '_type' => 'user', '_id' => '4']],
  199. ['user' => ['name' => 'mans']],
  200. ['delete' => ['_index' => 'test', '_type' => 'user', '_id' => '5']],
  201. ];
  202. $bulk->addRawData($rawData);
  203. $actions = $bulk->getActions();
  204. $this->assertInternalType('array', $actions);
  205. $this->assertEquals(5, count($actions));
  206. $this->assertInstanceOf('Elastica\Bulk\Action', $actions[0]);
  207. $this->assertEquals('index', $actions[0]->getOpType());
  208. $this->assertEquals($rawData[0]['index'], $actions[0]->getMetadata());
  209. $this->assertTrue($actions[0]->hasSource());
  210. $this->assertEquals($rawData[1], $actions[0]->getSource());
  211. $this->assertInstanceOf('Elastica\Bulk\Action', $actions[1]);
  212. $this->assertEquals('delete', $actions[1]->getOpType());
  213. $this->assertEquals($rawData[2]['delete'], $actions[1]->getMetadata());
  214. $this->assertFalse($actions[1]->hasSource());
  215. $this->assertInstanceOf('Elastica\Bulk\Action', $actions[2]);
  216. $this->assertEquals('delete', $actions[2]->getOpType());
  217. $this->assertEquals($rawData[3]['delete'], $actions[2]->getMetadata());
  218. $this->assertFalse($actions[2]->hasSource());
  219. $this->assertInstanceOf('Elastica\Bulk\Action', $actions[3]);
  220. $this->assertEquals('create', $actions[3]->getOpType());
  221. $this->assertEquals($rawData[4]['create'], $actions[3]->getMetadata());
  222. $this->assertTrue($actions[3]->hasSource());
  223. $this->assertEquals($rawData[5], $actions[3]->getSource());
  224. $this->assertInstanceOf('Elastica\Bulk\Action', $actions[4]);
  225. $this->assertEquals('delete', $actions[4]->getOpType());
  226. $this->assertEquals($rawData[6]['delete'], $actions[4]->getMetadata());
  227. $this->assertFalse($actions[4]->hasSource());
  228. }
  229. /**
  230. * @group unit
  231. * @dataProvider invalidRawDataProvider
  232. * @expectedException \Elastica\Exception\InvalidException
  233. */
  234. public function testInvalidRawData($rawData, $failMessage)
  235. {
  236. $bulk = new Bulk($this->_getClient());
  237. $bulk->addRawData($rawData);
  238. $this->fail($failMessage);
  239. }
  240. public function invalidRawDataProvider()
  241. {
  242. return [
  243. [
  244. [
  245. ['index' => ['_index' => 'test', '_type' => 'user', '_id' => '1']],
  246. ['user' => ['name' => 'hans']],
  247. ['user' => ['name' => 'mans']],
  248. ],
  249. 'Two sources for one action',
  250. ],
  251. [
  252. [
  253. ['index' => ['_index' => 'test', '_type' => 'user', '_id' => '1']],
  254. ['user' => ['name' => 'hans']],
  255. ['upsert' => ['_index' => 'test', '_type' => 'user', '_id' => '2']],
  256. ],
  257. 'Invalid optype for action',
  258. ],
  259. [
  260. [
  261. ['user' => ['name' => 'mans']],
  262. ],
  263. 'Source without action',
  264. ],
  265. [
  266. [
  267. [],
  268. ],
  269. 'Empty array',
  270. ],
  271. [
  272. [
  273. 'dummy',
  274. ],
  275. 'String as data',
  276. ],
  277. ];
  278. }
  279. /**
  280. * @group unit
  281. */
  282. public function testCreateAbstractDocumentWithInvalidData()
  283. {
  284. //Wrong class type
  285. try {
  286. $badDocument = new \stdClass();
  287. AbstractDocument::create($badDocument);
  288. $this->fail('Tried to create an abstract document with an object that is not a Document or Script, but no exception was thrown');
  289. } catch (\Exception $e) {
  290. //Excepted exception was thrown.
  291. }
  292. //Try to create document with a script
  293. try {
  294. $script = new Script();
  295. AbstractDocument::create($script, AbstractDocument::OP_TYPE_CREATE);
  296. $this->fail('Tried to create an abstract document with a Script, but no exception was thrown');
  297. } catch (\Exception $e) {
  298. //Excepted exception was thrown.
  299. }
  300. }
  301. /**
  302. * @group functional
  303. */
  304. public function testErrorRequest()
  305. {
  306. $index = $this->_createIndex();
  307. $type = $index->getType('bulk_test');
  308. $client = $index->getClient();
  309. $documents = [
  310. $type->createDocument(1, ['name' => 'Mister Fantastic']),
  311. $type->createDocument(2, ['name' => 'Invisible Woman']),
  312. $type->createDocument(2, ['name' => 'The Human Torch']),
  313. ];
  314. $documents[2]->setOpType(Document::OP_TYPE_CREATE);
  315. $bulk = new Bulk($client);
  316. $bulk->addDocuments($documents);
  317. try {
  318. $bulk->send();
  319. $bulk->fail('3rd document create should produce error');
  320. } catch (ResponseException $e) {
  321. $error = $e->getResponseSet()->getFullError();
  322. $this->assertContains('document_already_exists_exception', $error['type']);
  323. $failures = $e->getFailures();
  324. $this->assertInternalType('array', $failures);
  325. $this->assertArrayHasKey(0, $failures);
  326. }
  327. }
  328. /**
  329. * @group functional
  330. */
  331. public function testRawDocumentDataRequest()
  332. {
  333. $index = $this->_createIndex();
  334. $type = $index->getType('bulk_test');
  335. $client = $index->getClient();
  336. $documents = [
  337. new Document(null, '{"name":"Mister Fantastic"}'),
  338. new Document(null, '{"name":"Invisible Woman"}'),
  339. new Document(null, '{"name":"The Human Torch"}'),
  340. ];
  341. $bulk = new Bulk($client);
  342. $bulk->addDocuments($documents);
  343. $bulk->setType($type);
  344. $expectedJson = '{"index":{}}
  345. {"name":"Mister Fantastic"}
  346. {"index":{}}
  347. {"name":"Invisible Woman"}
  348. {"index":{}}
  349. {"name":"The Human Torch"}
  350. ';
  351. $expectedJson = str_replace(PHP_EOL, "\n", $expectedJson);
  352. $this->assertEquals($expectedJson, $bulk->toString());
  353. $response = $bulk->send();
  354. $this->assertTrue($response->isOk());
  355. $type->getIndex()->refresh();
  356. $response = $type->search();
  357. $this->assertEquals(3, $response->count());
  358. foreach (['Mister', 'Invisible', 'Torch'] as $name) {
  359. $result = $type->search($name);
  360. $this->assertEquals(1, count($result->getResults()));
  361. }
  362. }
  363. /**
  364. * @group functional
  365. */
  366. public function testUpdate()
  367. {
  368. $this->_checkScriptInlineSetting();
  369. $index = $this->_createIndex();
  370. $type = $index->getType('bulk_test');
  371. $client = $index->getClient();
  372. $doc1 = $type->createDocument(1, ['name' => 'John']);
  373. $doc2 = $type->createDocument(2, ['name' => 'Paul']);
  374. $doc3 = $type->createDocument(3, ['name' => 'George']);
  375. $doc4 = $type->createDocument(4, ['name' => 'Ringo']);
  376. $documents = [$doc1, $doc2, $doc3, $doc4];
  377. //index some documents
  378. $bulk = new Bulk($client);
  379. $bulk->setType($type);
  380. $bulk->addDocuments($documents);
  381. $response = $bulk->send();
  382. $this->assertTrue($response->isOk());
  383. $this->assertFalse($response->hasError());
  384. $index->refresh();
  385. //test updating via document
  386. $doc2 = $type->createDocument(2, ['name' => 'The Walrus']);
  387. $bulk = new Bulk($client);
  388. $bulk->setType($type);
  389. $updateAction = new \Elastica\Bulk\Action\UpdateDocument($doc2);
  390. $bulk->addAction($updateAction);
  391. $response = $bulk->send();
  392. $this->assertTrue($response->isOk());
  393. $this->assertFalse($response->hasError());
  394. $index->refresh();
  395. $doc = $type->getDocument(2);
  396. $docData = $doc->getData();
  397. $this->assertEquals('The Walrus', $docData['name']);
  398. //test updating via script
  399. $script = new \Elastica\Script\Script('ctx._source.name += param1;', ['param1' => ' was Paul'], null, 2);
  400. $doc2 = new Document();
  401. $script->setUpsert($doc2);
  402. $updateAction = Action\AbstractDocument::create($script, Action::OP_TYPE_UPDATE);
  403. $bulk = new Bulk($client);
  404. $bulk->setType($type);
  405. $bulk->addAction($updateAction);
  406. $response = $bulk->send();
  407. $this->assertTrue($response->isOk());
  408. $this->assertFalse($response->hasError());
  409. $index->refresh();
  410. $doc2 = $type->getDocument(2);
  411. $this->assertEquals('The Walrus was Paul', $doc2->name);
  412. //test upsert
  413. $script = new \Elastica\Script\Script('ctx._scource.counter += count', ['count' => 1], null, 5);
  414. $doc = new Document('', ['counter' => 1]);
  415. $script->setUpsert($doc);
  416. $updateAction = Action\AbstractDocument::create($script, Action::OP_TYPE_UPDATE);
  417. $bulk = new Bulk($client);
  418. $bulk->setType($type);
  419. $bulk->addAction($updateAction);
  420. $response = $bulk->send();
  421. $this->assertTrue($response->isOk());
  422. $this->assertFalse($response->hasError());
  423. $index->refresh();
  424. $doc = $type->getDocument(5);
  425. $this->assertEquals(1, $doc->counter);
  426. //test doc_as_upsert
  427. $doc = new \Elastica\Document(6, ['test' => 'test']);
  428. $doc->setDocAsUpsert(true);
  429. $updateAction = Action\AbstractDocument::create($doc, Action::OP_TYPE_UPDATE);
  430. $bulk = new Bulk($client);
  431. $bulk->setType($type);
  432. $bulk->addAction($updateAction);
  433. $response = $bulk->send();
  434. $this->assertTrue($response->isOk());
  435. $this->assertFalse($response->hasError());
  436. $index->refresh();
  437. $doc = $type->getDocument(6);
  438. $this->assertEquals('test', $doc->test);
  439. //test doc_as_upsert with set of documents (use of addDocuments)
  440. $doc1 = new \Elastica\Document(7, ['test' => 'test1']);
  441. $doc1->setDocAsUpsert(true);
  442. $doc2 = new \Elastica\Document(8, ['test' => 'test2']);
  443. $doc2->setDocAsUpsert(true);
  444. $docs = [$doc1, $doc2];
  445. $bulk = new Bulk($client);
  446. $bulk->setType($type);
  447. $bulk->addDocuments($docs, \Elastica\Bulk\Action::OP_TYPE_UPDATE);
  448. $response = $bulk->send();
  449. $this->assertTrue($response->isOk());
  450. $this->assertFalse($response->hasError());
  451. $index->refresh();
  452. $doc = $type->getDocument(7);
  453. $this->assertEquals('test1', $doc->test);
  454. $doc = $type->getDocument(8);
  455. $this->assertEquals('test2', $doc->test);
  456. //test updating via document with json string as data
  457. $doc3 = $type->createDocument(2);
  458. $bulk = new Bulk($client);
  459. $bulk->setType($type);
  460. $doc3->setData('{"name" : "Paul it is"}');
  461. $updateAction = new \Elastica\Bulk\Action\UpdateDocument($doc3);
  462. $bulk->addAction($updateAction);
  463. $response = $bulk->send();
  464. $this->assertTrue($response->isOk());
  465. $this->assertFalse($response->hasError());
  466. $index->refresh();
  467. $doc = $type->getDocument(2);
  468. $docData = $doc->getData();
  469. $this->assertEquals('Paul it is', $docData['name']);
  470. $index->delete();
  471. }
  472. /**
  473. * @group unit
  474. */
  475. public function testGetPath()
  476. {
  477. $client = $this->_getClient();
  478. $bulk = new Bulk($client);
  479. $this->assertEquals('_bulk', $bulk->getPath());
  480. $indexName = 'testIndex';
  481. $bulk->setIndex($indexName);
  482. $this->assertEquals($indexName.'/_bulk', $bulk->getPath());
  483. $typeName = 'testType';
  484. $bulk->setType($typeName);
  485. $this->assertEquals($indexName.'/'.$typeName.'/_bulk', $bulk->getPath());
  486. }
  487. /**
  488. * @group functional
  489. */
  490. public function testRetry()
  491. {
  492. $index = $this->_createIndex();
  493. $type = $index->getType('bulk_test');
  494. $client = $index->getClient();
  495. $doc1 = $type->createDocument(1, ['name' => 'Mister Fantastic']);
  496. $doc1->setOpType(Action::OP_TYPE_UPDATE);
  497. $doc1->setRetryOnConflict(5);
  498. $bulk = new Bulk($client);
  499. $bulk->addDocument($doc1);
  500. $actions = $bulk->getActions();
  501. $metadata = $actions[0]->getMetadata();
  502. $this->assertEquals(5, $metadata[ '_retry_on_conflict' ]);
  503. $script = new \Elastica\Script\Script('');
  504. $script->setRetryOnConflict(5);
  505. $bulk = new Bulk($client);
  506. $bulk->addScript($script);
  507. $actions = $bulk->getActions();
  508. $metadata = $actions[0]->getMetadata();
  509. $this->assertEquals(5, $metadata[ '_retry_on_conflict' ]);
  510. }
  511. /**
  512. * @group unit
  513. */
  514. public function testSetShardTimeout()
  515. {
  516. $bulk = new Bulk($this->_getClient());
  517. $this->assertInstanceOf('Elastica\Bulk', $bulk->setShardTimeout(10));
  518. }
  519. /**
  520. * @group unit
  521. */
  522. public function testSetRequestParam()
  523. {
  524. $bulk = new Bulk($this->_getClient());
  525. $this->assertInstanceOf('Elastica\Bulk', $bulk->setRequestParam('key', 'value'));
  526. }
  527. /**
  528. * @group benchmark
  529. */
  530. public function testMemoryUsage()
  531. {
  532. $type = $this->_createIndex()->getType('test');
  533. $data = [
  534. 'text1' => 'Very long text for a string',
  535. 'text2' => 'But this is not very long',
  536. 'text3' => 'random or not random?',
  537. ];
  538. $startMemory = memory_get_usage();
  539. for ($n = 1; $n < 10; ++$n) {
  540. $docs = [];
  541. for ($i = 1; $i <= 3000; ++$i) {
  542. $docs[] = new Document(uniqid(), $data);
  543. }
  544. $type->addDocuments($docs);
  545. $docs = [];
  546. }
  547. unset($docs);
  548. $endMemory = memory_get_usage();
  549. $this->markTestIncomplete('Failed asserting that 2.2414096568375803 is less than 1.3.');
  550. $this->assertLessThan(1.3, $endMemory / $startMemory);
  551. }
  552. /**
  553. * @group unit
  554. */
  555. public function testHasIndex()
  556. {
  557. $client = $this->_getClient();
  558. $bulk = new Bulk($client);
  559. $this->assertFalse($bulk->hasIndex());
  560. $bulk->setIndex('unittest');
  561. $this->assertTrue($bulk->hasIndex());
  562. }
  563. /**
  564. * @group unit
  565. */
  566. public function testHasType()
  567. {
  568. $client = $this->_getClient();
  569. $bulk = new Bulk($client);
  570. $this->assertFalse($bulk->hasType());
  571. $bulk->setType('unittest');
  572. $this->assertTrue($bulk->hasType());
  573. }
  574. }