Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] migrate-junit5-client-module #4492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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