@@ -30,7 +30,7 @@ public function test_it_can_acquire_lock(): void
30
30
$ dbConnection = $ this ->initPostgresPdoConnection ();
31
31
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
32
32
33
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
33
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
34
34
35
35
$ this ->assertTrue ($ isLockAcquired );
36
36
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
@@ -43,7 +43,7 @@ public function test_it_can_acquire_lock_with_smallest_lock_id(): void
43
43
$ dbConnection = $ this ->initPostgresPdoConnection ();
44
44
$ postgresLockId = new PostgresLockId (self ::DB_INT64_VALUE_MIN );
45
45
46
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
46
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
47
47
48
48
$ this ->assertTrue ($ isLockAcquired );
49
49
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
@@ -56,7 +56,7 @@ public function test_it_can_acquire_lock_with_biggest_lock_id(): void
56
56
$ dbConnection = $ this ->initPostgresPdoConnection ();
57
57
$ postgresLockId = new PostgresLockId (self ::DB_INT64_VALUE_MAX );
58
58
59
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
59
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
60
60
61
61
$ this ->assertTrue ($ isLockAcquired );
62
62
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
@@ -69,8 +69,8 @@ public function test_it_can_acquire_lock_in_same_connection_only_once(): void
69
69
$ dbConnection = $ this ->initPostgresPdoConnection ();
70
70
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
71
71
72
- $ isLockAcquired1 = $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
73
- $ isLockAcquired2 = $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
72
+ $ isLockAcquired1 = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
73
+ $ isLockAcquired2 = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
74
74
75
75
$ this ->assertTrue ($ isLockAcquired1 );
76
76
$ this ->assertTrue ($ isLockAcquired2 );
@@ -85,8 +85,8 @@ public function test_it_can_acquire_multiple_locks_in_one_connection(): void
85
85
$ postgresLockId1 = $ this ->initPostgresLockId ('test1 ' );
86
86
$ postgresLockId2 = $ this ->initPostgresLockId ('test2 ' );
87
87
88
- $ isLock1Acquired = $ locker ->acquireLock ($ dbConnection , $ postgresLockId1 );
89
- $ isLock2Acquired = $ locker ->acquireLock ($ dbConnection , $ postgresLockId2 );
88
+ $ isLock1Acquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
89
+ $ isLock2Acquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId2 );
90
90
91
91
$ this ->assertTrue ($ isLock1Acquired );
92
92
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId1 );
@@ -101,9 +101,9 @@ public function test_it_cannot_acquire_same_lock_in_two_connections(): void
101
101
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
102
102
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
103
103
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
104
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId );
104
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
105
105
106
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId );
106
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
107
107
108
108
$ this ->assertFalse ($ isLockAcquired );
109
109
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -115,7 +115,7 @@ public function test_it_can_release_lock(): void
115
115
$ locker = $ this ->initLocker ();
116
116
$ dbConnection = $ this ->initPostgresPdoConnection ();
117
117
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
118
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
118
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
119
119
120
120
$ isLockReleased = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
121
121
@@ -128,8 +128,8 @@ public function test_it_can_release_lock_twice_if_acquired_twice(): void
128
128
$ locker = $ this ->initLocker ();
129
129
$ dbConnection = $ this ->initPostgresPdoConnection ();
130
130
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
131
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
132
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId );
131
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
132
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
133
133
134
134
$ isLockReleased1 = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
135
135
$ isLockReleased2 = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
@@ -145,10 +145,10 @@ public function test_it_can_acquire_lock_in_second_connection_after_release(): v
145
145
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
146
146
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
147
147
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
148
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId );
148
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
149
149
$ locker ->releaseLock ($ dbConnection1 , $ postgresLockId );
150
150
151
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId );
151
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
152
152
153
153
$ this ->assertTrue ($ isLockAcquired );
154
154
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection2 , $ postgresLockId );
@@ -161,11 +161,11 @@ public function test_it_cannot_acquire_lock_in_second_connection_after_one_relea
161
161
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
162
162
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
163
163
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
164
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId );
165
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId );
164
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
165
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
166
166
167
167
$ isLockReleased = $ locker ->releaseLock ($ dbConnection1 , $ postgresLockId );
168
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId );
168
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
169
169
170
170
$ this ->assertTrue ($ isLockReleased );
171
171
$ this ->assertFalse ($ isLockAcquired );
@@ -192,7 +192,7 @@ public function test_it_cannot_release_lock_if_acquired_in_other_connection(): v
192
192
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
193
193
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
194
194
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
195
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId );
195
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
196
196
197
197
$ isLockReleased = $ locker ->releaseLock ($ dbConnection2 , $ postgresLockId );
198
198
@@ -207,8 +207,8 @@ public function test_it_can_release_all_locks_in_connection(): void
207
207
$ dbConnection = $ this ->initPostgresPdoConnection ();
208
208
$ postgresLockId1 = $ this ->initPostgresLockId ('test ' );
209
209
$ postgresLockId2 = $ this ->initPostgresLockId ('test2 ' );
210
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId1 );
211
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId2 );
210
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
211
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId2 );
212
212
213
213
$ locker ->releaseAllLocks ($ dbConnection );
214
214
@@ -234,10 +234,10 @@ public function test_it_can_release_all_locks_in_connection_but_keeps_other_lock
234
234
$ postgresLockId2 = $ this ->initPostgresLockId ('test2 ' );
235
235
$ postgresLockId3 = $ this ->initPostgresLockId ('test3 ' );
236
236
$ postgresLockId4 = $ this ->initPostgresLockId ('test4 ' );
237
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId1 );
238
- $ locker ->acquireLock ($ dbConnection1 , $ postgresLockId2 );
239
- $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId3 );
240
- $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId4 );
237
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId1 );
238
+ $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId2 );
239
+ $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId3 );
240
+ $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId4 );
241
241
242
242
$ locker ->releaseAllLocks ($ dbConnection1 );
243
243
@@ -253,7 +253,7 @@ public function test_it_can_acquire_lock_within_transaction(): void
253
253
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
254
254
$ dbConnection ->beginTransaction ();
255
255
256
- $ isLockAcquired = $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
256
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
257
257
258
258
$ this ->assertTrue ($ isLockAcquired );
259
259
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -271,7 +271,7 @@ public function test_it_cannot_acquire_lock_within_transaction_not_in_transactio
271
271
$ dbConnection = $ this ->initPostgresPdoConnection ();
272
272
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
273
273
274
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
274
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
275
275
}
276
276
277
277
public function test_it_cannot_acquire_lock_in_second_connection_if_taken_within_transaction (): void
@@ -281,9 +281,9 @@ public function test_it_cannot_acquire_lock_in_second_connection_if_taken_within
281
281
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
282
282
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
283
283
$ dbConnection1 ->beginTransaction ();
284
- $ locker ->acquireLockWithinTransaction ($ dbConnection1 , $ postgresLockId );
284
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection1 , $ postgresLockId );
285
285
286
- $ isLockAcquired = $ locker ->acquireLock ($ dbConnection2 , $ postgresLockId );
286
+ $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
287
287
288
288
$ this ->assertFalse ($ isLockAcquired );
289
289
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -296,7 +296,7 @@ public function test_it_can_auto_release_lock_acquired_within_transaction_on_com
296
296
$ dbConnection = $ this ->initPostgresPdoConnection ();
297
297
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
298
298
$ dbConnection ->beginTransaction ();
299
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
299
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
300
300
301
301
$ dbConnection ->commit ();
302
302
@@ -310,7 +310,7 @@ public function test_it_can_auto_release_lock_acquired_within_transaction_on_rol
310
310
$ dbConnection = $ this ->initPostgresPdoConnection ();
311
311
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
312
312
$ dbConnection ->beginTransaction ();
313
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
313
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
314
314
315
315
$ dbConnection ->rollBack ();
316
316
@@ -324,7 +324,7 @@ public function test_it_can_auto_release_lock_acquired_within_transaction_on_con
324
324
$ dbConnection = $ this ->initPostgresPdoConnection ();
325
325
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
326
326
$ dbConnection ->beginTransaction ();
327
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
327
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
328
328
329
329
$ dbConnection = null ;
330
330
@@ -337,7 +337,7 @@ public function test_it_cannot_release_lock_acquired_within_transaction(): void
337
337
$ dbConnection = $ this ->initPostgresPdoConnection ();
338
338
$ postgresLockId = $ this ->initPostgresLockId ('test ' );
339
339
$ dbConnection ->beginTransaction ();
340
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
340
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
341
341
342
342
$ isLockReleased = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
343
343
@@ -352,9 +352,9 @@ public function test_it_cannot_release_all_locks_acquired_within_transaction():
352
352
$ dbConnection = $ this ->initPostgresPdoConnection ();
353
353
$ postgresLockId1 = $ this ->initPostgresLockId ('test ' );
354
354
$ postgresLockId2 = $ this ->initPostgresLockId ('test2 ' );
355
- $ locker ->acquireLock ($ dbConnection , $ postgresLockId1 );
355
+ $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
356
356
$ dbConnection ->beginTransaction ();
357
- $ locker ->acquireLockWithinTransaction ($ dbConnection , $ postgresLockId2 );
357
+ $ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId2 );
358
358
359
359
$ locker ->releaseAllLocks ($ dbConnection );
360
360
0 commit comments