add java 11 support (o) (#1222)
This commit is contained in:
@ -54,14 +54,14 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
OliphauntPool pool = new OliphauntPool();
|
||||
var pool = new OliphauntPool();
|
||||
LOGGER.info(pool.toString());
|
||||
Oliphaunt oliphaunt1 = pool.checkOut();
|
||||
var oliphaunt1 = pool.checkOut();
|
||||
LOGGER.info("Checked out {}", oliphaunt1);
|
||||
LOGGER.info(pool.toString());
|
||||
Oliphaunt oliphaunt2 = pool.checkOut();
|
||||
var oliphaunt2 = pool.checkOut();
|
||||
LOGGER.info("Checked out {}", oliphaunt2);
|
||||
Oliphaunt oliphaunt3 = pool.checkOut();
|
||||
var oliphaunt3 = pool.checkOut();
|
||||
LOGGER.info("Checked out {}", oliphaunt3);
|
||||
LOGGER.info(pool.toString());
|
||||
LOGGER.info("Checking in {}", oliphaunt1);
|
||||
@ -69,9 +69,9 @@ public class App {
|
||||
LOGGER.info("Checking in {}", oliphaunt2);
|
||||
pool.checkIn(oliphaunt2);
|
||||
LOGGER.info(pool.toString());
|
||||
Oliphaunt oliphaunt4 = pool.checkOut();
|
||||
var oliphaunt4 = pool.checkOut();
|
||||
LOGGER.info("Checked out {}", oliphaunt4);
|
||||
Oliphaunt oliphaunt5 = pool.checkOut();
|
||||
var oliphaunt5 = pool.checkOut();
|
||||
LOGGER.info("Checked out {}", oliphaunt5);
|
||||
LOGGER.info(pool.toString());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public abstract class ObjectPool<T> {
|
||||
if (available.isEmpty()) {
|
||||
available.add(create());
|
||||
}
|
||||
T instance = available.iterator().next();
|
||||
var instance = available.iterator().next();
|
||||
available.remove(instance);
|
||||
inUse.add(instance);
|
||||
return instance;
|
||||
|
@ -44,17 +44,17 @@ public class OliphauntPoolTest {
|
||||
@Test
|
||||
public void testSubsequentCheckinCheckout() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final OliphauntPool pool = new OliphauntPool();
|
||||
final var pool = new OliphauntPool();
|
||||
assertEquals("Pool available=0 inUse=0", pool.toString());
|
||||
|
||||
final Oliphaunt expectedOliphaunt = pool.checkOut();
|
||||
final var expectedOliphaunt = pool.checkOut();
|
||||
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||
|
||||
pool.checkIn(expectedOliphaunt);
|
||||
assertEquals("Pool available=1 inUse=0", pool.toString());
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final Oliphaunt oliphaunt = pool.checkOut();
|
||||
final var oliphaunt = pool.checkOut();
|
||||
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||
assertSame(expectedOliphaunt, oliphaunt);
|
||||
assertEquals(expectedOliphaunt.getId(), oliphaunt.getId());
|
||||
@ -73,13 +73,13 @@ public class OliphauntPoolTest {
|
||||
@Test
|
||||
public void testConcurrentCheckinCheckout() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final OliphauntPool pool = new OliphauntPool();
|
||||
final var pool = new OliphauntPool();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=0");
|
||||
|
||||
final Oliphaunt firstOliphaunt = pool.checkOut();
|
||||
final var firstOliphaunt = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=1");
|
||||
|
||||
final Oliphaunt secondOliphaunt = pool.checkOut();
|
||||
final var secondOliphaunt = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
|
||||
assertNotSame(firstOliphaunt, secondOliphaunt);
|
||||
@ -89,7 +89,7 @@ public class OliphauntPoolTest {
|
||||
pool.checkIn(secondOliphaunt);
|
||||
assertEquals(pool.toString(), "Pool available=1 inUse=1");
|
||||
|
||||
final Oliphaunt oliphaunt3 = pool.checkOut();
|
||||
final var oliphaunt3 = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertSame(secondOliphaunt, oliphaunt3);
|
||||
|
||||
@ -97,7 +97,7 @@ public class OliphauntPoolTest {
|
||||
pool.checkIn(firstOliphaunt);
|
||||
assertEquals(pool.toString(), "Pool available=1 inUse=1");
|
||||
|
||||
final Oliphaunt oliphaunt4 = pool.checkOut();
|
||||
final var oliphaunt4 = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertSame(firstOliphaunt, oliphaunt4);
|
||||
|
||||
@ -110,7 +110,7 @@ public class OliphauntPoolTest {
|
||||
|
||||
// The order of the returned instances is not determined, so just put them in a list
|
||||
// and verify if both expected instances are in there.
|
||||
final List<Oliphaunt> oliphaunts = List.of(pool.checkOut(), pool.checkOut());
|
||||
final var oliphaunts = List.of(pool.checkOut(), pool.checkOut());
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertTrue(oliphaunts.contains(firstOliphaunt));
|
||||
assertTrue(oliphaunts.contains(secondOliphaunt));
|
||||
|
Reference in New Issue
Block a user