lhotari commented on code in PR #4543: URL: https://github.com/apache/bookkeeper/pull/4543#discussion_r1910549783
########## stream/distributedlog/core/src/test/java/org/apache/distributedlog/bk/TestLedgerAllocator.java: ########## @@ -164,152 +163,162 @@ public void testAllocation() throws Exception { Utils.close(allocator); } - @Test(timeout = 60000) + @Test public void testBadVersionOnTwoAllocators() throws Exception { - String allocationPath = "/allocation-bad-version"; - zkc.get().create(allocationPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - Stat stat = new Stat(); - byte[] data = zkc.get().getData(allocationPath, false, stat); - Versioned<byte[]> allocationData = new Versioned<byte[]>(data, new LongVersion(stat.getVersion())); - - SimpleLedgerAllocator allocator1 = - new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc); - SimpleLedgerAllocator allocator2 = - new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc); - allocator1.allocate(); - // wait until allocated - ZKTransaction txn1 = newTxn(); - LedgerHandle lh = Utils.ioResult(allocator1.tryObtain(txn1, NULL_LISTENER)); - allocator2.allocate(); - ZKTransaction txn2 = newTxn(); - try { - Utils.ioResult(allocator2.tryObtain(txn2, NULL_LISTENER)); - fail("Should fail allocating on second allocator as allocator1 is starting allocating something."); - } catch (ZKException ke) { - assertEquals(KeeperException.Code.BADVERSION, ke.getKeeperExceptionCode()); - } - Utils.ioResult(txn1.execute()); - Utils.close(allocator1); - Utils.close(allocator2); - - long eid = lh.addEntry("hello world".getBytes()); - lh.close(); - LedgerHandle readLh = bkc.get().openLedger(lh.getId(), - BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes()); - Enumeration<LedgerEntry> entries = readLh.readEntries(eid, eid); - int i = 0; - while (entries.hasMoreElements()) { - LedgerEntry entry = entries.nextElement(); - assertEquals("hello world", new String(entry.getEntry(), UTF_8)); - ++i; - } - assertEquals(1, i); + assertTimeout(Duration.ofMinutes(1), () -> { Review Comment: It's better to use Junit 5's `@Timeout` annotation instead of using `assertTimeout`. https://www.baeldung.com/java-junit-5-timeout-annotation -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@bookkeeper.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org