Skip to content

Commit

Permalink
migrate-junit5-client-module
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlock-lin committed Sep 3, 2024
1 parent 4936d39 commit b21e0c5
Show file tree
Hide file tree
Showing 18 changed files with 6,485 additions and 6,367 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,62 @@
import org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture;
import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test the bookkeeper client while losing a ZK session.
*/
public class BookKeeperClientZKSessionExpiry extends BookKeeperClusterTestCase {
private static final Logger LOG = LoggerFactory.getLogger(BookKeeperClientZKSessionExpiry.class);

public BookKeeperClientZKSessionExpiry() {
super(4);
}
private static final Logger LOG = LoggerFactory.getLogger(BookKeeperClientZKSessionExpiry.class);

@Test
public void testSessionLossWhileWriting() throws Exception {
public BookKeeperClientZKSessionExpiry() {
super(4);
}

Thread expiryThread = new Thread() {
@Override
public void run() {
try {
while (true) {
Thread.sleep(5000);
long sessionId = bkc.getZkHandle().getSessionId();
byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd();
@Test
void sessionLossWhileWriting() throws Exception {

try {
ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000, false);
ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000,
watcher, sessionId, sessionPasswd);
zk.close();
} catch (Exception e) {
LOG.info("Error killing session", e);
}
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
}
}
};
expiryThread.start();
Thread expiryThread = new Thread() {
@Override
public void run() {
try {
while (true) {
Thread.sleep(5000);
long sessionId = bkc.getZkHandle().getSessionId();
byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd();

for (int i = 0; i < 3; i++) {
LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes());
for (int j = 0; j < 100; j++) {
lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null);
try {
ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000, true);
ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, watcher,
sessionId,
sessionPasswd);
zk.close();
} catch (Exception e) {
LOG.info("Error killing session", e);
}
startNewBookie();
killBookie(0);
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
}
}
};
expiryThread.start();

lh.addEntry("lastEntry".getBytes());
for (int i = 0; i < 3; i++) {
LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes());
for (int j = 0; j < 100; j++) {
lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null);
}
startNewBookie();
killBookie(0);

lh.close();
}
lh.addEntry("lastEntry".getBytes());

lh.close();
}
}
}
Loading

0 comments on commit b21e0c5

Please sign in to comment.