|
2 | 2 |
|
3 | 3 | namespace Sineflow\ElasticsearchBundle\Tests\Functional\Subscriber;
|
4 | 4 |
|
| 5 | +use Sineflow\ElasticsearchBundle\Exception\BulkRequestException; |
5 | 6 | use Sineflow\ElasticsearchBundle\Finder\Finder;
|
6 | 7 | use Sineflow\ElasticsearchBundle\Result\DocumentConverter;
|
7 | 8 | use Sineflow\ElasticsearchBundle\Tests\AbstractElasticsearchTestCase;
|
|
13 | 14 | */
|
14 | 15 | class EntityTrackerSubscriberTest extends AbstractElasticsearchTestCase
|
15 | 16 | {
|
| 17 | + /** |
| 18 | + * Test executing 2 separate bulk requests, where there's an error in the first one, |
| 19 | + * to make sure the subscriber properly keeps track of bulk request items. |
| 20 | + */ |
| 21 | + public function testTwoBulkRequestWithErrorInFirstOne() |
| 22 | + { |
| 23 | + $imWithAliases = $this->getIndexManager('customer'); |
| 24 | + $customer1 = new Customer(); |
| 25 | + $customer1->name = 'batman'; |
| 26 | + $customer1->setActive('invalid value'); |
| 27 | + $customer2 = new Customer(); |
| 28 | + $customer2->name = 'robin'; |
| 29 | + $imWithAliases->persist($customer1); |
| 30 | + $imWithAliases->persist($customer2); |
| 31 | + try { |
| 32 | + $imWithAliases->getConnection()->commit(); |
| 33 | + } catch (BulkRequestException $e) { |
| 34 | + // ignore the exception |
| 35 | + } |
| 36 | + |
| 37 | + $customer3 = new Customer(); |
| 38 | + $customer3->name = 'superman'; |
| 39 | + $imWithAliases->persist($customer3); |
| 40 | + $imWithAliases->getConnection()->commit(); |
| 41 | + |
| 42 | + $this->assertNull($customer1->id, 'id should not have been set'); |
| 43 | + $this->assertNotNull($customer2->id, 'id should have been set'); |
| 44 | + $this->assertNotNull($customer3->id, 'id should have been set'); |
| 45 | + |
| 46 | + // Make sure that the correct id was assigned to the object, not the id of another customer |
| 47 | + // Get the customer from ES by name |
| 48 | + $finder = $this->getContainer()->get(Finder::class); |
| 49 | + |
| 50 | + $docs = $finder->find(['AcmeFooBundle:Customer'], ['query' => ['match' => ['name' => 'robin']]]); |
| 51 | + $this->assertCount(1, $docs); |
| 52 | + $retrievedCustomer2 = $docs->current(); |
| 53 | + $this->assertEquals($customer2->id, $retrievedCustomer2->id); |
| 54 | + |
| 55 | + $docs = $finder->find(['AcmeFooBundle:Customer'], ['query' => ['match' => ['name' => 'superman']]]); |
| 56 | + $this->assertCount(1, $docs); |
| 57 | + $retrievedCustomer3 = $docs->current(); |
| 58 | + $this->assertEquals($customer3->id, $retrievedCustomer3->id); |
| 59 | + } |
| 60 | + |
16 | 61 | /**
|
17 | 62 | * Test populating persisted entity ids after a bulk operation with several operations
|
18 | 63 | */
|
|
0 commit comments