@@ -24,34 +24,34 @@ final class PostgresAdvisoryLockerTest extends AbstractIntegrationTestCase
24
24
private const DB_INT32_VALUE_MIN = -2_147_483_648 ;
25
25
private const DB_INT32_VALUE_MAX = 2_147_483_647 ;
26
26
27
- public function testItCanAcquireLock (): void
27
+ public function testItCanTryAcquireLockWithinSession (): void
28
28
{
29
29
$ locker = $ this ->initLocker ();
30
30
$ dbConnection = $ this ->initPostgresPdoConnection ();
31
31
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
32
32
33
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
33
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
34
34
35
35
$ this ->assertTrue ($ isLockAcquired );
36
36
$ this ->assertPgAdvisoryLocksCount (1 );
37
37
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
38
38
}
39
39
40
- #[DataProvider('provideItCanAcquireLockFromIntKeysCornerCasesData ' )]
41
- public function testItCanAcquireLockFromIntKeysCornerCases (): void
40
+ #[DataProvider('provideItCanTryAcquireLockFromIntKeysCornerCasesData ' )]
41
+ public function testItCanTryAcquireLockFromIntKeysCornerCases (): void
42
42
{
43
43
$ locker = $ this ->initLocker ();
44
44
$ dbConnection = $ this ->initPostgresPdoConnection ();
45
45
$ postgresLockId = PostgresLockId::fromIntKeys (self ::DB_INT32_VALUE_MIN , 0 );
46
46
47
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
47
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
48
48
49
49
$ this ->assertTrue ($ isLockAcquired );
50
50
$ this ->assertPgAdvisoryLocksCount (1 );
51
51
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
52
52
}
53
53
54
- public static function provideItCanAcquireLockFromIntKeysCornerCasesData (): array
54
+ public static function provideItCanTryAcquireLockFromIntKeysCornerCasesData (): array
55
55
{
56
56
return [
57
57
'min class_id ' => [
@@ -73,30 +73,30 @@ public static function provideItCanAcquireLockFromIntKeysCornerCasesData(): arra
73
73
];
74
74
}
75
75
76
- public function testItCanAcquireLockInSameConnectionOnlyOnce (): void
76
+ public function testItCanTryAcquireLockInSameConnectionOnlyOnce (): void
77
77
{
78
78
$ locker = $ this ->initLocker ();
79
79
$ dbConnection = $ this ->initPostgresPdoConnection ();
80
80
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
81
81
82
- $ isLockAcquired1 = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
83
- $ isLockAcquired2 = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
82
+ $ isLockAcquired1 = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
83
+ $ isLockAcquired2 = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
84
84
85
85
$ this ->assertTrue ($ isLockAcquired1 );
86
86
$ this ->assertTrue ($ isLockAcquired2 );
87
87
$ this ->assertPgAdvisoryLocksCount (1 );
88
88
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection , $ postgresLockId );
89
89
}
90
90
91
- public function testItCanAcquireMultipleLocksInOneConnection (): void
91
+ public function testItCanTryAcquireMultipleLocksInOneConnection (): void
92
92
{
93
93
$ locker = $ this ->initLocker ();
94
94
$ dbConnection = $ this ->initPostgresPdoConnection ();
95
95
$ postgresLockId1 = PostgresLockId::fromKeyValue ('test1 ' );
96
96
$ postgresLockId2 = PostgresLockId::fromKeyValue ('test2 ' );
97
97
98
- $ isLock1Acquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
99
- $ isLock2Acquired = $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId2 );
98
+ $ isLock1Acquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId1 );
99
+ $ isLock2Acquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId2 );
100
100
101
101
$ this ->assertTrue ($ isLock1Acquired );
102
102
$ this ->assertTrue ($ isLock2Acquired );
@@ -111,9 +111,9 @@ public function testItCannotAcquireSameLockInTwoConnections(): void
111
111
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
112
112
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
113
113
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
114
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
114
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId );
115
115
116
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
116
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId );
117
117
118
118
$ this ->assertFalse ($ isLockAcquired );
119
119
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -125,9 +125,9 @@ public function testItCanReleaseLock(): void
125
125
$ locker = $ this ->initLocker ();
126
126
$ dbConnection = $ this ->initPostgresPdoConnection ();
127
127
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
128
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
128
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
129
129
130
- $ isLockReleased = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
130
+ $ isLockReleased = $ locker ->releaseLockWithinSession ($ dbConnection , $ postgresLockId );
131
131
132
132
$ this ->assertTrue ($ isLockReleased );
133
133
$ this ->assertPgAdvisoryLocksCount (0 );
@@ -138,27 +138,27 @@ public function testItCanReleaseLockTwiceIfAcquiredTwice(): void
138
138
$ locker = $ this ->initLocker ();
139
139
$ dbConnection = $ this ->initPostgresPdoConnection ();
140
140
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
141
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
142
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId );
141
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
142
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId );
143
143
144
- $ isLockReleased1 = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
145
- $ isLockReleased2 = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
144
+ $ isLockReleased1 = $ locker ->releaseLockWithinSession ($ dbConnection , $ postgresLockId );
145
+ $ isLockReleased2 = $ locker ->releaseLockWithinSession ($ dbConnection , $ postgresLockId );
146
146
147
147
$ this ->assertTrue ($ isLockReleased1 );
148
148
$ this ->assertTrue ($ isLockReleased2 );
149
149
$ this ->assertPgAdvisoryLocksCount (0 );
150
150
}
151
151
152
- public function testItCanAcquireLockInSecondConnectionAfterRelease (): void
152
+ public function testItCanTryAcquireLockInSecondConnectionAfterRelease (): void
153
153
{
154
154
$ locker = $ this ->initLocker ();
155
155
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
156
156
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
157
157
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
158
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
159
- $ locker ->releaseLock ($ dbConnection1 , $ postgresLockId );
158
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId );
159
+ $ locker ->releaseLockWithinSession ($ dbConnection1 , $ postgresLockId );
160
160
161
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
161
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId );
162
162
163
163
$ this ->assertTrue ($ isLockAcquired );
164
164
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -171,11 +171,11 @@ public function testItCannotAcquireLockInSecondConnectionAfterOneReleaseTwiceLoc
171
171
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
172
172
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
173
173
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
174
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
175
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
174
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId );
175
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId );
176
176
177
- $ isLockReleased = $ locker ->releaseLock ($ dbConnection1 , $ postgresLockId );
178
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
177
+ $ isLockReleased = $ locker ->releaseLockWithinSession ($ dbConnection1 , $ postgresLockId );
178
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId );
179
179
180
180
$ this ->assertTrue ($ isLockReleased );
181
181
$ this ->assertFalse ($ isLockAcquired );
@@ -190,7 +190,7 @@ public function testItCannotReleaseLockIfNotAcquired(): void
190
190
$ dbConnection = $ this ->initPostgresPdoConnection ();
191
191
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
192
192
193
- $ isLockReleased = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
193
+ $ isLockReleased = $ locker ->releaseLockWithinSession ($ dbConnection , $ postgresLockId );
194
194
195
195
$ this ->assertFalse ($ isLockReleased );
196
196
$ this ->assertPgAdvisoryLocksCount (0 );
@@ -202,9 +202,9 @@ public function testItCannotReleaseLockIfAcquiredInOtherConnection(): void
202
202
$ dbConnection1 = $ this ->initPostgresPdoConnection ();
203
203
$ dbConnection2 = $ this ->initPostgresPdoConnection ();
204
204
$ postgresLockId = PostgresLockId::fromKeyValue ('test ' );
205
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId );
205
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId );
206
206
207
- $ isLockReleased = $ locker ->releaseLock ($ dbConnection2 , $ postgresLockId );
207
+ $ isLockReleased = $ locker ->releaseLockWithinSession ($ dbConnection2 , $ postgresLockId );
208
208
209
209
$ this ->assertFalse ($ isLockReleased );
210
210
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -217,10 +217,10 @@ public function testItCanReleaseAllLocksInConnection(): void
217
217
$ dbConnection = $ this ->initPostgresPdoConnection ();
218
218
$ postgresLockId1 = PostgresLockId::fromKeyValue ('test ' );
219
219
$ postgresLockId2 = PostgresLockId::fromKeyValue ('test2 ' );
220
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
221
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId2 );
220
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId1 );
221
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId2 );
222
222
223
- $ locker ->releaseAllLocks ($ dbConnection );
223
+ $ locker ->releaseAllLocksWithinSession ($ dbConnection );
224
224
225
225
$ this ->assertPgAdvisoryLocksCount (0 );
226
226
}
@@ -230,7 +230,7 @@ public function testItCanReleaseAllLocksInConnectionIfNoLocksWereAcquired(): voi
230
230
$ locker = $ this ->initLocker ();
231
231
$ dbConnection = $ this ->initPostgresPdoConnection ();
232
232
233
- $ locker ->releaseAllLocks ($ dbConnection );
233
+ $ locker ->releaseAllLocksWithinSession ($ dbConnection );
234
234
235
235
$ this ->assertPgAdvisoryLocksCount (0 );
236
236
}
@@ -244,19 +244,19 @@ public function testItCanReleaseAllLocksInConnectionButKeepsOtherLocks(): void
244
244
$ postgresLockId2 = PostgresLockId::fromKeyValue ('test2 ' );
245
245
$ postgresLockId3 = PostgresLockId::fromKeyValue ('test3 ' );
246
246
$ postgresLockId4 = PostgresLockId::fromKeyValue ('test4 ' );
247
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId1 );
248
- $ locker ->tryAcquireLock ($ dbConnection1 , $ postgresLockId2 );
249
- $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId3 );
250
- $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId4 );
247
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId1 );
248
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection1 , $ postgresLockId2 );
249
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId3 );
250
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId4 );
251
251
252
- $ locker ->releaseAllLocks ($ dbConnection1 );
252
+ $ locker ->releaseAllLocksWithinSession ($ dbConnection1 );
253
253
254
254
$ this ->assertPgAdvisoryLocksCount (2 );
255
255
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection2 , $ postgresLockId3 );
256
256
$ this ->assertPgAdvisoryLockExistsInConnection ($ dbConnection2 , $ postgresLockId4 );
257
257
}
258
258
259
- public function testItCanAcquireLockWithinTransaction (): void
259
+ public function testItCanTryAcquireLockWithinTransaction (): void
260
260
{
261
261
$ locker = $ this ->initLocker ();
262
262
$ dbConnection = $ this ->initPostgresPdoConnection ();
@@ -293,7 +293,7 @@ public function testItCannotAcquireLockInSecondConnectionIfTakenWithinTransactio
293
293
$ dbConnection1 ->beginTransaction ();
294
294
$ locker ->tryAcquireLockWithinTransaction ($ dbConnection1 , $ postgresLockId );
295
295
296
- $ isLockAcquired = $ locker ->tryAcquireLock ($ dbConnection2 , $ postgresLockId );
296
+ $ isLockAcquired = $ locker ->tryAcquireLockWithinSession ($ dbConnection2 , $ postgresLockId );
297
297
298
298
$ this ->assertFalse ($ isLockAcquired );
299
299
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -349,7 +349,7 @@ public function testItCannotReleaseLockAcquiredWithinTransaction(): void
349
349
$ dbConnection ->beginTransaction ();
350
350
$ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId );
351
351
352
- $ isLockReleased = $ locker ->releaseLock ($ dbConnection , $ postgresLockId );
352
+ $ isLockReleased = $ locker ->releaseLockWithinSession ($ dbConnection , $ postgresLockId );
353
353
354
354
$ this ->assertFalse ($ isLockReleased );
355
355
$ this ->assertPgAdvisoryLocksCount (1 );
@@ -362,11 +362,11 @@ public function testItCannotReleaseAllLocksAcquiredWithinTransaction(): void
362
362
$ dbConnection = $ this ->initPostgresPdoConnection ();
363
363
$ postgresLockId1 = PostgresLockId::fromKeyValue ('test ' );
364
364
$ postgresLockId2 = PostgresLockId::fromKeyValue ('test2 ' );
365
- $ locker ->tryAcquireLock ($ dbConnection , $ postgresLockId1 );
365
+ $ locker ->tryAcquireLockWithinSession ($ dbConnection , $ postgresLockId1 );
366
366
$ dbConnection ->beginTransaction ();
367
367
$ locker ->tryAcquireLockWithinTransaction ($ dbConnection , $ postgresLockId2 );
368
368
369
- $ locker ->releaseAllLocks ($ dbConnection );
369
+ $ locker ->releaseAllLocksWithinSession ($ dbConnection );
370
370
371
371
$ this ->assertPgAdvisoryLocksCount (1 );
372
372
$ this ->assertPgAdvisoryLockMissingInConnection ($ dbConnection , $ postgresLockId1 );
0 commit comments