Search in sources :

Example 1 with DaoTestConfigBean

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);
    }
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 2 with DaoTestConfigBean

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("------------------------------------------------------------------------------");
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) OpenSessionInViewFilter(org.springframework.orm.hibernate3.support.OpenSessionInViewFilter) ServletException(javax.servlet.ServletException) MockDatabase(org.opennms.core.test.db.MockDatabase) MockServletConfig(org.springframework.mock.web.MockServletConfig) CXFServlet(org.apache.cxf.transport.servlet.CXFServlet) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) Before(org.junit.Before)

Example 3 with DaoTestConfigBean

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());
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) Before(org.junit.Before)

Example 4 with DaoTestConfigBean

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);
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockScheduler(org.opennms.netmgt.poller.mock.MockScheduler) MockTimer(org.opennms.netmgt.poller.mock.MockTimer) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockPollContext(org.opennms.netmgt.poller.mock.MockPollContext) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) MockDatabase(org.opennms.core.test.db.MockDatabase) OutageAnticipator(org.opennms.netmgt.mock.OutageAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) Before(org.junit.Before)

Example 5 with DaoTestConfigBean

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());
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) Before(org.junit.Before)

Aggregations

DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)10 Before (org.junit.Before)6 MockDatabase (org.opennms.core.test.db.MockDatabase)4 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 ServletException (javax.servlet.ServletException)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2 MockNetwork (org.opennms.netmgt.mock.MockNetwork)2 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)2 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)2 SQLException (java.sql.SQLException)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 CXFServlet (org.apache.cxf.transport.servlet.CXFServlet)1 MockDestinationPathManager (org.opennms.netmgt.config.mock.MockDestinationPathManager)1 MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)1 MockNotificationCommandManager (org.opennms.netmgt.config.mock.MockNotificationCommandManager)1 MockNotificationManager (org.opennms.netmgt.config.mock.MockNotificationManager)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1