Search in sources :

Example 16 with BrokerService

use of org.apache.activemq.broker.BrokerService in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerTest method contextInitialized_waitUntilStartedReturnsFalse_ExcThrown.

@Test(expected = BrokerLifecycleException.class)
public void contextInitialized_waitUntilStartedReturnsFalse_ExcThrown() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    BrokerService broker = mock(BrokerService.class);
    doReturn(false).when(broker).waitUntilStarted();
    WebBrokerInitializer i = spy(WebBrokerInitializer.class);
    doReturn(broker).when(i).createBroker(sc);
    i.contextInitialized(new ServletContextEvent(sc));
}
Also used : ServletContext(javax.servlet.ServletContext) BrokerService(org.apache.activemq.broker.BrokerService) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 17 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class KahaDBSupportTest method create.

@Test
public void create() throws Exception {
    final String path = "target/kahatest" + System.currentTimeMillis();
    final BrokerService broker = BrokerFactory.createBroker(new URI("openejb:broker:(tcp://localhost:" + NetworkUtil.getNextAvailablePort() + ")?usekahadb=true&kahadb.directory=" + path));
    try {
        assertThat(broker.getPersistenceAdapter(), instanceOf(KahaDBPersistenceAdapter.class));
        final KahaDBPersistenceAdapter adapter = KahaDBPersistenceAdapter.class.cast(broker.getPersistenceAdapter());
        assertEquals(new File(path), adapter.getDirectory());
    } finally {
        broker.stop();
    }
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Test(org.junit.Test)

Example 18 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class OpenEjbBrokerFactoryTest method testLookupDataSource.

public void testLookupDataSource() throws Exception {
    final Properties properties = new Properties();
    final JDBCDataSource dataSource = new JDBCDataSource();
    dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
    dataSource.setUser("sa");
    dataSource.setPassword("");
    dataSource.getConnection().close();
    MockInitialContextFactory.install(Collections.singletonMap("openejb/Resource/TestDs", dataSource));
    assertSame(dataSource, new InitialContext().lookup("openejb/Resource/TestDs"));
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    containerSystem.getJNDIContext().bind("openejb/Resource/TestDs", dataSource);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    properties.put("DataSource", "TestDs");
    properties.put("UseDatabaseLock", "false");
    properties.put("StartupTimeout", "10000");
    ActiveMQFactory.setThreadProperties(properties);
    BrokerService broker = null;
    try {
        broker = BrokerFactory.createBroker(new URI(getBrokerUri("broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
        assertNotNull("broker is null", broker);
        final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
        assertNotNull("persistenceAdapter is null", persistenceAdapter);
        assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter", persistenceAdapter instanceof JDBCPersistenceAdapter);
        final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;
        assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
    } finally {
        stopBroker(broker);
        ActiveMQFactory.setThreadProperties(null);
    }
}
Also used : JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) JDBCDataSource(org.hsqldb.jdbc.JDBCDataSource) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) Properties(java.util.Properties) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) InitialContext(javax.naming.InitialContext) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Example 19 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class ActiveMQ5FactoryTest method duplex.

@Test
public void duplex() throws Exception {
    final int port = getNextAvailablePort();
    for (final boolean b : asList(true, false)) {
        // broker:(tcp://localhost:${port})?networkConnectorURIs=static%3A%2F%2Ftcp%3A%2F%2Flocalhost%3A${port}%3Fduplex%3Dtrue
        final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + port + ")?" + "networkConnectorURIs=" + URLEncoder.encode("static://tcp://localhost:" + port + "?duplex=" + b, "UTF-8"));
        final BrokerService bs = new ActiveMQ5Factory().createBroker(brokerURI);
        bs.stop();
        ActiveMQ5Factory.brokers.remove(brokerURI);
        final NetworkConnector nc = bs.getNetworkConnectors().iterator().next();
        assertEquals("duplex is " + b, b, nc.isDuplex());
    }
}
Also used : NetworkConnector(org.apache.activemq.network.NetworkConnector) URI(java.net.URI) BrokerService(org.apache.activemq.broker.BrokerService) Test(org.junit.Test)

Example 20 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class OpenEjbBrokerFactoryTest method testNoDataSource.

public void testNoDataSource() throws Exception {
    final BrokerService broker = BrokerFactory.createBroker(new URI(getBrokerUri("broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
    assertNotNull("broker is null", broker);
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    assertNotNull("persistenceAdapter is null", persistenceAdapter);
    assertTrue("persistenceAdapter should be an instance of MemoryPersistenceAdapter", persistenceAdapter instanceof MemoryPersistenceAdapter);
    stopBroker(broker);
}
Also used : MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Aggregations

BrokerService (org.apache.activemq.broker.BrokerService)40 Test (org.junit.Test)13 URI (java.net.URI)10 ServletContext (javax.servlet.ServletContext)7 ServletContextEvent (javax.servlet.ServletContextEvent)7 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)5 Before (org.junit.Before)5 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)4 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)4 Properties (java.util.Properties)3 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)3 ServerSocket (java.net.ServerSocket)2 HashMap (java.util.HashMap)2 BrokerPlugin (org.apache.activemq.broker.BrokerPlugin)2 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)2 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)2 SystemUsage (org.apache.activemq.usage.SystemUsage)2 URISupport (org.apache.activemq.util.URISupport)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 JDBCDataSource (org.hsqldb.jdbc.JDBCDataSource)2