Skip to content

Commit 1e5552f

Browse files
committed
Always provide a cluster file, and reset in afterEach
1 parent c9eeaa4 commit 1e5552f

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/test/FDBDatabaseExtension.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.apple.foundationdb.test.FDBTestEnvironment;
3030
import com.apple.foundationdb.test.TestExecutors;
3131
import org.junit.jupiter.api.extension.AfterEachCallback;
32-
import org.junit.jupiter.api.extension.BeforeEachCallback;
3332
import org.junit.jupiter.api.extension.ExtensionContext;
3433
import org.junit.jupiter.api.extension.RegisterExtension;
3534
import org.slf4j.Logger;
@@ -60,7 +59,7 @@
6059
* tests that use this extension are free to modify what would otherwise be global state on the factory or database.
6160
* </p>
6261
*/
63-
public class FDBDatabaseExtension implements AfterEachCallback, BeforeEachCallback {
62+
public class FDBDatabaseExtension implements AfterEachCallback {
6463
private static final Logger LOGGER = LoggerFactory.getLogger(FDBDatabaseExtension.class);
6564
public static final String BLOCKING_IN_ASYNC_PROPERTY = "com.apple.foundationdb.record.blockingInAsyncDetection";
6665
public static final String API_VERSION_PROPERTY = "com.apple.foundationdb.apiVersion";
@@ -71,7 +70,7 @@ public class FDBDatabaseExtension implements AfterEachCallback, BeforeEachCallba
7170
private FDBDatabaseFactory databaseFactory;
7271
@Nonnull
7372
private final Map<String, FDBDatabase> databases = new HashMap<>();
74-
private String defaultClusterFile;
73+
private String defaultClusterFile = FDBTestEnvironment.randomClusterFile();
7574

7675

7776
public FDBDatabaseExtension() {
@@ -169,11 +168,6 @@ public void checkForOpenContexts() {
169168
}
170169
}
171170

172-
@Override
173-
public void beforeEach(final ExtensionContext context) {
174-
defaultClusterFile = FDBTestEnvironment.randomClusterFile();
175-
}
176-
177171
@Override
178172
public void afterEach(final ExtensionContext extensionContext) {
179173
// Validate that the test closes all the transactions that it opens
@@ -186,5 +180,7 @@ public void afterEach(final ExtensionContext extensionContext) {
186180
getDatabaseFactory().clear();
187181
databaseFactory = null;
188182
}
183+
// we don't do this in a beforeEach, in case a test is accessing the database in the constructor.
184+
defaultClusterFile = FDBTestEnvironment.randomClusterFile();
189185
}
190186
}

0 commit comments

Comments
 (0)