18
18
package org .apache .distributedlog .bk ;
19
19
20
20
import static java .nio .charset .StandardCharsets .UTF_8 ;
21
- import static org .junit .Assert .assertEquals ;
22
- import static org .junit .Assert .assertTrue ;
23
- import static org .junit .Assert .fail ;
21
+ import static org .junit .jupiter . api . Assertions .assertEquals ;
22
+ import static org .junit .jupiter . api . Assertions .assertTrue ;
23
+ import static org .junit .jupiter . api . Assertions .fail ;
24
24
25
25
import java .net .URI ;
26
26
import java .util .Enumeration ;
27
27
import java .util .HashSet ;
28
28
import java .util .Map ;
29
29
import java .util .Set ;
30
30
import java .util .concurrent .CompletableFuture ;
31
+ import java .util .concurrent .TimeUnit ;
31
32
import org .apache .bookkeeper .client .BKException ;
32
33
import org .apache .bookkeeper .client .BookKeeper ;
33
34
import org .apache .bookkeeper .client .LedgerEntry ;
53
54
import org .apache .zookeeper .Op ;
54
55
import org .apache .zookeeper .ZooDefs ;
55
56
import org .apache .zookeeper .data .Stat ;
56
- import org .junit .After ;
57
- import org .junit .Before ;
58
- import org .junit .Rule ;
59
- import org .junit .Test ;
60
- import org .junit .rules . TestName ;
57
+ import org .junit .jupiter . api . AfterAll ;
58
+ import org .junit .jupiter . api . BeforeAll ;
59
+ import org .junit .jupiter . api . Test ;
60
+ import org .junit .jupiter . api . TestInstance ;
61
+ import org .junit .jupiter . api . Timeout ;
61
62
import org .slf4j .Logger ;
62
63
import org .slf4j .LoggerFactory ;
63
64
64
65
/**
65
66
* TestLedgerAllocator.
66
67
*/
68
+ @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
67
69
public class TestLedgerAllocator extends TestDistributedLogBase {
68
70
69
71
private static final Logger logger = LoggerFactory .getLogger (TestLedgerAllocator .class );
@@ -81,9 +83,6 @@ public void onAbort(Throwable t) {
81
83
}
82
84
};
83
85
84
- @ Rule
85
- public TestName runtime = new TestName ();
86
-
87
86
private ZooKeeperClient zkc ;
88
87
private BookKeeperClient bkc ;
89
88
private DistributedLogConfiguration dlConf = new DistributedLogConfiguration ();
@@ -92,7 +91,7 @@ private URI createURI(String path) {
92
91
return URI .create ("distributedlog://" + zkServers + path );
93
92
}
94
93
95
- @ Before
94
+ @ BeforeAll
96
95
public void setup () throws Exception {
97
96
zkc = TestZooKeeperClientBuilder .newBuilder ()
98
97
.uri (createURI ("/" ))
@@ -102,7 +101,7 @@ public void setup() throws Exception {
102
101
.dlConfig (dlConf ).ledgersPath (ledgersPath ).zkc (zkc ).build ();
103
102
}
104
103
105
- @ After
104
+ @ AfterAll
106
105
public void teardown () throws Exception {
107
106
bkc .close ();
108
107
zkc .close ();
@@ -164,7 +163,8 @@ public void testAllocation() throws Exception {
164
163
Utils .close (allocator );
165
164
}
166
165
167
- @ Test (timeout = 60000 )
166
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
167
+ @ Test
168
168
public void testBadVersionOnTwoAllocators () throws Exception {
169
169
String allocationPath = "/allocation-bad-version" ;
170
170
zkc .get ().create (allocationPath , new byte [0 ], ZooDefs .Ids .OPEN_ACL_UNSAFE , CreateMode .PERSISTENT );
@@ -173,9 +173,11 @@ public void testBadVersionOnTwoAllocators() throws Exception {
173
173
Versioned <byte []> allocationData = new Versioned <byte []>(data , new LongVersion (stat .getVersion ()));
174
174
175
175
SimpleLedgerAllocator allocator1 =
176
- new SimpleLedgerAllocator (allocationPath , allocationData , newQuorumConfigProvider (dlConf ), zkc , bkc );
176
+ new SimpleLedgerAllocator (allocationPath , allocationData , newQuorumConfigProvider (dlConf ),
177
+ zkc , bkc );
177
178
SimpleLedgerAllocator allocator2 =
178
- new SimpleLedgerAllocator (allocationPath , allocationData , newQuorumConfigProvider (dlConf ), zkc , bkc );
179
+ new SimpleLedgerAllocator (allocationPath , allocationData , newQuorumConfigProvider (dlConf ),
180
+ zkc , bkc );
179
181
allocator1 .allocate ();
180
182
// wait until allocated
181
183
ZKTransaction txn1 = newTxn ();
@@ -206,7 +208,8 @@ public void testBadVersionOnTwoAllocators() throws Exception {
206
208
assertEquals (1 , i );
207
209
}
208
210
209
- @ Test (timeout = 60000 )
211
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
212
+ @ Test
210
213
public void testAllocatorWithoutEnoughBookies () throws Exception {
211
214
String allocationPath = "/allocator-without-enough-bookies" ;
212
215
@@ -230,17 +233,18 @@ public void testAllocatorWithoutEnoughBookies() throws Exception {
230
233
assertEquals (0 , data .length );
231
234
}
232
235
233
- @ Test (timeout = 60000 )
234
- public void testSuccessAllocatorShouldDeleteUnusedledger () throws Exception {
236
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
237
+ @ Test
238
+ public void testSuccessAllocatorShouldDeleteUnusedLedger () throws Exception {
235
239
String allocationPath = "/allocation-delete-unused-ledger" ;
236
240
zkc .get ().create (allocationPath , new byte [0 ], ZooDefs .Ids .OPEN_ACL_UNSAFE , CreateMode .PERSISTENT );
237
241
Stat stat = new Stat ();
238
242
byte [] data = zkc .get ().getData (allocationPath , false , stat );
239
243
240
244
Versioned <byte []> allocationData = new Versioned <byte []>(data , new LongVersion (stat .getVersion ()));
241
245
242
- SimpleLedgerAllocator allocator1 =
243
- new SimpleLedgerAllocator ( allocationPath , allocationData , newQuorumConfigProvider (dlConf ), zkc , bkc );
246
+ SimpleLedgerAllocator allocator1 = new SimpleLedgerAllocator ( allocationPath , allocationData ,
247
+ newQuorumConfigProvider (dlConf ), zkc , bkc );
244
248
allocator1 .allocate ();
245
249
// wait until allocated
246
250
ZKTransaction txn1 = newTxn ();
@@ -250,8 +254,8 @@ public void testSuccessAllocatorShouldDeleteUnusedledger() throws Exception {
250
254
stat = new Stat ();
251
255
data = zkc .get ().getData (allocationPath , false , stat );
252
256
allocationData = new Versioned <byte []>(data , new LongVersion (stat .getVersion ()));
253
- SimpleLedgerAllocator allocator2 =
254
- new SimpleLedgerAllocator ( allocationPath , allocationData , newQuorumConfigProvider (dlConf ), zkc , bkc );
257
+ SimpleLedgerAllocator allocator2 = new SimpleLedgerAllocator ( allocationPath , allocationData ,
258
+ newQuorumConfigProvider (dlConf ), zkc , bkc );
255
259
allocator2 .allocate ();
256
260
// wait until allocated
257
261
ZKTransaction txn2 = newTxn ();
@@ -296,7 +300,8 @@ public void testSuccessAllocatorShouldDeleteUnusedledger() throws Exception {
296
300
assertEquals (1 , i );
297
301
}
298
302
299
- @ Test (timeout = 60000 )
303
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
304
+ @ Test
300
305
public void testCloseAllocatorDuringObtaining () throws Exception {
301
306
String allocationPath = "/allocation2" ;
302
307
SimpleLedgerAllocator allocator = createAllocator (allocationPath );
@@ -329,7 +334,8 @@ public void testCloseAllocatorAfterConfirm() throws Exception {
329
334
dlConf .getBKDigestPW ().getBytes (UTF_8 ));
330
335
}
331
336
332
- @ Test (timeout = 60000 )
337
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
338
+ @ Test
333
339
public void testCloseAllocatorAfterAbort () throws Exception {
334
340
String allocationPath = "/allocation3" ;
335
341
SimpleLedgerAllocator allocator = createAllocator (allocationPath );
@@ -352,9 +358,10 @@ public void testCloseAllocatorAfterAbort() throws Exception {
352
358
dlConf .getBKDigestPW ().getBytes (UTF_8 ));
353
359
}
354
360
355
- @ Test (timeout = 60000 )
361
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
362
+ @ Test
356
363
public void testConcurrentAllocation () throws Exception {
357
- String allocationPath = "/" + runtime . getMethodName () ;
364
+ String allocationPath = "/" + testName ;
358
365
SimpleLedgerAllocator allocator = createAllocator (allocationPath );
359
366
allocator .allocate ();
360
367
ZKTransaction txn1 = newTxn ();
@@ -365,15 +372,17 @@ public void testConcurrentAllocation() throws Exception {
365
372
assertTrue (obtainFuture2 .isCompletedExceptionally ());
366
373
try {
367
374
Utils .ioResult (obtainFuture2 );
368
- fail ("Should fail the concurrent obtain since there is already a transaction obtaining the ledger handle" );
375
+ fail ("Should fail the concurrent obtain since there is "
376
+ + "already a transaction obtaining the ledger handle" );
369
377
} catch (SimpleLedgerAllocator .ConcurrentObtainException cbe ) {
370
378
// expected
371
379
}
372
380
}
373
381
374
- @ Test (timeout = 60000 )
382
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
383
+ @ Test
375
384
public void testObtainMultipleLedgers () throws Exception {
376
- String allocationPath = "/" + runtime . getMethodName () ;
385
+ String allocationPath = "/" + testName ;
377
386
SimpleLedgerAllocator allocator = createAllocator (allocationPath );
378
387
int numLedgers = 10 ;
379
388
Set <LedgerHandle > allocatedLedgers = new HashSet <LedgerHandle >();
@@ -387,9 +396,10 @@ public void testObtainMultipleLedgers() throws Exception {
387
396
assertEquals (numLedgers , allocatedLedgers .size ());
388
397
}
389
398
390
- @ Test (timeout = 60000 )
399
+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
400
+ @ Test
391
401
public void testAllocationWithMetadata () throws Exception {
392
- String allocationPath = "/" + runtime . getMethodName () ;
402
+ String allocationPath = "/" + testName ;
393
403
394
404
String application = "testApplicationMetadata" ;
395
405
String component = "testComponentMetadata" ;
0 commit comments