Search in sources :

Example 1 with BasePooledProxy

use of com.serotonin.m2m2.db.BasePooledProxy in project ma-core-public by MangoAutomation.

the class MangoTestBase method after.

@After
public void after() {
    // Tear down to simulate some form of shutdown
    for (Module module : ModuleRegistry.getModules()) {
        module.postRuntimeManagerTerminate(false);
    }
    // Need to restart background processing and clear it out
    Common.backgroundProcessing.terminate();
    Common.backgroundProcessing.joinTermination();
    for (Module module : ModuleRegistry.getModules()) {
        module.postTerminate(false);
    }
    // Setup for next test in class
    Common.eventManager.purgeAllEvents();
    Common.backgroundProcessing = lifecycle.getBackgroundProcessing();
    Common.backgroundProcessing.initialize(false);
    SimulationTimerProvider provider = (SimulationTimerProvider) Providers.get(TimerProvider.class);
    provider.reset();
    // Clean the noSQL database
    if (properties.getBoolean("tests.after.deleteAllPointData", true)) {
        try {
            Common.getBean(PointValueDao.class).deleteAllPointData();
        } catch (UnsupportedOperationException e) {
            LOG.warn("PointValueDao does not support deleteAllPointData() method. Your tests may be effected if you reuse this Mango lifecycle");
        }
    }
    // Clear all caches in services
    Common.getRuntimeContext().getBeansOfType(CachingService.class).values().forEach(s -> s.clearCaches(true));
    DatabaseProxy databaseProxy = Common.getBean(DatabaseProxy.class);
    // Try to release active connections if possible
    if (databaseProxy instanceof BasePooledProxy) {
        ((BasePooledProxy) databaseProxy).softEvictConnections();
    }
    // Clean database
    databaseProxy.clean();
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) TimerProvider(com.serotonin.provider.TimerProvider) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Module(com.serotonin.m2m2.module.Module) BasePooledProxy(com.serotonin.m2m2.db.BasePooledProxy) After(org.junit.After)

Example 2 with BasePooledProxy

use of com.serotonin.m2m2.db.BasePooledProxy in project ma-core-public by infiniteautomation.

the class MangoTestBase method after.

@After
public void after() {
    // Tear down to simulate some form of shutdown
    for (Module module : ModuleRegistry.getModules()) {
        module.postRuntimeManagerTerminate(false);
    }
    // Need to restart background processing and clear it out
    Common.backgroundProcessing.terminate();
    Common.backgroundProcessing.joinTermination();
    for (Module module : ModuleRegistry.getModules()) {
        module.postTerminate(false);
    }
    // Setup for next test in class
    Common.eventManager.purgeAllEvents();
    Common.backgroundProcessing = lifecycle.getBackgroundProcessing();
    Common.backgroundProcessing.initialize(false);
    SimulationTimerProvider provider = (SimulationTimerProvider) Providers.get(TimerProvider.class);
    provider.reset();
    // Clean the noSQL database
    if (properties.getBoolean("tests.after.deleteAllPointData", true)) {
        try {
            Common.getBean(PointValueDao.class).deleteAllPointData();
        } catch (UnsupportedOperationException e) {
            LOG.warn("PointValueDao does not support deleteAllPointData() method. Your tests may be effected if you reuse this Mango lifecycle");
        }
    }
    // Clear all caches in services
    Common.getRuntimeContext().getBeansOfType(CachingService.class).values().forEach(s -> s.clearCaches(true));
    DatabaseProxy databaseProxy = Common.getBean(DatabaseProxy.class);
    // Try to release active connections if possible
    if (databaseProxy instanceof BasePooledProxy) {
        ((BasePooledProxy) databaseProxy).softEvictConnections();
    }
    // Clean database
    databaseProxy.clean();
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) TimerProvider(com.serotonin.provider.TimerProvider) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Module(com.serotonin.m2m2.module.Module) BasePooledProxy(com.serotonin.m2m2.db.BasePooledProxy) After(org.junit.After)

Aggregations

BasePooledProxy (com.serotonin.m2m2.db.BasePooledProxy)2 DatabaseProxy (com.serotonin.m2m2.db.DatabaseProxy)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 Module (com.serotonin.m2m2.module.Module)2 TimerProvider (com.serotonin.provider.TimerProvider)2 After (org.junit.After)2