From 445b01e07fa3c1a24cb5a03193161200de06bd00 Mon Sep 17 00:00:00 2001
From: Patrick Doyle
Date: Sun, 21 Jul 2024 11:47:38 -0400
Subject: [PATCH] BoskTestUtils.boskName
---
.../java/works/bosk/BoskConstructorTest.java | 17 ++++---
.../works/bosk/BoskDiagnosticContextTest.java | 3 +-
.../works/bosk/BoskLocalReferenceTest.java | 15 +++---
.../test/java/works/bosk/BoskUpdateTest.java | 3 +-
.../java/works/bosk/CatalogBenchmark.java | 3 +-
.../src/test/java/works/bosk/ListingTest.java | 7 +--
.../java/works/bosk/OptionalRefsTest.java | 5 +-
.../java/works/bosk/ReferenceErrorTest.java | 3 +-
.../src/test/java/works/bosk/VariantTest.java | 3 +-
.../bosk/dereferencers/PathCompilerTest.java | 3 +-
.../drivers/ReplicaSetConformanceTest.java | 3 +-
.../bosk/drivers/mongo/BsonPluginTest.java | 3 +-
.../mongo/MongoDriverDottedFieldNameTest.java | 3 +-
.../MongoDriverInitializationFailureTest.java | 3 +-
.../mongo/MongoDriverRecoveryTest.java | 9 ++--
.../drivers/mongo/MongoDriverSpecialTest.java | 51 ++++++++++---------
.../drivers/mongo/SchemaEvolutionTest.java | 5 +-
.../main/java/works/bosk/BoskTestUtils.java | 21 ++++++++
.../bosk/drivers/AbstractDriverTest.java | 6 ++-
.../bosk/drivers/DriverStateVerifier.java | 3 +-
.../java/works/bosk/drivers/HanoiTest.java | 5 +-
lib-testing/build.gradle | 1 +
.../java/works/bosk/AbstractBoskTest.java | 3 +-
23 files changed, 109 insertions(+), 69 deletions(-)
create mode 100644 bosk-testing/src/main/java/works/bosk/BoskTestUtils.java
mode change 100644 => 100755 bosk-testing/src/main/java/works/bosk/drivers/AbstractDriverTest.java
diff --git a/bosk-core/src/test/java/works/bosk/BoskConstructorTest.java b/bosk-core/src/test/java/works/bosk/BoskConstructorTest.java
index 99c1ab65..c3c2c1c5 100644
--- a/bosk-core/src/test/java/works/bosk/BoskConstructorTest.java
+++ b/bosk-core/src/test/java/works/bosk/BoskConstructorTest.java
@@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.TypeValidationTest.SimpleTypes.MyEnum.LEFT;
/**
@@ -28,7 +29,7 @@ public class BoskConstructorTest {
@Test
void basicProperties_correctValues() {
- String name = "Name";
+ String name = boskName();
Type rootType = SimpleTypes.class;
StateTreeNode root = newEntity();
@@ -63,7 +64,7 @@ void basicProperties_correctValues() {
void invalidRootType_throws() {
assertThrows(IllegalArgumentException.class, ()->
new Bosk(
- "Invalid root type",
+ boskName("Invalid root type"),
MutableField.class,
bosk -> new MutableField(),
Bosk::simpleDriver));
@@ -89,7 +90,7 @@ void badDefaultRootFunction_throws() {
void mismatchedRootType_throws() {
assertThrows(ClassCastException.class, ()->
new Bosk (
- "Mismatched root",
+ boskName("Mismatched root"),
BoxedPrimitives.class, // Valid but wrong
bosk -> newEntity(),
Bosk::simpleDriver
@@ -101,7 +102,7 @@ void mismatchedRootType_throws() {
void driverInitialRoot_matches() {
SimpleTypes root = newEntity();
Bosk bosk = new Bosk(
- "By value",
+ boskName(),
SimpleTypes.class,
__ -> {throw new AssertionError("Shouldn't be called");},
initialRootDriver(()->root));
@@ -114,14 +115,14 @@ void driverInitialRoot_matches() {
void defaultRoot_matches() {
SimpleTypes root = newEntity();
{
- Bosk valueBosk = new Bosk<>("By value", SimpleTypes.class, root, Bosk::simpleDriver);
+ Bosk valueBosk = new Bosk<>(boskName(), SimpleTypes.class, root, Bosk::simpleDriver);
try (val __ = valueBosk.readContext()) {
assertSame(root, valueBosk.rootReference().value());
}
}
{
- Bosk functionBosk = new Bosk("By value", SimpleTypes.class, __ -> root, Bosk::simpleDriver);
+ Bosk functionBosk = new Bosk(boskName(), SimpleTypes.class, __ -> root, Bosk::simpleDriver);
try (val __ = functionBosk.readContext()) {
assertSame(root, functionBosk.rootReference().value());
}
@@ -135,7 +136,7 @@ void defaultRoot_matches() {
private static void assertInitialRootThrows(Class extends Throwable> expectedType, InitialRootFunction initialRootFunction) {
assertThrows(expectedType, () -> new Bosk<>(
- "Throw test",
+ boskName(),
SimpleTypes.class,
newEntity(),
initialRootDriver(initialRootFunction)
@@ -144,7 +145,7 @@ private static void assertInitialRootThrows(Class extends Throwable> expectedT
private static void assertDefaultRootThrows(Class extends Throwable> expectedType, DefaultRootFunction defaultRootFunction) {
assertThrows(expectedType, () -> new Bosk<>(
- "Throw test",
+ boskName(),
SimpleTypes.class,
defaultRootFunction,
Bosk::simpleDriver
diff --git a/bosk-core/src/test/java/works/bosk/BoskDiagnosticContextTest.java b/bosk-core/src/test/java/works/bosk/BoskDiagnosticContextTest.java
index 850c230d..23ea761b 100644
--- a/bosk-core/src/test/java/works/bosk/BoskDiagnosticContextTest.java
+++ b/bosk-core/src/test/java/works/bosk/BoskDiagnosticContextTest.java
@@ -13,6 +13,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static works.bosk.BoskTestUtils.boskName;
/**
* Note that context propagation for driver operations is tested by {@link DriverConformanceTest}.
@@ -27,7 +28,7 @@ public interface Refs {
@BeforeEach
void setupBosk() throws InvalidTypeException {
bosk = new Bosk(
- BoskDiagnosticContextTest.class.getSimpleName(),
+ boskName(),
TestEntity.class,
AbstractDriverTest::initialRoot,
Bosk::simpleDriver
diff --git a/bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java b/bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java
index 4da1f9ef..e9a4fbb6 100644
--- a/bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java
+++ b/bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java
@@ -37,6 +37,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.ListingEntry.LISTING_ENTRY;
import static works.bosk.ReferenceUtils.rawClass;
@@ -55,6 +56,7 @@
*
*/
class BoskLocalReferenceTest {
+ String boskName;
Bosk bosk;
Root root;
Refs refs;
@@ -66,8 +68,9 @@ public interface Refs {
@BeforeEach
void initializeBosk() throws InvalidTypeException {
+ boskName = boskName();
Root initialRoot = new Root(1, Catalog.empty());
- bosk = new Bosk<>(BOSK_NAME, Root.class, initialRoot, Bosk::simpleDriver);
+ bosk = new Bosk<>(boskName, Root.class, initialRoot, Bosk::simpleDriver);
refs = bosk.rootReference().buildReferences(Refs.class);
Identifier ernieID = Identifier.from("ernie");
Identifier bertID = Identifier.from("bert");
@@ -255,7 +258,7 @@ void testBogusReferenceReference() {
@Test
void testName() {
- assertEquals(BOSK_NAME, bosk.name());
+ assertEquals(boskName, bosk.name());
}
@Test
@@ -270,15 +273,15 @@ public InvalidRoot(Identifier id, Catalog entities, String str) {
this.mutableString = str;
}
}
- assertThrows(IllegalArgumentException.class, () -> new Bosk<>("invalid", InvalidRoot.class, new InvalidRoot(Identifier.unique("yucky"), Catalog.empty(), "hello"), Bosk::simpleDriver));
- assertThrows(IllegalArgumentException.class, () -> new Bosk<>("invalid", String.class, new InvalidRoot(Identifier.unique("yucky"), Catalog.empty(), "hello"), Bosk::simpleDriver));
+ assertThrows(IllegalArgumentException.class, () -> new Bosk<>(boskName(), InvalidRoot.class, new InvalidRoot(Identifier.unique("yucky"), Catalog.empty(), "hello"), Bosk::simpleDriver));
+ assertThrows(IllegalArgumentException.class, () -> new Bosk<>(boskName(), String.class, new InvalidRoot(Identifier.unique("yucky"), Catalog.empty(), "hello"), Bosk::simpleDriver));
}
@Test
void testDriver() {
// This doesn't test the operation of the driver; merely that the right driver is returned
AtomicReference> driver = new AtomicReference<>();
- Bosk myBosk = new Bosk<>("My bosk", Root.class, new Root(123, Catalog.empty()), (b,d) -> {
+ Bosk myBosk = new Bosk<>(boskName(), Root.class, new Root(123, Catalog.empty()), (b,d) -> {
BoskDriver bd = new ProxyDriver(d);
driver.set(bd);
return bd;
@@ -446,6 +449,4 @@ private Reference refUpdater(Reference ref) {
throw new AssertionError("Unexpected!", e);
}
}
-
- private static final String BOSK_NAME = "bosk name";
}
diff --git a/bosk-core/src/test/java/works/bosk/BoskUpdateTest.java b/bosk-core/src/test/java/works/bosk/BoskUpdateTest.java
index 2c6f17e8..4ce41bd4 100644
--- a/bosk-core/src/test/java/works/bosk/BoskUpdateTest.java
+++ b/bosk-core/src/test/java/works/bosk/BoskUpdateTest.java
@@ -8,6 +8,7 @@
import works.bosk.exceptions.InvalidTypeException;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
/**
* To get complete coverage of Bosk.java, include these:
@@ -40,7 +41,7 @@ public interface Refs {
@BeforeEach
void createBosk() throws InvalidTypeException {
bosk = new Bosk(
- BoskUpdateTest.class.getSimpleName(),
+ boskName(),
TestRoot.class,
AbstractBoskTest::initialRoot,
Bosk::simpleDriver
diff --git a/bosk-core/src/test/java/works/bosk/CatalogBenchmark.java b/bosk-core/src/test/java/works/bosk/CatalogBenchmark.java
index c4be0415..e919536b 100644
--- a/bosk-core/src/test/java/works/bosk/CatalogBenchmark.java
+++ b/bosk-core/src/test/java/works/bosk/CatalogBenchmark.java
@@ -14,6 +14,7 @@
import works.bosk.exceptions.InvalidTypeException;
import static org.openjdk.jmh.annotations.Mode.Throughput;
+import static works.bosk.BoskTestUtils.boskName;
@Fork(0)
@Warmup(iterations = 5, time = 1)
@@ -29,7 +30,7 @@ public static class BenchmarkState {
@Setup(Level.Trial)
public void setup() throws InvalidTypeException {
Bosk bosk = new Bosk(
- "CatalogBenchmarkBosk",
+ boskName(),
AbstractBoskTest.TestRoot.class,
AbstractBoskTest::initialRoot,
Bosk::simpleDriver
diff --git a/bosk-core/src/test/java/works/bosk/ListingTest.java b/bosk-core/src/test/java/works/bosk/ListingTest.java
index 50121d15..9580d609 100644
--- a/bosk-core/src/test/java/works/bosk/ListingTest.java
+++ b/bosk-core/src/test/java/works/bosk/ListingTest.java
@@ -37,6 +37,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static works.bosk.BoskTestUtils.boskName;
/*
* TODO: This test is written in a mighty weird style. Change it to set up
@@ -54,7 +55,7 @@ public Stream extends Arguments> provideArguments(ExtensionContext context) {
return childrenStream
.map(children -> {
TestEntity root = new TestEntity(Identifier.unique("parent"), Catalog.of(children));
- Bosk bosk = new Bosk<>("Test Bosk", TestEntity.class, root, Bosk::simpleDriver);
+ Bosk bosk = new Bosk<>(boskName(), TestEntity.class, root, Bosk::simpleDriver);
CatalogReference catalog;
try {
catalog = bosk.rootReference().thenCatalog(TestEntity.class, Path.just(TestEntity.Fields.children));
@@ -73,7 +74,7 @@ public Stream extends Arguments> provideArguments(ExtensionContext context) th
TestEntity child = new TestEntity(Identifier.unique("child"), Catalog.empty());
List children = singletonList(child);
TestEntity root = new TestEntity(Identifier.unique("parent"), Catalog.of(children));
- Bosk bosk = new Bosk<>("Test Bosk", TestEntity.class, root, Bosk::simpleDriver);
+ Bosk bosk = new Bosk<>(boskName(), TestEntity.class, root, Bosk::simpleDriver);
CatalogReference childrenRef = bosk.rootReference().thenCatalog(TestEntity.class, Path.just(TestEntity.Fields.children));
return idStreams().map(list -> Arguments.of(list.map(Identifier::from).collect(toList()), childrenRef, bosk));
}
@@ -248,7 +249,7 @@ void testEmpty() throws InvalidTypeException {
TestEntity child = new TestEntity(Identifier.unique("child"), Catalog.empty());
List children = singletonList(child);
TestEntity root = new TestEntity(Identifier.unique("parent"), Catalog.of(children));
- Bosk bosk = new Bosk<>("Test Bosk", TestEntity.class, root, Bosk::simpleDriver);
+ Bosk bosk = new Bosk<>(boskName(), TestEntity.class, root, Bosk::simpleDriver);
CatalogReference childrenRef = bosk.rootReference().thenCatalog(TestEntity.class, Path.just(TestEntity.Fields.children));
Listing actual = Listing.empty(childrenRef);
diff --git a/bosk-core/src/test/java/works/bosk/OptionalRefsTest.java b/bosk-core/src/test/java/works/bosk/OptionalRefsTest.java
index 9e102a02..a61fdc4d 100644
--- a/bosk-core/src/test/java/works/bosk/OptionalRefsTest.java
+++ b/bosk-core/src/test/java/works/bosk/OptionalRefsTest.java
@@ -17,13 +17,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
class OptionalRefsTest extends AbstractRoundTripTest {
private static final Identifier ID = Identifier.from("dummy");
@Test
void testReferenceOptionalNotAllowed() {
- Bosk bosk = new Bosk<>("optionalNotAllowed", OptionalString.class, new OptionalString(ID, Optional.empty()), Bosk::simpleDriver);
+ Bosk bosk = new Bosk<>(boskName(), OptionalString.class, new OptionalString(ID, Optional.empty()), Bosk::simpleDriver);
InvalidTypeException e = assertThrows(InvalidTypeException.class, () -> bosk.rootReference().then(Optional.class, Path.just("field")));
assertThat(e.getMessage(), containsString("not supported"));
}
@@ -117,7 +118,7 @@ private interface ValueFactory {
}
private void doTest(E initialRoot, ValueFactory valueFactory, DriverFactory driverFactory) throws InvalidTypeException {
- Bosk bosk = new Bosk<>("bosk", initialRoot.getClass(), initialRoot, driverFactory);
+ Bosk bosk = new Bosk<>(boskName(), initialRoot.getClass(), initialRoot, driverFactory);
V value = valueFactory.createFrom(bosk);
@SuppressWarnings("unchecked")
Reference optionalRef = bosk.rootReference().then((Class)value.getClass(), "field");
diff --git a/bosk-core/src/test/java/works/bosk/ReferenceErrorTest.java b/bosk-core/src/test/java/works/bosk/ReferenceErrorTest.java
index 4cc6bdc7..16975599 100644
--- a/bosk-core/src/test/java/works/bosk/ReferenceErrorTest.java
+++ b/bosk-core/src/test/java/works/bosk/ReferenceErrorTest.java
@@ -10,6 +10,7 @@
import works.bosk.exceptions.InvalidTypeException;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
public class ReferenceErrorTest {
Bosk> bosk;
@@ -17,7 +18,7 @@ public class ReferenceErrorTest {
@BeforeEach
void setupBosk() {
bosk = new Bosk<>(
- "Test",
+ boskName(),
BadGetters.class,
new BadGetters(Identifier.from("test"), new NestedObject(Optional.of("stringValue"))),
Bosk::simpleDriver);
diff --git a/bosk-core/src/test/java/works/bosk/VariantTest.java b/bosk-core/src/test/java/works/bosk/VariantTest.java
index a6db4ec0..bde99601 100644
--- a/bosk-core/src/test/java/works/bosk/VariantTest.java
+++ b/bosk-core/src/test/java/works/bosk/VariantTest.java
@@ -10,6 +10,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
class VariantTest extends AbstractBoskTest {
@@ -46,7 +47,7 @@ public interface Refs {
@Test
void test() throws InvalidTypeException, IOException, InterruptedException {
String stringValue = "test";
- var bosk = new Bosk<>(VariantTest.class.getSimpleName(), BoskState.class, new BoskState(new StringCase(stringValue)), Bosk::simpleDriver);
+ var bosk = new Bosk<>(boskName(), BoskState.class, new BoskState(new StringCase(stringValue)), Bosk::simpleDriver);
var refs = bosk.rootReference().buildReferences(Refs.class);
try (var __ = bosk.readContext()) {
assertEquals(stringValue, refs.stringValue().value());
diff --git a/bosk-core/src/test/java/works/bosk/dereferencers/PathCompilerTest.java b/bosk-core/src/test/java/works/bosk/dereferencers/PathCompilerTest.java
index fac99ffd..1ad47d6b 100644
--- a/bosk-core/src/test/java/works/bosk/dereferencers/PathCompilerTest.java
+++ b/bosk-core/src/test/java/works/bosk/dereferencers/PathCompilerTest.java
@@ -39,6 +39,7 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.ListingEntry.LISTING_ENTRY;
public class PathCompilerTest extends AbstractBoskTest {
@@ -268,7 +269,7 @@ protected Class> loadClass(String name, boolean resolve) throws ClassNotFoundE
.getConstructor(Identifier.class)
.newInstance(rootID);
Bosk differentBosk = new Bosk<>(
- "Different",
+ boskName("Different"),
differentRootClass,
initialRoot,
Bosk::simpleDriver
diff --git a/bosk-core/src/test/java/works/bosk/drivers/ReplicaSetConformanceTest.java b/bosk-core/src/test/java/works/bosk/drivers/ReplicaSetConformanceTest.java
index 5c29d7e0..ba9da08a 100644
--- a/bosk-core/src/test/java/works/bosk/drivers/ReplicaSetConformanceTest.java
+++ b/bosk-core/src/test/java/works/bosk/drivers/ReplicaSetConformanceTest.java
@@ -6,6 +6,7 @@
import works.bosk.drivers.state.TestEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
class ReplicaSetConformanceTest extends DriverConformanceTest {
Bosk replicaBosk;
@@ -14,7 +15,7 @@ class ReplicaSetConformanceTest extends DriverConformanceTest {
void setupDriverFactory() {
ReplicaSet replicaSet = new ReplicaSet<>();
replicaBosk = new Bosk(
- "Replica bosk",
+ boskName("Replica"),
TestEntity.class,
AbstractDriverTest::initialRoot,
replicaSet.driverFactory());
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/BsonPluginTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/BsonPluginTest.java
index e3836d56..1f1a9e2b 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/BsonPluginTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/BsonPluginTest.java
@@ -22,13 +22,14 @@
import works.bosk.exceptions.InvalidTypeException;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
class BsonPluginTest {
@Test
void sideTableOfSideTables() {
BsonPlugin bp = new BsonPlugin();
- Bosk bosk = new Bosk("Test bosk", Root.class, this::defaultRoot, Bosk::simpleDriver);
+ Bosk bosk = new Bosk(boskName(), Root.class, this::defaultRoot, Bosk::simpleDriver);
CodecRegistry registry = CodecRegistries.fromProviders(bp.codecProviderFor(bosk), new ValueCodecProvider());
Codec codec = registry.get(Root.class);
try (var __ = bosk.readContext()) {
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverDottedFieldNameTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverDottedFieldNameTest.java
index 00403cd5..c19ab788 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverDottedFieldNameTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverDottedFieldNameTest.java
@@ -17,13 +17,14 @@
import works.bosk.exceptions.InvalidTypeException;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
class MongoDriverDottedFieldNameTest extends AbstractDriverTest {
private Bosk bosk;
@BeforeEach
void setUpStuff() {
- bosk = new Bosk("Test bosk", TestEntity.class, AbstractDriverTest::initialRoot, Bosk::simpleDriver);
+ bosk = new Bosk(boskName(), TestEntity.class, AbstractDriverTest::initialRoot, Bosk::simpleDriver);
}
private CatalogReference rootCatalogRef(Bosk bosk) throws InvalidTypeException {
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverInitializationFailureTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverInitializationFailureTest.java
index 29b5dd37..556a49f6 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverInitializationFailureTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverInitializationFailureTest.java
@@ -6,6 +6,7 @@
import static ch.qos.logback.classic.Level.ERROR;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
/**
* Tests the functionality of {@link MongoDriverSettings.InitialDatabaseUnavailableMode#FAIL FAIL} mode.
@@ -27,7 +28,7 @@ void initialOutage_throws() {
mongoService.proxy().setConnectionCut(true);
tearDownActions.add(()->mongoService.proxy().setConnectionCut(false));
assertThrows(InitialRootFailureException.class, ()->{
- new Bosk("Fail", TestEntity.class, this::initialRoot, super.createDriverFactory(logController));
+ new Bosk(boskName("Fail"), TestEntity.class, this::initialRoot, super.createDriverFactory(logController));
});
}
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverRecoveryTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverRecoveryTest.java
index 795594ba..abf152c4 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverRecoveryTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverRecoveryTest.java
@@ -25,6 +25,7 @@
import static ch.qos.logback.classic.Level.ERROR;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.ListingEntry.LISTING_ENTRY;
import static works.bosk.drivers.mongo.MainDriver.COLLECTION_NAME;
@@ -78,7 +79,7 @@ void initialOutage_recovers() throws InvalidTypeException, InterruptedException,
tearDownActions.add(()->mongoService.proxy().setConnectionCut(false));
LOGGER.debug("Create a new bosk that can't connect");
- Bosk bosk = new Bosk("Test " + boskCounter.incrementAndGet(), TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(getClass().getSimpleName() + boskCounter.incrementAndGet(), TestEntity.class, this::initialRoot, driverFactory);
MongoDriverSpecialTest.Refs refs = bosk.buildReferences(MongoDriverSpecialTest.Refs.class);
BoskDriver driver = bosk.driver();
@@ -208,7 +209,7 @@ void revisionDeleted_recovers() throws InvalidTypeException, InterruptedExceptio
LOGGER.debug("Setup database to beforeState");
TestEntity beforeState = initializeDatabase("before deletion");
- Bosk bosk = new Bosk("Test " + boskCounter.incrementAndGet(), TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName(getClass().getSimpleName()), TestEntity.class, this::initialRoot, driverFactory);
try (var __ = bosk.readContext()) {
assertEquals(beforeState, bosk.rootReference().value());
@@ -252,7 +253,7 @@ private void setRevision(long revisionNumber) {
private TestEntity initializeDatabase(String distinctiveString) {
try {
Bosk prepBosk = new Bosk(
- "Prep " + boskCounter.incrementAndGet(),
+ boskName("Prep " + getClass().getSimpleName()),
TestEntity.class,
bosk -> initialRoot(bosk).withString(distinctiveString),
driverFactory);
@@ -270,7 +271,7 @@ private void testRecovery(Runnable disruptiveAction, Function bosk = new Bosk("Test " + boskCounter.incrementAndGet(), TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName(getClass().getSimpleName()), TestEntity.class, this::initialRoot, driverFactory);
try (var __ = bosk.readContext()) {
assertEquals(beforeState, bosk.rootReference().value());
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverSpecialTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverSpecialTest.java
index 59a36384..c8d7a7da 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverSpecialTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverSpecialTest.java
@@ -47,6 +47,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.ListingEntry.LISTING_ENTRY;
/**
@@ -73,7 +74,7 @@ static Stream parameters() {
@ParametersByName
@UsesMongoService
void warmStart_stateMatches() throws InvalidTypeException, InterruptedException, IOException {
- Bosk setupBosk = new Bosk("Setup", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk setupBosk = new Bosk(boskName("Setup"), TestEntity.class, this::initialRoot, driverFactory);
Refs refs = setupBosk.buildReferences(Refs.class);
// Make a change to the bosk so it's not just the initial root
@@ -82,7 +83,7 @@ void warmStart_stateMatches() throws InvalidTypeException, InterruptedException,
TestEntity expected = initialRoot(setupBosk)
.withListing(Listing.of(refs.catalog(), entity123));
- Bosk latecomerBosk = new Bosk("Latecomer", TestEntity.class, b->{
+ Bosk latecomerBosk = new Bosk(boskName("Latecomer"), TestEntity.class, b->{
throw new AssertionError("Default root function should not be called");
}, driverFactory);
@@ -98,7 +99,7 @@ void flush_localStateUpdated() throws InvalidTypeException, InterruptedException
// Set up MongoDriver writing to a modified BufferingDriver that lets us
// have tight control over all the comings and goings from MongoDriver.
BlockingQueue> replacementsSeen = new LinkedBlockingDeque<>();
- Bosk bosk = new Bosk("Test", TestEntity.class, this::initialRoot,
+ Bosk bosk = new Bosk(boskName(), TestEntity.class, this::initialRoot,
(b,d) -> driverFactory.build(b, new BufferingDriver<>(d) {
@Override
public void submitReplacement(Reference target, T newValue) {
@@ -150,7 +151,7 @@ public void submitReplacement(Reference target, T newValue) {
@ParametersByName
@UsesMongoService
void listing_stateMatches() throws InvalidTypeException, InterruptedException, IOException {
- Bosk bosk = new Bosk("Test", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName(), TestEntity.class, this::initialRoot, driverFactory);
BoskDriver driver = bosk.driver();
CatalogReference catalogRef = bosk.rootReference().thenCatalog(TestEntity.class,
TestEntity.Fields.catalog);
@@ -190,7 +191,7 @@ void listing_stateMatches() throws InvalidTypeException, InterruptedException, I
void networkOutage_boskRecovers() throws InvalidTypeException, InterruptedException, IOException {
setLogging(ERROR, MainDriver.class, ChangeReceiver.class);
- Bosk bosk = new Bosk("Main", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName("Main"), TestEntity.class, this::initialRoot, driverFactory);
Refs refs = bosk.buildReferences(Refs.class);
BoskDriver driver = bosk.driver();
@@ -198,7 +199,7 @@ void networkOutage_boskRecovers() throws InvalidTypeException, InterruptedExcept
driver.flush();
LOGGER.debug("Make another bosk that doesn't witness any change stream events before the outage");
- Bosk latecomerBosk = new Bosk("Latecomer", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk latecomerBosk = new Bosk(boskName("Latecomer"), TestEntity.class, this::initialRoot, driverFactory);
LOGGER.debug("Cut connection");
mongoService.proxy().setConnectionCut(true);
@@ -236,7 +237,7 @@ void networkOutage_boskRecovers() throws InvalidTypeException, InterruptedExcept
void hookRegisteredDuringNetworkOutage_works() throws InvalidTypeException, InterruptedException, IOException {
setLogging(ERROR, MainDriver.class, ChangeReceiver.class);
- Bosk bosk = new Bosk("Main", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName(), TestEntity.class, this::initialRoot, driverFactory);
Refs refs = bosk.buildReferences(Refs.class);
BoskDriver driver = bosk.driver();
CountDownLatch listingEntry124Exists = new CountDownLatch(1);
@@ -293,11 +294,11 @@ void initialStateHasNonexistentFields_ignored() throws InvalidTypeException {
setLogging(ERROR, BsonPlugin.class);
// Upon creating bosk, the initial value will be saved to MongoDB
- new Bosk("Newer", TestEntity.class, this::initialRootWithValues, driverFactory);
+ new Bosk(boskName("Newer"), TestEntity.class, this::initialRootWithValues, driverFactory);
// Upon creating prevBosk, the state in the database will be loaded into the local.
Bosk prevBosk = new Bosk(
- "Prev",
+ boskName("Prev"),
OldEntity.class,
(b) -> { throw new AssertionError("prevBosk should use the state from MongoDB"); },
createDriverFactory(logController));
@@ -316,9 +317,9 @@ void initialStateHasNonexistentFields_ignored() throws InvalidTypeException {
void updateHasNonexistentFields_ignored() throws InvalidTypeException, IOException, InterruptedException {
setLogging(ERROR, BsonPlugin.class);
- Bosk bosk = new Bosk("Newer", TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
+ Bosk bosk = new Bosk(boskName("Newer"), TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
Bosk prevBosk = new Bosk(
- "Prev",
+ boskName("Prev"),
OldEntity.class,
(b) -> { throw new AssertionError("prevBosk should use the state from MongoDB"); },
createDriverFactory(logController));
@@ -346,9 +347,9 @@ void updateHasNonexistentFields_ignored() throws InvalidTypeException, IOExcepti
void updateNonexistentField_ignored() throws InvalidTypeException, IOException, InterruptedException {
setLogging(ERROR, SequoiaFormatDriver.class, PandoFormatDriver.class, BsonPlugin.class);
- Bosk bosk = new Bosk("Newer", TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
+ Bosk bosk = new Bosk(boskName("Newer"), TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
Bosk prevBosk = new Bosk(
- "Prev",
+ boskName("Prev"),
OldEntity.class,
(b) -> { throw new AssertionError("prevBosk should use the state from MongoDB"); },
createDriverFactory(logController));
@@ -376,7 +377,7 @@ void updateInsidePolyfill_works() throws IOException, InterruptedException, Inva
// We'll use this as an honest observer of the actual state
LOGGER.debug("Create Original bosk");
Bosk originalBosk = new Bosk(
- "Original",
+ boskName("Original"),
TestEntity.class,
this::initialRoot,
createDriverFactory(logController)
@@ -384,7 +385,7 @@ void updateInsidePolyfill_works() throws IOException, InterruptedException, Inva
LOGGER.debug("Create Upgradeable bosk");
Bosk upgradeableBosk = new Bosk(
- "Upgradeable",
+ boskName("Upgradeable"),
UpgradeableEntity.class,
(b) -> { throw new AssertionError("upgradeableBosk should use the state from MongoDB"); },
createDriverFactory(logController)
@@ -422,9 +423,9 @@ void updateInsidePolyfill_works() throws IOException, InterruptedException, Inva
void deleteNonexistentField_ignored() throws InvalidTypeException, IOException, InterruptedException {
setLogging(ERROR, SequoiaFormatDriver.class, PandoFormatDriver.class);
- Bosk newerBosk = new Bosk("Newer", TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
+ Bosk newerBosk = new Bosk(boskName("Newer"), TestEntity.class, this::initialRootWithEmptyCatalog, driverFactory);
Bosk prevBosk = new Bosk(
- "Prev",
+ boskName("Prev"),
OldEntity.class,
(b) -> { throw new AssertionError("prevBosk should use the state from MongoDB"); },
createDriverFactory(logController));
@@ -450,10 +451,10 @@ void databaseMissingField_fallsBackToDefaultState() throws InvalidTypeException,
setLogging(ERROR, ChangeReceiver.class);
LOGGER.debug("Set up database with entity that has no string field");
- Bosk setupBosk = new Bosk("Setup", OptionalEntity.class, b -> OptionalEntity.withString(Optional.empty(), b), createDriverFactory(logController));
+ Bosk setupBosk = new Bosk(boskName("Setup"), OptionalEntity.class, b -> OptionalEntity.withString(Optional.empty(), b), createDriverFactory(logController));
LOGGER.debug("Connect another bosk where the string field is mandatory");
- Bosk testBosk = new Bosk("Test", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk testBosk = new Bosk(boskName("Test"), TestEntity.class, this::initialRoot, driverFactory);
TestEntity expected1 = initialRoot(testBosk); // NOT what was put there by the setup bosk!
TestEntity actual1;
try (var __ = testBosk.readContext()) {
@@ -502,7 +503,7 @@ void unrelatedDoc_ignored() throws InvalidTypeException, IOException, Interrupte
}
private void doUnrelatedChangeTest(String databaseName, String collectionName, String docID) throws IOException, InterruptedException, InvalidTypeException {
- Bosk bosk = new Bosk("Test", TestEntity.class, this::initialRoot, driverFactory);
+ Bosk bosk = new Bosk(boskName(), TestEntity.class, this::initialRoot, driverFactory);
MongoCollection counterfeitCollection = mongoService.client()
.getDatabase(databaseName)
@@ -534,7 +535,7 @@ void refurbish_createsField() throws IOException, InterruptedException {
// We'll use this as an honest observer of the actual state
LOGGER.debug("Create Original bosk");
Bosk originalBosk = new Bosk(
- "Original",
+ boskName("Original"),
TestEntity.class,
this::initialRoot,
createDriverFactory(logController)
@@ -542,7 +543,7 @@ void refurbish_createsField() throws IOException, InterruptedException {
LOGGER.debug("Create Upgradeable bosk");
Bosk upgradeableBosk = new Bosk(
- "Upgradeable",
+ boskName("Upgradeable"),
UpgradeableEntity.class,
(b) -> { throw new AssertionError("upgradeableBosk should use the state from MongoDB"); },
createDriverFactory(logController)
@@ -573,7 +574,7 @@ void manifestVersionBump_disconnects() throws IOException, InterruptedException
setLogging(ERROR, MainDriver.class, ChangeReceiver.class);
Bosk bosk = new Bosk(
- "bosk",
+ boskName(),
TestEntity.class,
this::initialRoot,
createDriverFactory(logController)
@@ -607,7 +608,7 @@ void manifestVersionBump_disconnects() throws IOException, InterruptedException
void refurbish_fixesMetadata() throws IOException, InterruptedException {
// Set up the database so it looks basically right
Bosk initialBosk = new Bosk(
- "Initial",
+ boskName("Initial"),
TestEntity.class,
this::initialRoot,
createDriverFactory(logController)
@@ -624,7 +625,7 @@ void refurbish_fixesMetadata() throws IOException, InterruptedException {
// Make the bosk whose refurbish operation we want to test
Bosk bosk = new Bosk(
- "bosk",
+ boskName("Main"),
TestEntity.class,
this::initialRoot,
createDriverFactory(logController)
diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/SchemaEvolutionTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/SchemaEvolutionTest.java
index c114dc7e..82759249 100644
--- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/SchemaEvolutionTest.java
+++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/SchemaEvolutionTest.java
@@ -17,6 +17,7 @@
import works.bosk.junit.ParametersByName;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
@UsesMongoService
public class SchemaEvolutionTest {
@@ -176,11 +177,9 @@ private static void flushIfLiveRefurbishIsNotSupported(
}
private static Bosk newBosk(Helper helper) {
- return new Bosk("bosk" + boskCounter.incrementAndGet(), TestEntity.class, helper::initialRoot, helper.driverFactory);
+ return new Bosk(boskName(helper.toString()), TestEntity.class, helper::initialRoot, helper.driverFactory);
}
- private static final AtomicInteger boskCounter = new AtomicInteger(0);
-
record Configuration(
MongoDriverSettings.DatabaseFormat preferredFormat,
MongoDriverSettings.ManifestMode manifestMode
diff --git a/bosk-testing/src/main/java/works/bosk/BoskTestUtils.java b/bosk-testing/src/main/java/works/bosk/BoskTestUtils.java
new file mode 100644
index 00000000..c9a0a194
--- /dev/null
+++ b/bosk-testing/src/main/java/works/bosk/BoskTestUtils.java
@@ -0,0 +1,21 @@
+package works.bosk;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class BoskTestUtils {
+ private static final AtomicInteger boskCounter = new AtomicInteger(0);
+
+ /**
+ * @return an informative string suitable to be used as the name of a {@link Bosk}.
+ * Helpful especially in parallel testing, to figure out which bosk emitted a log message.
+ */
+ public static String boskName() {
+ var caller = StackWalker.getInstance().walk(s -> s.skip(1).findFirst()).get();
+ return "bosk" + boskCounter.incrementAndGet() + "(" + caller.getFileName() + ":" + caller.getLineNumber() + ")";
+ }
+
+ public static String boskName(String prefix) {
+ return prefix + " " + boskName();
+ }
+
+}
diff --git a/bosk-testing/src/main/java/works/bosk/drivers/AbstractDriverTest.java b/bosk-testing/src/main/java/works/bosk/drivers/AbstractDriverTest.java
old mode 100644
new mode 100755
index c2a9a07e..8694d9a0
--- a/bosk-testing/src/main/java/works/bosk/drivers/AbstractDriverTest.java
+++ b/bosk-testing/src/main/java/works/bosk/drivers/AbstractDriverTest.java
@@ -20,6 +20,7 @@
import static java.lang.Thread.currentThread;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
public abstract class AbstractDriverTest {
protected final Identifier child1ID = Identifier.from("child1");
@@ -47,11 +48,12 @@ private static void logTest(String verb, TestInfo testInfo) {
}
protected void setupBosksAndReferences(DriverFactory driverFactory) {
+ var frame = StackWalker.getInstance().walk(s -> s.skip(1).findFirst()).get();
// This is the bosk whose behaviour we'll consider to be correct by definition
- canonicalBosk = new Bosk(getClass().getSimpleName() + "-canonical", TestEntity.class, AbstractDriverTest::initialRoot, Bosk::simpleDriver);
+ canonicalBosk = new Bosk(boskName("Canonical"), TestEntity.class, AbstractDriverTest::initialRoot, Bosk::simpleDriver);
// This is the bosk we're testing
- bosk = new Bosk(getClass().getSimpleName(), TestEntity.class, AbstractDriverTest::initialRoot, DriverStack.of(
+ bosk = new Bosk(boskName("Test"), TestEntity.class, AbstractDriverTest::initialRoot, DriverStack.of(
MirroringDriver.targeting(canonicalBosk),
DriverStateVerifier.wrap(driverFactory, TestEntity.class, AbstractDriverTest::initialRoot)
));
diff --git a/bosk-testing/src/main/java/works/bosk/drivers/DriverStateVerifier.java b/bosk-testing/src/main/java/works/bosk/drivers/DriverStateVerifier.java
index fd3e10cf..dca36e82 100644
--- a/bosk-testing/src/main/java/works/bosk/drivers/DriverStateVerifier.java
+++ b/bosk-testing/src/main/java/works/bosk/drivers/DriverStateVerifier.java
@@ -22,6 +22,7 @@
import static java.lang.Thread.currentThread;
import static lombok.AccessLevel.PRIVATE;
+import static works.bosk.BoskTestUtils.boskName;
/**
* Watches the updates entering and leaving a particular {@link BoskDriver} and ensures
@@ -51,7 +52,7 @@ public class DriverStateVerifier {
public static DriverFactory wrap(DriverFactory subject, Type rootType, Bosk.DefaultRootFunction defaultRootFunction) {
Bosk stateTrackingBosk = new Bosk<>(
- DriverStateVerifier.class.getSimpleName(),
+ boskName(),
rootType, defaultRootFunction,
Bosk::simpleDriver
);
diff --git a/bosk-testing/src/main/java/works/bosk/drivers/HanoiTest.java b/bosk-testing/src/main/java/works/bosk/drivers/HanoiTest.java
index efdbbc87..57eaf86b 100644
--- a/bosk-testing/src/main/java/works/bosk/drivers/HanoiTest.java
+++ b/bosk-testing/src/main/java/works/bosk/drivers/HanoiTest.java
@@ -2,7 +2,6 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
@@ -27,6 +26,7 @@
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static works.bosk.BoskTestUtils.boskName;
import static works.bosk.ListingEntry.LISTING_ENTRY;
/**
@@ -42,7 +42,6 @@ public abstract class HanoiTest {
Refs refs;
BlockingQueue numSolved;
protected DriverFactory driverFactory;
- private static final AtomicInteger boskCounter = new AtomicInteger(0);
public interface Refs {
@ReferencePath("/puzzles")
@@ -58,7 +57,7 @@ public interface Refs {
@BeforeEach
void setup() throws InvalidTypeException {
bosk = new Bosk(
- getClass().getSimpleName() + "_" + boskCounter.incrementAndGet(),
+ boskName(),
HanoiState.class,
this::defaultRoot,
driverFactory
diff --git a/lib-testing/build.gradle b/lib-testing/build.gradle
index c777af1f..902f1a07 100644
--- a/lib-testing/build.gradle
+++ b/lib-testing/build.gradle
@@ -14,6 +14,7 @@ dependencies {
// It's a mild kind of circular dependency we can probably live with for now.
implementation project(":bosk-core")
implementation project(":bosk-logback")
+ implementation project(":bosk-testing")
// These are for AbstractRoundTripTest. That logic ought to be moved to their respective sub-projects
implementation project(":bosk-jackson")
implementation project(":bosk-mongo")
diff --git a/lib-testing/src/main/java/works/bosk/AbstractBoskTest.java b/lib-testing/src/main/java/works/bosk/AbstractBoskTest.java
index ac0ff33a..425471d0 100644
--- a/lib-testing/src/main/java/works/bosk/AbstractBoskTest.java
+++ b/lib-testing/src/main/java/works/bosk/AbstractBoskTest.java
@@ -10,6 +10,7 @@
import works.bosk.exceptions.InvalidTypeException;
import static java.util.Arrays.asList;
+import static works.bosk.BoskTestUtils.boskName;
public abstract class AbstractBoskTest {
@With
@@ -126,7 +127,7 @@ public enum TestEnum {
}
protected static Bosk setUpBosk(DriverFactory driverFactory) {
- return new Bosk("Test", TestRoot.class, AbstractRoundTripTest::initialRoot, driverFactory);
+ return new Bosk(boskName(), TestRoot.class, AbstractRoundTripTest::initialRoot, driverFactory);
}
protected static TestRoot initialRoot(Bosk bosk) {