Cleaning up the cache of Builders after each test has ran

This commit is contained in:
Raf Ponsaerts
2020-10-12 15:21:38 +02:00
parent 01e61aedff
commit ce04f78703
3 changed files with 16 additions and 1 deletions

View File

@@ -192,6 +192,8 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati
// Reload our ConfigurationService (to reset configs to defaults again)
DSpaceServicesFactory.getInstance().getConfigurationService().reloadConfig();
AbstractBuilder.cleanupBuilderCache();
// NOTE: we explicitly do NOT destroy our default eperson & admin as they
// are cached and reused for all tests. This speeds up all tests.
} catch (Exception e) {

View File

@@ -195,6 +195,10 @@ public abstract class AbstractBuilder<T, S> {
}
}
public static void cleanupBuilderCache() {
abstractBuilderCleanupUtil.cleanupMap();
}
/**
* This method will ensure that the DSpaceObject contained within the Builder will be cleaned up properly
* @throws Exception If something goes wrong

View File

@@ -46,6 +46,11 @@ public class AbstractBuilderCleanupUtil {
* Constructor that will initialize the Map with a predefined order for deletion
*/
public AbstractBuilderCleanupUtil() {
initMap();
}
private void initMap() {
map.put(RelationshipBuilder.class.getName(), new LinkedList<>());
map.put(RelationshipTypeBuilder.class.getName(), new LinkedList<>());
map.put(EntityTypeBuilder.class.getName(), new LinkedList<>());
@@ -64,7 +69,6 @@ public class AbstractBuilderCleanupUtil {
map.put(MetadataSchemaBuilder.class.getName(), new LinkedList<>());
map.put(SiteBuilder.class.getName(), new LinkedList<>());
map.put(ProcessBuilder.class.getName(), new LinkedList<>());
}
/**
@@ -90,4 +94,9 @@ public class AbstractBuilderCleanupUtil {
}
}
}
public void cleanupMap() {
this.map.clear();
initMap();
}
}