29
29
import com .apple .foundationdb .test .FDBTestEnvironment ;
30
30
import com .apple .foundationdb .test .TestExecutors ;
31
31
import org .junit .jupiter .api .extension .AfterEachCallback ;
32
- import org .junit .jupiter .api .extension .BeforeEachCallback ;
33
32
import org .junit .jupiter .api .extension .ExtensionContext ;
34
33
import org .junit .jupiter .api .extension .RegisterExtension ;
35
34
import org .slf4j .Logger ;
60
59
* tests that use this extension are free to modify what would otherwise be global state on the factory or database.
61
60
* </p>
62
61
*/
63
- public class FDBDatabaseExtension implements AfterEachCallback , BeforeEachCallback {
62
+ public class FDBDatabaseExtension implements AfterEachCallback {
64
63
private static final Logger LOGGER = LoggerFactory .getLogger (FDBDatabaseExtension .class );
65
64
public static final String BLOCKING_IN_ASYNC_PROPERTY = "com.apple.foundationdb.record.blockingInAsyncDetection" ;
66
65
public static final String API_VERSION_PROPERTY = "com.apple.foundationdb.apiVersion" ;
@@ -71,7 +70,7 @@ public class FDBDatabaseExtension implements AfterEachCallback, BeforeEachCallba
71
70
private FDBDatabaseFactory databaseFactory ;
72
71
@ Nonnull
73
72
private final Map <String , FDBDatabase > databases = new HashMap <>();
74
- private String defaultClusterFile ;
73
+ private String defaultClusterFile = FDBTestEnvironment . randomClusterFile () ;
75
74
76
75
77
76
public FDBDatabaseExtension () {
@@ -169,11 +168,6 @@ public void checkForOpenContexts() {
169
168
}
170
169
}
171
170
172
- @ Override
173
- public void beforeEach (final ExtensionContext context ) {
174
- defaultClusterFile = FDBTestEnvironment .randomClusterFile ();
175
- }
176
-
177
171
@ Override
178
172
public void afterEach (final ExtensionContext extensionContext ) {
179
173
// Validate that the test closes all the transactions that it opens
@@ -186,5 +180,7 @@ public void afterEach(final ExtensionContext extensionContext) {
186
180
getDatabaseFactory ().clear ();
187
181
databaseFactory = null ;
188
182
}
183
+ // we don't do this in a beforeEach, in case a test is accessing the database in the constructor.
184
+ defaultClusterFile = FDBTestEnvironment .randomClusterFile ();
189
185
}
190
186
}
0 commit comments