use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.
the class ConnectionFactoryIT method testPoolWithSqlExceptions.
public void testPoolWithSqlExceptions() throws Exception {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
AtomikosDataSourceFactory factory = makeFactory("opennms");
factory.afterPropertiesSet();
// Verify the default values
assertEquals(30, factory.poolAvailableSize());
assertEquals(30, factory.poolTotalSize());
// Close the factory so that we can reregister another factory with the same name
factory.close();
final AtomikosDataSourceFactory factory2 = makeFactory("opennms");
factory2.setPoolSize(50);
factory2.afterPropertiesSet();
// Verify the altered values
assertEquals(50, factory2.poolAvailableSize());
assertEquals(50, factory2.poolTotalSize());
// Spawn a bunch of threads that generate continuous SQLExceptions
for (int i = 0; i < 2000; i++) {
new Thread() {
public void run() {
Connection conn = null;
try {
assertEquals(50, factory2.poolTotalSize());
conn = factory2.getConnection();
// Make sure that the total size of the pool stays at 50
assertEquals(50, factory2.poolTotalSize());
assertTrue(factory2.poolAvailableSize() > 0);
// Fetching the current connection will push the available connections below 50
assertTrue(factory2.poolAvailableSize() < 50);
Statement stmt = conn.createStatement();
stmt.execute("BEGIN");
stmt.execute("SELECT * FROM doesnt_exist_in_the_database");
} catch (SQLException e) {
e.printStackTrace();
} finally {
/*
if (conn != null) {
try {
Statement stmt = conn.createStatement();
stmt.execute("ROLLBACK");
conn.close();
} catch (SQLException e) {
fail("Exception thrown when trying to close connection");
}
}
*/
}
}
}.start();
// contention.
if (i % 10 == 0)
Thread.sleep(200);
}
}
use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.
the class AbstractSpringJerseyRestTestCase method setUp.
@Before
public void setUp() throws Throwable {
beforeServletStart();
setUser("admin", new String[] { "ROLE_ADMIN" });
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockDatabase db = new MockDatabase(true);
DataSourceFactory.setInstance(db);
XADataSourceFactory.setInstance(db);
try {
MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
setFilter(new OpenSessionInViewFilter());
getFilter().init(filterConfig);
// Jersey
/*
setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.codehaus.jackson.jaxrs;org.opennms.web.rest;org.opennms.web.rest.config");
getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
setDispatcher(new SpringServlet());
getDispatcher().init(getServletConfig());
*/
// Apache CXF
setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
getServletConfig().addInitParameter("config-location", m_cxfContextPath);
CXFServlet servlet = new CXFServlet();
setDispatcher(servlet);
getDispatcher().init(getServletConfig());
} catch (ServletException se) {
throw se.getRootCause();
}
afterServletStart();
System.err.println("------------------------------------------------------------------------------");
}
use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.
the class ConfigTesterTest method init.
@Before
public void init() {
DaoTestConfigBean daoTestConfig = new DaoTestConfigBean();
daoTestConfig.afterPropertiesSet();
m_dataSource = new ConfigTesterDataSource();
DataSourceFactory.setInstance(m_dataSource);
FilterDaoFactory.setInstance(new ConfigTesterFilterDao());
}
use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.
the class PollablesIT method setUp.
@Before
public void setUp() throws Exception {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_lockCount = 0;
m_mockNetwork = new MockNetwork();
m_mockNetwork.addNode(1, "Router");
m_mockNetwork.addInterface("192.168.1.1");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addInterface("192.168.1.2");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addNode(2, "Server");
m_mockNetwork.addInterface("192.168.1.3");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("HTTP");
m_mockNetwork.addNode(3, "Firewall");
m_mockNetwork.addInterface("192.168.1.4");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addService("HTTP");
m_mockNetwork.addInterface("192.168.1.5");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addService("SNMP");
m_db = new MockDatabase();
m_db.populate(m_mockNetwork);
m_outageAnticipator = new OutageAnticipator(m_db);
m_eventMgr = new MockEventIpcManager();
m_eventMgr.setEventWriter(m_db);
m_eventMgr.addEventListener(m_outageAnticipator);
m_pollContext = new MockPollContext();
m_pollContext.setDatabase(m_db);
m_pollContext.setCriticalServiceName("ICMP");
m_pollContext.setNodeProcessingEnabled(true);
m_pollContext.setPollingAllIfCritServiceUndefined(true);
m_pollContext.setServiceUnresponsiveEnabled(true);
m_pollContext.setEventMgr(m_eventMgr);
m_pollContext.setMockNetwork(m_mockNetwork);
m_pollerConfig = new MockPollerConfig(m_mockNetwork);
m_pollerConfig.setNodeOutageProcessingEnabled(true);
m_pollerConfig.setCriticalService("ICMP");
m_pollerConfig.addPackage("TestPackage");
m_pollerConfig.addDowntime(100L, 0L, 500L, false);
m_pollerConfig.addDowntime(200L, 500L, 1500L, false);
m_pollerConfig.addDowntime(500L, 1500L, -1L, true);
m_pollerConfig.setDefaultPollInterval(1000L);
m_pollerConfig.populatePackage(m_mockNetwork);
m_pollerConfig.addPackage("TestPkg2");
m_pollerConfig.addDowntime(500L, 0L, 1000L, false);
m_pollerConfig.addDowntime(500L, 1000L, -1L, true);
m_pollerConfig.setDefaultPollInterval(2000L);
m_pollerConfig.addService(m_mockNetwork.getService(2, "192.168.1.3", "HTTP"));
m_timer = new MockTimer();
m_scheduler = new MockScheduler(m_timer);
m_network = createPollableNetwork(m_db, m_scheduler, m_pollerConfig, m_pollerConfig, m_pollContext);
// set members to make the tests easier
mNode1 = m_mockNetwork.getNode(1);
mDot1 = mNode1.getInterface("192.168.1.1");
mDot1Smtp = mDot1.getService("SMTP");
mDot1Icmp = mDot1.getService("ICMP");
mDot2 = mNode1.getInterface("192.168.1.2");
mDot2Icmp = mDot2.getService("ICMP");
mNode2 = m_mockNetwork.getNode(2);
mDot3 = mNode2.getInterface("192.168.1.3");
mDot3Http = mDot3.getService("HTTP");
mNode3 = m_mockNetwork.getNode(3);
mDot4 = mNode3.getInterface("192.168.1.4");
mDot4Smtp = mDot4.getService("SMTP");
mDot4Http = mDot4.getService("HTTP");
assignPollableMembers(m_network);
}
use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.
the class MicroblogNotificationStrategyIT method setUpConfigDao.
@Before
public void setUpConfigDao() throws Exception {
DaoTestConfigBean daoTestConfig = new DaoTestConfigBean();
daoTestConfig.setRelativeHomeDirectory("src/test/resources");
daoTestConfig.afterPropertiesSet();
m_daoConfigResource = ConfigurationTestUtils.getSpringResourceForResource(this, "/microblog-configuration.xml");
Assert.assertTrue(m_daoConfigResource.exists());
}
Aggregations