public function testAddActionWithRetryOnConflict() { $id = 'my-id'; $retryOnConflict = 2; $doc = array('my' => 'doc'); $serializedDoc = 'my-doc'; $action = array(AbstractBulkUpdateRequest::BULK_ACTION => array('_id' => $id, '_index' => self::INDEX, '_type' => self::TYPE, '_retry_on_conflict' => $retryOnConflict)); $this->serializer->expects($this->once())->method('serialize')->with($doc, array())->willReturn($serializedDoc); $this->request->addDocument($doc, $id, $retryOnConflict); $expected = json_encode($action) . AbstractBulkUpdateRequest::LINE_BREAK . '{"doc":' . $serializedDoc . '}' . AbstractBulkUpdateRequest::LINE_BREAK; $result = $this->request->getBody(); $this->assertSame($expected, $result); }
public function testBulkUpdateThreeMissingDocs() { $this->createIndex(); $doc1 = array('name' => 'test1' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $doc2 = array('name' => 'test2' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $doc3 = array('name' => 'test3' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $bulkUpdateRequest = new BulkUpdateRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $bulkUpdateRequest->addDocument($doc1, 'doc1'); $bulkUpdateRequest->addDocument($doc2, 'doc2'); $bulkUpdateRequest->addDocument($doc3, 'doc3'); /** @var BulkResponse $response */ $response = $this->getClient()->send($bulkUpdateRequest); $this->assertGreaterThanOrEqual(0, $response->took()); $items = $response->getItems(); $this->assertTrue(is_array($items)); $this->assertCount(3, $items); foreach ($items as $key => $item) { $this->assertArrayHasKey(AbstractBulkUpdateRequest::BULK_ACTION, $item); $this->assertSame(ES_INDEX, $item[AbstractBulkUpdateRequest::BULK_ACTION]['_index']); $this->assertSame(self::TYPE, $item[AbstractBulkUpdateRequest::BULK_ACTION]['_type']); $this->assertContains('[' . $item[AbstractBulkUpdateRequest::BULK_ACTION]['_id'] . ']: document missing', $item[AbstractBulkUpdateRequest::BULK_ACTION]['error']); } }