mirror of
https://github.com/signalapp/Signal-Server
synced 2026-10-06 18:18:13 +01:00
Clear FoundationDB databases before each test
This commit is contained in:
1 parent
4443c31ee0
commit
2df897ab0b
1 file changed
+17
-3
+17
-3
@@ -6,15 +6,19 @@
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.apple.foundationdb.FDB;
|
||||
import com.apple.foundationdb.Range;
|
||||
import java.io.IOException;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.whispersystems.textsecuregcm.storage.foundationdb.FaultTolerantDatabase;
|
||||
|
||||
public class FoundationDbClusterExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
|
||||
public class FoundationDbClusterExtension implements BeforeAllCallback, BeforeEachCallback, ExtensionContext.Store.CloseableResource {
|
||||
|
||||
private FoundationDbDatabaseLifecycleManager[] databaseLifecycleManagers;
|
||||
private FaultTolerantDatabase[] databases;
|
||||
private final FoundationDbDatabaseLifecycleManager[] databaseLifecycleManagers;
|
||||
private final FaultTolerantDatabase[] databases;
|
||||
|
||||
private static final Range ALL_KEYS_RANGE = new Range(new byte[] {}, new byte[] {(byte) 0xff});
|
||||
|
||||
public FoundationDbClusterExtension(final int numInstances) {
|
||||
this.databaseLifecycleManagers = new FoundationDbDatabaseLifecycleManager[numInstances];
|
||||
@@ -38,6 +42,16 @@ public class FoundationDbClusterExtension implements BeforeAllCallback, Extensio
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEach(final ExtensionContext context) throws Exception {
|
||||
for (final FaultTolerantDatabase database : databases) {
|
||||
database.run(transaction -> {
|
||||
transaction.clear(ALL_KEYS_RANGE);
|
||||
return null;
|
||||
}, FaultTolerantDatabase.Context.TEST);
|
||||
}
|
||||
}
|
||||
|
||||
public FaultTolerantDatabase[] getDatabases() {
|
||||
return databases;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user