A few more lambdas.

This commit is contained in:
akwizgran
2017-11-17 15:47:37 +00:00
committed by Torsten Grote
parent d7383a3361
commit 879f699b2b
2 changed files with 98 additions and 119 deletions

View File

@@ -473,9 +473,7 @@ public class H2DatabaseTest extends BrambleTestCase {
// Start a transaction
Connection txn = db.startTransaction();
// In another thread, close the database
Thread close = new Thread() {
@Override
public void run() {
Thread close = new Thread(() -> {
try {
closing.countDown();
db.close();
@@ -484,8 +482,7 @@ public class H2DatabaseTest extends BrambleTestCase {
} catch (Exception e) {
error.set(true);
}
}
};
});
close.start();
closing.await();
// Do whatever the transaction needs to do
@@ -510,9 +507,7 @@ public class H2DatabaseTest extends BrambleTestCase {
// Start a transaction
Connection txn = db.startTransaction();
// In another thread, close the database
Thread close = new Thread() {
@Override
public void run() {
Thread close = new Thread(() -> {
try {
closing.countDown();
db.close();
@@ -521,8 +516,7 @@ public class H2DatabaseTest extends BrambleTestCase {
} catch (Exception e) {
error.set(true);
}
}
};
});
close.start();
closing.await();
// Do whatever the transaction needs to do

View File

@@ -23,9 +23,7 @@ public class LockFairnessTest extends BrambleTestCase {
CountDownLatch secondReaderHasLock = new CountDownLatch(1);
CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
// First reader
Thread first = new Thread() {
@Override
public void run() {
Thread first = new Thread(() -> {
try {
// Acquire the lock
lock.readLock().lock();
@@ -42,13 +40,10 @@ public class LockFairnessTest extends BrambleTestCase {
fail();
}
firstReaderHasFinished.countDown();
}
};
});
first.start();
// Second reader
Thread second = new Thread() {
@Override
public void run() {
Thread second = new Thread(() -> {
try {
// Wait for the first reader to acquire the lock
assertTrue(firstReaderHasLock.await(10, SECONDS));
@@ -65,8 +60,7 @@ public class LockFairnessTest extends BrambleTestCase {
fail();
}
secondReaderHasFinished.countDown();
}
};
});
second.start();
// Wait for both readers to finish
assertTrue(firstReaderHasFinished.await(10, SECONDS));
@@ -84,9 +78,7 @@ public class LockFairnessTest extends BrambleTestCase {
AtomicBoolean secondReaderHasHeldLock = new AtomicBoolean(false);
AtomicBoolean writerHasHeldLock = new AtomicBoolean(false);
// First reader
Thread first = new Thread() {
@Override
public void run() {
Thread first = new Thread(() -> {
try {
// Acquire the lock
lock.readLock().lock();
@@ -106,13 +98,10 @@ public class LockFairnessTest extends BrambleTestCase {
fail();
}
firstReaderHasFinished.countDown();
}
};
});
first.start();
// Writer
Thread writer = new Thread() {
@Override
public void run() {
Thread writer = new Thread(() -> {
try {
// Wait for the first reader to acquire the lock
assertTrue(firstReaderHasLock.await(10, SECONDS));
@@ -129,13 +118,10 @@ public class LockFairnessTest extends BrambleTestCase {
fail();
}
writerHasFinished.countDown();
}
};
});
writer.start();
// Second reader
Thread second = new Thread() {
@Override
public void run() {
Thread second = new Thread(() -> {
try {
// Wait for the first reader to acquire the lock
assertTrue(firstReaderHasLock.await(10, SECONDS));
@@ -154,8 +140,7 @@ public class LockFairnessTest extends BrambleTestCase {
fail();
}
secondReaderHasFinished.countDown();
}
};
});
second.start();
// Wait for all the threads to finish
assertTrue(firstReaderHasFinished.await(10, SECONDS));