use of com.apple.foundationdb.record.provider.foundationdb.synchronizedsession.SynchronizedSessionRunner in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionTest method secondSessionShouldTakeLockIfTheFirstOneExpiresAndTheFirstOneCannotContinue.
@Test
public void secondSessionShouldTakeLockIfTheFirstOneExpiresAndTheFirstOneCannotContinue() throws Exception {
try (SynchronizedSessionRunner session1Runner = newRunnerStartSession(lockSubspace1)) {
checkActive(session1Runner);
waitLongEnough();
// Able to create another session and the new session is active.
try (SynchronizedSessionRunner session2Runner = newRunnerStartSession(lockSubspace1)) {
checkActive(session2Runner);
}
// Should not be able to use session1, neither by existing runner nor by new runner.
assertFailedContinueSession(session1Runner);
assertFailedJoinSession(lockSubspace1, session1Runner.getSessionId());
session1Runner.endSession();
}
}
use of com.apple.foundationdb.record.provider.foundationdb.synchronizedsession.SynchronizedSessionRunner in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionTest method sessionsOnDifferentLocksShouldNotInterfere.
// Sessions on distinct locks.
@Test
public void sessionsOnDifferentLocksShouldNotInterfere() {
try (SynchronizedSessionRunner sessionOnLock1 = newRunnerStartSession(lockSubspace1)) {
sessionOnLock1.run(context -> {
try (SynchronizedSessionRunner sessionOnLock2 = newRunnerStartSession(lockSubspace2)) {
checkActive(sessionOnLock2);
sessionOnLock2.endSession();
}
return null;
});
sessionOnLock1.endSession();
}
}
use of com.apple.foundationdb.record.provider.foundationdb.synchronizedsession.SynchronizedSessionRunner in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionTest method testRenewLeaseContinuously.
private void testRenewLeaseContinuously(boolean reuseRunner) throws Exception {
try (SynchronizedSessionRunner session1Runner0 = database.newRunner().startSynchronizedSession(lockSubspace1, 1_000)) {
UUID session1 = session1Runner0.getSessionId();
AtomicBoolean session1Stopped = new AtomicBoolean(false);
Thread longSession = new Thread(() -> {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
SynchronizedSessionRunner runner = reuseRunner ? session1Runner0 : database.newRunner().joinSynchronizedSession(lockSubspace1, session1, 1_000);
checkActive(runner);
}
session1Stopped.set(true);
});
Thread tryStartSession = new Thread(() -> {
while (!session1Stopped.get()) {
assertFailedStartSession(lockSubspace1);
try {
Thread.sleep(random.nextInt(500));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
AtomicBoolean threadsHaveExceptions = new AtomicBoolean(false);
logExceptionsInThreads(threadsHaveExceptions);
longSession.start();
tryStartSession.start();
tryStartSession.join();
assertTrue(!threadsHaveExceptions.get());
session1Runner0.endSession();
}
}
use of com.apple.foundationdb.record.provider.foundationdb.synchronizedsession.SynchronizedSessionRunner in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionTest method assertFailedContinueSession.
private void assertFailedContinueSession(SynchronizedSessionRunner synchronizedSessionRunner) {
SynchronizedSessionLockedException exception = assertThrows(SynchronizedSessionLockedException.class, () -> synchronizedSessionRunner.run(c -> null));
assertEquals("Failed to continue the session", exception.getMessage());
}
use of com.apple.foundationdb.record.provider.foundationdb.synchronizedsession.SynchronizedSessionRunner in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionTest method clearSession.
@Test
public void clearSession() {
try (SynchronizedSessionRunner session1Runner = newRunnerStartSession(lockSubspace1)) {
checkActive(session1Runner);
session1Runner.endSession();
// Runners of the current session should not be able to work (neither existing runner nor newly created runner).
assertFailedContinueSession(session1Runner);
assertFailedJoinSession(lockSubspace1, session1Runner.getSessionId());
// The new session should be able to be created and used right away.
try (SynchronizedSessionRunner session2Runner = newRunnerStartSession(lockSubspace1)) {
checkActive(session2Runner);
// This call should no nothing because Session 1 has ended.
session1Runner.endSession();
// Make sure manually ending Session 1 does not clear the current lock.
checkActive(session2Runner);
// Use session1Runner to end eny active session (i.e. Session 2 here) even Session 1 has ended.
session1Runner.endAnySession();
// Check Session 2 is ended.
assertFailedContinueSession(session2Runner);
assertFailedJoinSession(lockSubspace1, session2Runner.getSessionId());
}
}
}
Aggregations