Search in sources :

Example 6 with ServerService

use of org.apache.openejb.server.ServerService in project tomee by apache.

the class FailoverTest method _testCleanShutdown.

public void _testCleanShutdown() throws Exception {
    agent = new TestAgent();
    try {
        // Properties initProps = System.getProperties();
        final Properties initProps = new Properties();
        initProps.setProperty("openejb.deployments.classpath.include", "");
        initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
        OpenEJB.init(initProps, new ServerFederation());
    } catch (Exception e) {
    }
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Target.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    SystemInstance.get().setComponent(DiscoveryAgent.class, agent);
    final ServerService red = server(Host.RED);
    final ServerService blue = server(Host.BLUE);
    final ServerService green = server(Host.GREEN);
    red.start();
    blue.start();
    green.start();
    final TargetRemote target = getBean(red);
    assertEquals(Host.RED, target.getHost());
    red.stop();
    assertEquals(Host.BLUE, target.getHost());
    blue.stop();
    assertEquals(Host.GREEN, target.getHost());
    green.stop();
    try {
        target.getHost();
        fail("EJBException should have been thrown");
    } catch (EJBException e) {
    // pass
    }
    red.start();
    assertEquals(Host.RED, target.getHost());
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServerService(org.apache.openejb.server.ServerService) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) EJBException(javax.ejb.EJBException) ServiceException(org.apache.openejb.server.ServiceException) EjbJar(org.apache.openejb.jee.EjbJar)

Example 7 with ServerService

use of org.apache.openejb.server.ServerService in project tomee by apache.

the class FailoverTest method server.

private ServerService server(final Host host) throws Exception {
    ServerService server = new EjbServer();
    server = new HostFilter(server, host);
    server = new ServiceDaemon(server, 0, "localhost");
    server = new AgentFilter(server, agent, host);
    server.init(new Properties());
    return server;
}
Also used : ServerService(org.apache.openejb.server.ServerService) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) Properties(java.util.Properties)

Example 8 with ServerService

use of org.apache.openejb.server.ServerService in project tomee by apache.

the class FailoverTest method testCrash.

public void testCrash() throws Exception {
    agent = new TestAgent();
    try {
        // Properties initProps = System.getProperties();
        final Properties initProps = new Properties();
        initProps.setProperty("openejb.deployments.classpath.include", "");
        initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
        OpenEJB.init(initProps, new ServerFederation());
    } catch (Exception e) {
    }
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Target.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    SystemInstance.get().setComponent(DiscoveryAgent.class, agent);
    final ServerService red = server(Host.RED);
    final ServerService blue = server(Host.BLUE);
    final ServerService green = server(Host.GREEN);
    red.start();
    blue.start();
    green.start();
    final TargetRemote target = getBean(red);
    assertEquals(Host.GREEN, target.kill(Host.RED, Host.BLUE).host);
    assertEquals(Host.GREEN, target.getHost());
    red.stop();
    blue.stop();
    green.stop();
    try {
        target.getHost();
        fail("EJBException should have been thrown");
    } catch (EJBException e) {
    // pass
    }
    red.start();
    assertEquals(Host.RED, target.getHost());
    red.stop();
    OpenEJB.destroy();
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServerService(org.apache.openejb.server.ServerService) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) EJBException(javax.ejb.EJBException) ServiceException(org.apache.openejb.server.ServiceException) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

ServerService (org.apache.openejb.server.ServerService)8 Properties (java.util.Properties)6 ServiceException (org.apache.openejb.server.ServiceException)4 ServerFederation (org.apache.openejb.core.ServerFederation)3 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)3 IOException (java.io.IOException)2 EJBException (javax.ejb.EJBException)2 NamingException (javax.naming.NamingException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 WebAppBuilder (org.apache.openejb.assembler.classic.WebAppBuilder)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 EjbJar (org.apache.openejb.jee.EjbJar)2 StatelessBean (org.apache.openejb.jee.StatelessBean)2 Test (org.junit.Test)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1