use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptorIT method testThresholds.
@Test
@JUnitTemporaryDatabase(tempDbClass = MockDatabase.class)
public void testThresholds() throws Exception {
EventBuilder bldr = new EventBuilder(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "LatencyStoringServiceMonitorAdaptorTest");
bldr.setNodeid(1);
bldr.setInterface(addr("127.0.0.1"));
bldr.setService("ICMP");
m_eventIpcManager.getEventAnticipator().anticipateEvent(bldr.getEvent());
bldr = new EventBuilder(EventConstants.HIGH_THRESHOLD_REARM_EVENT_UEI, "LatencyStoringServiceMonitorAdaptorTest");
bldr.setNodeid(1);
bldr.setInterface(addr("127.0.0.1"));
bldr.setService("ICMP");
m_eventIpcManager.getEventAnticipator().anticipateEvent(bldr.getEvent());
// This should emulate a trigger and a rearm
executeThresholdTest(new Double[] { 100.0, 10.0 });
m_eventIpcManager.getEventAnticipator().verifyAnticipated();
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class TemporaryDatabaseExecutionListener method beforeTestClass.
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
TemporaryDatabasePostgreSQL.failIfUnitTest();
// Fire up a thread pool for each CPU to create test databases
ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
final JUnitTemporaryDatabase classJtd = testContext.getTestClass().getAnnotation(JUnitTemporaryDatabase.class);
final Future<TemporaryDatabase> classDs;
if (classJtd != null) {
classDs = pool.submit(new CreateNewDatabaseCallable(classJtd, testContext.getTestClass().getName(), null));
if (classJtd.reuseDatabase() == false) {
m_createNewDatabases = true;
}
} else {
classDs = null;
}
List<Future<TemporaryDatabase>> futures = new ArrayList<Future<TemporaryDatabase>>();
for (Method method : getOrderedTestMethods(testContext.getTestClass())) {
if (method != null) {
final JUnitTemporaryDatabase methodJtd = method.getAnnotation(JUnitTemporaryDatabase.class);
boolean methodHasTest = method.getAnnotation(Test.class) != null;
if (methodHasTest) {
// If there is a method-specific annotation, use it to create the temporary database
if (methodJtd != null) {
// Create a new database based on the method-specific annotation
Future<TemporaryDatabase> submit = pool.submit(new CreateNewDatabaseCallable(methodJtd, testContext.getTestClass().getName(), method.getName()));
Assert.notNull(submit, "pool.submit(new CreateNewDatabaseCallable(methodJtd = " + methodJtd + ")");
futures.add(submit);
} else if (classJtd != null) {
if (m_createNewDatabases) {
// Create a new database based on the test class' annotation
Future<TemporaryDatabase> submit = pool.submit(new CreateNewDatabaseCallable(classJtd, testContext.getTestClass().getName(), method.getName()));
Assert.notNull(submit, "pool.submit(new CreateNewDatabaseCallable(classJtd = " + classJtd + ")");
futures.add(submit);
} else {
// Reuse the database based on the test class' annotation
Assert.notNull(classDs, "classDs");
futures.add(classDs);
}
}
}
}
}
for (Future<TemporaryDatabase> db : futures) {
m_databases.add(db.get());
}
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class TemporaryDatabaseExecutionListener method findAnnotation.
private static JUnitTemporaryDatabase findAnnotation(final TestContext testContext) {
JUnitTemporaryDatabase jtd = null;
final Method testMethod = testContext.getTestMethod();
if (testMethod != null) {
jtd = testMethod.getAnnotation(JUnitTemporaryDatabase.class);
}
if (jtd == null) {
final Class<?> testClass = testContext.getTestClass();
jtd = testClass.getAnnotation(JUnitTemporaryDatabase.class);
}
return jtd;
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class MigratorIT method testMultipleChangelogs.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testMultipleChangelogs() throws Exception {
assertFalse(changelogExists());
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
// from the classpath
for (final Resource resource : getTestResources()) {
URI uri = resource.getURI();
if (uri.getScheme().equals("jar") && !uri.toString().contains("test-api.schema"))
continue;
if (uri.getScheme().equals("file") && !uri.toString().contains("test-api/schema"))
continue;
LOG.info("=== found resource: {} ===", resource);
migration.setAccessor(new ExistingResourceAccessor(resource));
m.migrate(migration);
}
final List<ChangelogEntry> ids = getChangelogEntries();
assertTrue(ids.size() > 0);
assertEquals("test-api.schema.a", ids.get(0).getId());
assertEquals("test-api.schema.b", ids.get(1).getId());
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class MigratorIT method testRealChangelog.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testRealChangelog() throws Exception {
assertFalse(changelogExists());
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
// from the classpath
for (final Resource resource : getRealChangelog()) {
LOG.info("=== found resource: {} ===", resource);
migration.setAccessor(new ExistingResourceAccessor(resource));
m.migrate(migration);
}
final List<ChangelogEntry> ids = getChangelogEntries();
assertTrue(ids.size() > 0);
// Check to make sure some of the changelogs ran
assertTrue(ids.stream().anyMatch(id -> "17.0.0-remove-legacy-ipinterface-composite-key-fields".equals(id.getId())));
assertTrue(ids.stream().anyMatch(id -> "17.0.0-remove-legacy-outages-composite-key-fields".equals(id.getId())));
}
Aggregations