mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
A few more lambdas.
This commit is contained in:
@@ -473,9 +473,7 @@ public class H2DatabaseTest extends BrambleTestCase {
|
|||||||
// Start a transaction
|
// Start a transaction
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
// In another thread, close the database
|
// In another thread, close the database
|
||||||
Thread close = new Thread() {
|
Thread close = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
closing.countDown();
|
closing.countDown();
|
||||||
db.close();
|
db.close();
|
||||||
@@ -484,8 +482,7 @@ public class H2DatabaseTest extends BrambleTestCase {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error.set(true);
|
error.set(true);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
close.start();
|
close.start();
|
||||||
closing.await();
|
closing.await();
|
||||||
// Do whatever the transaction needs to do
|
// Do whatever the transaction needs to do
|
||||||
@@ -510,9 +507,7 @@ public class H2DatabaseTest extends BrambleTestCase {
|
|||||||
// Start a transaction
|
// Start a transaction
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
// In another thread, close the database
|
// In another thread, close the database
|
||||||
Thread close = new Thread() {
|
Thread close = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
closing.countDown();
|
closing.countDown();
|
||||||
db.close();
|
db.close();
|
||||||
@@ -521,8 +516,7 @@ public class H2DatabaseTest extends BrambleTestCase {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error.set(true);
|
error.set(true);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
close.start();
|
close.start();
|
||||||
closing.await();
|
closing.await();
|
||||||
// Do whatever the transaction needs to do
|
// Do whatever the transaction needs to do
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
CountDownLatch secondReaderHasLock = new CountDownLatch(1);
|
CountDownLatch secondReaderHasLock = new CountDownLatch(1);
|
||||||
CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
||||||
// First reader
|
// First reader
|
||||||
Thread first = new Thread() {
|
Thread first = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
// Acquire the lock
|
// Acquire the lock
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
@@ -42,13 +40,10 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
firstReaderHasFinished.countDown();
|
firstReaderHasFinished.countDown();
|
||||||
}
|
});
|
||||||
};
|
|
||||||
first.start();
|
first.start();
|
||||||
// Second reader
|
// Second reader
|
||||||
Thread second = new Thread() {
|
Thread second = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
// Wait for the first reader to acquire the lock
|
// Wait for the first reader to acquire the lock
|
||||||
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
||||||
@@ -65,8 +60,7 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
secondReaderHasFinished.countDown();
|
secondReaderHasFinished.countDown();
|
||||||
}
|
});
|
||||||
};
|
|
||||||
second.start();
|
second.start();
|
||||||
// Wait for both readers to finish
|
// Wait for both readers to finish
|
||||||
assertTrue(firstReaderHasFinished.await(10, SECONDS));
|
assertTrue(firstReaderHasFinished.await(10, SECONDS));
|
||||||
@@ -84,9 +78,7 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
AtomicBoolean secondReaderHasHeldLock = new AtomicBoolean(false);
|
AtomicBoolean secondReaderHasHeldLock = new AtomicBoolean(false);
|
||||||
AtomicBoolean writerHasHeldLock = new AtomicBoolean(false);
|
AtomicBoolean writerHasHeldLock = new AtomicBoolean(false);
|
||||||
// First reader
|
// First reader
|
||||||
Thread first = new Thread() {
|
Thread first = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
// Acquire the lock
|
// Acquire the lock
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
@@ -106,13 +98,10 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
firstReaderHasFinished.countDown();
|
firstReaderHasFinished.countDown();
|
||||||
}
|
});
|
||||||
};
|
|
||||||
first.start();
|
first.start();
|
||||||
// Writer
|
// Writer
|
||||||
Thread writer = new Thread() {
|
Thread writer = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
// Wait for the first reader to acquire the lock
|
// Wait for the first reader to acquire the lock
|
||||||
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
||||||
@@ -129,13 +118,10 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
writerHasFinished.countDown();
|
writerHasFinished.countDown();
|
||||||
}
|
});
|
||||||
};
|
|
||||||
writer.start();
|
writer.start();
|
||||||
// Second reader
|
// Second reader
|
||||||
Thread second = new Thread() {
|
Thread second = new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
// Wait for the first reader to acquire the lock
|
// Wait for the first reader to acquire the lock
|
||||||
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
assertTrue(firstReaderHasLock.await(10, SECONDS));
|
||||||
@@ -154,8 +140,7 @@ public class LockFairnessTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
secondReaderHasFinished.countDown();
|
secondReaderHasFinished.countDown();
|
||||||
}
|
});
|
||||||
};
|
|
||||||
second.start();
|
second.start();
|
||||||
// Wait for all the threads to finish
|
// Wait for all the threads to finish
|
||||||
assertTrue(firstReaderHasFinished.await(10, SECONDS));
|
assertTrue(firstReaderHasFinished.await(10, SECONDS));
|
||||||
|
|||||||
Reference in New Issue
Block a user