Skip to content

Commit c9eeaa4

Browse files
committed
Have FDBDatabaseExtension use a single cluster for the test
I think people could be confused by getting different clusters each call to `getDatabase`, so this persists that. If you want to test against multiple clusters, use the indexed methods.
1 parent 83f2657 commit c9eeaa4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
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;
3233
import org.junit.jupiter.api.extension.ExtensionContext;
3334
import org.junit.jupiter.api.extension.RegisterExtension;
3435
import org.slf4j.Logger;
@@ -59,7 +60,7 @@
5960
* tests that use this extension are free to modify what would otherwise be global state on the factory or database.
6061
* </p>
6162
*/
62-
public class FDBDatabaseExtension implements AfterEachCallback {
63+
public class FDBDatabaseExtension implements AfterEachCallback, BeforeEachCallback {
6364
private static final Logger LOGGER = LoggerFactory.getLogger(FDBDatabaseExtension.class);
6465
public static final String BLOCKING_IN_ASYNC_PROPERTY = "com.apple.foundationdb.record.blockingInAsyncDetection";
6566
public static final String API_VERSION_PROPERTY = "com.apple.foundationdb.apiVersion";
@@ -70,6 +71,7 @@ public class FDBDatabaseExtension implements AfterEachCallback {
7071
private FDBDatabaseFactory databaseFactory;
7172
@Nonnull
7273
private final Map<String, FDBDatabase> databases = new HashMap<>();
74+
private String defaultClusterFile;
7375

7476

7577
public FDBDatabaseExtension() {
@@ -103,7 +105,7 @@ private static FDB getInitedFDB() {
103105
for (final String clusterFile : FDBTestEnvironment.allClusterFiles()) {
104106
FDBDatabase unused = baseFactory.getDatabase(clusterFile);
105107
unused.performNoOp(); // make sure FDB gets opened
106-
unused.close();
108+
unused.close(); // FDBDatabase does not implement AutoCloseable
107109
}
108110
fdb = FDB.instance();
109111
}
@@ -145,7 +147,7 @@ public FDBDatabaseFactory getDatabaseFactory() {
145147

146148
@Nonnull
147149
public FDBDatabase getDatabase() {
148-
return getDatabase(FDBTestEnvironment.randomClusterFile());
150+
return getDatabase(defaultClusterFile);
149151
}
150152

151153
public FDBDatabase getDatabase(int clusterIndex) {
@@ -167,6 +169,11 @@ public void checkForOpenContexts() {
167169
}
168170
}
169171

172+
@Override
173+
public void beforeEach(final ExtensionContext context) {
174+
defaultClusterFile = FDBTestEnvironment.randomClusterFile();
175+
}
176+
170177
@Override
171178
public void afterEach(final ExtensionContext extensionContext) {
172179
// Validate that the test closes all the transactions that it opens

0 commit comments

Comments
 (0)