5
5
use Sineflow \ElasticsearchBundle \Finder \Finder ;
6
6
use Sineflow \ElasticsearchBundle \Tests \AbstractElasticsearchTestCase ;
7
7
use Sineflow \ElasticsearchBundle \Tests \app \fixture \Acme \FooBundle \Document \Customer ;
8
+ use Sineflow \ElasticsearchBundle \Tests \app \fixture \Acme \FooBundle \Document \Log ;
8
9
9
10
/**
10
11
* Class EntityTrackerSubscriberTest
@@ -19,22 +20,47 @@ public function testPersistWithSeveralBulkOps()
19
20
$ converter = $ this ->getContainer ()->get ('sfes.document_converter ' );
20
21
21
22
$ imWithAliases = $ this ->getIndexManager ('customer ' );
22
- $ imWithAliases ->getConnection ()->setAutocommit (false );
23
23
24
+ // Another index manager on the same connection
25
+ $ imNoAliases = $ this ->getIndexManager ('bar ' );
26
+
27
+ // Make sure both index managers share the same connection object instance
28
+ $ this ->assertSame ($ imWithAliases ->getConnection (), $ imNoAliases ->getConnection ());
29
+
30
+ $ imNoAliases ->getConnection ()->setAutocommit (false );
31
+
32
+ // Index manager on another connection
33
+ $ backupIm = $ this ->getIndexManager ('backup ' );
34
+ $ backupIm ->getConnection ()->setAutocommit (false );
35
+
36
+ // Make sure this index manager has a separate connection manager
37
+ $ this ->assertNotSame ($ imWithAliases ->getConnection (), $ backupIm ->getConnection ());
38
+
39
+
40
+ // Persist raw document - ignored by the subscriber as there's no entity to update
24
41
$ rawCustomer = new Customer ();
25
42
$ rawCustomer ->name = 'firstRaw ' ;
26
43
$ documentArray = $ converter ->convertToArray ($ rawCustomer );
27
44
$ imWithAliases ->persistRaw ('AcmeFooBundle:Customer ' , $ documentArray );
28
45
46
+ // Persist entity - handled by the subscriber
29
47
$ customer = new Customer ();
30
48
$ customer ->name = 'batman ' ;
31
49
$ imWithAliases ->persist ($ customer );
32
50
51
+ // Persist another raw document - ignored by the subscriber as there's no entity to update
33
52
$ secondRawCustomer = new Customer ();
34
53
$ secondRawCustomer ->name = 'secondRaw ' ;
35
54
$ documentArray = $ converter ->convertToArray ($ secondRawCustomer );
36
55
$ imWithAliases ->persistRaw ('AcmeFooBundle:Customer ' , $ documentArray );
37
56
57
+ // Persist an entity to another connection to make sure the subscriber handles the 2 commits independently
58
+ $ log = new Log ();
59
+ $ log ->id = 123 ;
60
+ $ log ->entry = 'test log entry ' ;
61
+ $ backupIm ->persist ($ log );
62
+
63
+ // Persist another entity to the first connection - handled by the subscriber
38
64
$ secondCustomer = new Customer ();
39
65
$ secondCustomer ->id = '555 ' ;
40
66
$ secondCustomer ->name = 'joker ' ;
@@ -45,12 +71,15 @@ public function testPersistWithSeveralBulkOps()
45
71
$ this ->assertNull ($ secondRawCustomer ->id );
46
72
$ this ->assertEquals ('555 ' , $ secondCustomer ->id );
47
73
74
+
48
75
$ imWithAliases ->getConnection ()->commit ();
76
+ $ backupIm ->getConnection ()->commit ();
49
77
50
78
$ this ->assertNull ($ rawCustomer ->id , 'id should not have been set ' );
51
79
$ this ->assertNotNull ($ customer ->id , 'id should have been set ' );
52
80
$ this ->assertNull ($ secondRawCustomer ->id , 'id should not have been set ' );
53
81
$ this ->assertEquals ('555 ' , $ secondCustomer ->id );
82
+ $ this ->assertEquals (123 , $ log ->id );
54
83
55
84
// Get the customer from ES by name
56
85
$ finder = $ this ->getContainer ()->get ('sfes.finder ' );
0 commit comments