Search in sources :

Example 1 with SimulationTimerProvider

use of com.serotonin.m2m2.SimulationTimerProvider 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 SimulationTimerProvider

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

the class MigrationPointValueDaoTest method getLifecycle.

@Override
protected MockMangoLifecycle getLifecycle() {
    MockMangoLifecycle lifecycle = super.getLifecycle();
    lifecycle.setTimer(new SimulationTimerProvider(new SimulationTimer(ZoneOffset.UTC)));
    return lifecycle;
}
Also used : SimulationTimer(com.serotonin.timer.SimulationTimer) SimulationTimerProvider(com.serotonin.m2m2.SimulationTimerProvider) MockMangoLifecycle(com.serotonin.m2m2.MockMangoLifecycle)

Example 3 with SimulationTimerProvider

use of com.serotonin.m2m2.SimulationTimerProvider 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)

Example 4 with SimulationTimerProvider

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

the class MangoTestBase method before.

@Before
public void before() {
    createTestDB();
    // So it only happens once per class for now (problems with restarting lifecycle during a running JVM)
    if (lifecycle == null) {
        lifecycle = getLifecycle();
        try {
            lifecycle.initialize();
        } catch (Exception e) {
            throw new RuntimeException("Lifecycle failed to initialize", e);
        }
    } else {
        // Re-initialize database
        Common.getBean(DatabaseProxy.class).initialize();
        // Lifecycle hook for things that need to run to install into a new database
        for (Module module : ModuleRegistry.getModules()) {
            module.postDatabase();
        }
        // Fix cached users for new database
        Common.getBean(UsersService.class).clearCaches(false);
    }
    SimulationTimerProvider provider = (SimulationTimerProvider) Providers.get(TimerProvider.class);
    this.timer = provider.getSimulationTimer();
}
Also used : UsersService(com.infiniteautomation.mango.spring.service.UsersService) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) TimerProvider(com.serotonin.provider.TimerProvider) Module(com.serotonin.m2m2.module.Module) JsonException(com.serotonin.json.JsonException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) Before(org.junit.Before)

Example 5 with SimulationTimerProvider

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

the class MangoTestBase method before.

@Before
public void before() {
    createTestDB();
    // So it only happens once per class for now (problems with restarting lifecycle during a running JVM)
    if (lifecycle == null) {
        lifecycle = getLifecycle();
        try {
            lifecycle.initialize();
        } catch (InterruptedException | ExecutionException e) {
            fail(e.getMessage());
        }
    } else {
        // Re-initialize database
        Common.getBean(DatabaseProxy.class).initialize();
        // Lifecycle hook for things that need to run to install into a new database
        for (Module module : ModuleRegistry.getModules()) {
            module.postDatabase();
        }
        // Fix cached users for new database
        Common.getBean(UsersService.class).clearCaches(false);
    }
    SimulationTimerProvider provider = (SimulationTimerProvider) Providers.get(TimerProvider.class);
    this.timer = provider.getSimulationTimer();
}
Also used : UsersService(com.infiniteautomation.mango.spring.service.UsersService) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) TimerProvider(com.serotonin.provider.TimerProvider) ExecutionException(java.util.concurrent.ExecutionException) Module(com.serotonin.m2m2.module.Module) Before(org.junit.Before)

Aggregations

DatabaseProxy (com.serotonin.m2m2.db.DatabaseProxy)4 Module (com.serotonin.m2m2.module.Module)4 TimerProvider (com.serotonin.provider.TimerProvider)4 UsersService (com.infiniteautomation.mango.spring.service.UsersService)2 BasePooledProxy (com.serotonin.m2m2.db.BasePooledProxy)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 After (org.junit.After)2 Before (org.junit.Before)2 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)1 JsonException (com.serotonin.json.JsonException)1 MockMangoLifecycle (com.serotonin.m2m2.MockMangoLifecycle)1 SimulationTimerProvider (com.serotonin.m2m2.SimulationTimerProvider)1 SimulationTimer (com.serotonin.timer.SimulationTimer)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ExecutionException (java.util.concurrent.ExecutionException)1