use of org.apache.openejb.config.ConfigurationFactory 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());
}
use of org.apache.openejb.config.ConfigurationFactory 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();
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class FullPoolFailoverTest method setup.
protected void setup(final int statelessPoolSize, final int connectionPoolSize) throws Exception {
Properties initProps = new Properties();
initProps.setProperty("openejb.deployments.classpath.include", "");
initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
OpenEJB.init(initProps, new ServerFederation());
System.setProperty(org.apache.openejb.client.SocketConnectionFactory.PROPERTY_POOL_SIZE, "" + connectionPoolSize);
EjbServer ejbServer = new EjbServer();
ejbServer.init(new Properties());
daemons.add(createServiceDaemon(connectionPoolSize, ejbServer, red));
daemons.add(createServiceDaemon(connectionPoolSize, ejbServer, blue));
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
// containers
StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
statelessContainerInfo.properties.setProperty("TimeOut", "100");
statelessContainerInfo.properties.setProperty("PoolSize", "" + statelessPoolSize);
statelessContainerInfo.properties.setProperty("MinSize", "2");
statelessContainerInfo.properties.setProperty("StrictPooling", "true");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
StatelessBean bean = new StatelessBean(CounterBean.class);
bean.addBusinessLocal(Counter.class.getName());
bean.addBusinessRemote(RemoteCounter.class.getName());
bean.addPostConstruct("init");
bean.addPreDestroy("destroy");
EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(bean);
CounterBean.instances.set(0);
assembler.createApplication(config.configureApplication(ejbJar));
String failoverURI = "failover:sticky:";
failoverURI += "ejbd://127.0.0.1:" + daemons.get(0).getPort() + "?red,";
failoverURI += "ejbd://127.0.0.1:" + daemons.get(1).getPort() + "?blue";
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
props.put("java.naming.provider.url", failoverURI);
Context context = new InitialContext(props);
counter = (Counter) context.lookup("CounterBeanRemote");
hold.clear();
hits.clear();
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class PropertiesPropogationTest method test.
public void test() throws Exception {
EjbServer ejbServer = new EjbServer();
Properties initProps = new Properties();
initProps.setProperty("openejb.deployments.classpath.include", "");
initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
OpenEJB.init(initProps, new ServerFederation());
ejbServer.init(new Properties());
ServicePool pool = new ServicePool(ejbServer, 10);
ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
serviceDaemon.start();
int port = serviceDaemon.getPort();
Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
ConfigurationFactory config = new ConfigurationFactory();
EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
EjbJar ejbJar = ejbModule.getEjbJar();
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
deployment.getProperties().put("openejb.client.color", "red");
EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
assertTrue(beanInfo.properties.containsKey("color"));
assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
assertEquals("orange", beanInfo.properties.get("color"));
assertEquals("red", beanInfo.properties.get("openejb.client.color"));
assembler.createApplication(ejbJarInfo);
ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
BeanContext info = cs.getBeanContext("WidgetBean");
assertNotNull(info);
assertTrue(info.getProperties().containsKey("color"));
assertTrue(info.getProperties().containsKey("openejb.client.color"));
assertEquals("orange", info.getProperties().get("color"));
assertEquals("red", info.getProperties().get("openejb.client.color"));
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
Context context = new InitialContext(props);
Widget remote = (Widget) context.lookup("WidgetBeanRemote");
InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
Properties properties = objectHandler.getEjb().getProperties();
// Should only contain "openejb.client.*" properties
assertFalse(properties.containsKey("color"));
// The openejb.client.color property should have been propogated
assertTrue(properties.containsKey("openejb.client.color"));
assertEquals("red", properties.getProperty("openejb.client.color"));
serviceDaemon.stop();
OpenEJB.destroy();
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class Server2ServerEjbRefTest method test.
public void test() throws Exception {
final Properties initProps = new Properties();
initProps.setProperty("openejb.deployments.classpath.include", "");
initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
OpenEJB.init(initProps, new ServerFederation());
final ServiceDaemon blue = server();
final ServiceDaemon orange = server();
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
final ConfigurationFactory config = new ConfigurationFactory();
final JndiProvider jndiProvider = new JndiProvider("orange");
final Properties p = jndiProvider.getProperties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + orange.getPort());
final JndiContextInfo contextInfo = config.configureService(jndiProvider, JndiContextInfo.class);
assembler.createExternalContext(contextInfo);
{
// Create the "Orange" bean
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
// Lets look it up the normal way to be sure it can work
final InitialContext initialContext = new InitialContext(jndiProvider.getProperties());
final OrangeRemote orangeBeanRemote = (OrangeRemote) initialContext.lookup("OrangeBeanRemote");
assertNotNull(orangeBeanRemote);
}
{
// Create the "Blue" bean
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(BlueBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
// Lets look it up the normal way to be sure it can work
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getPort());
final InitialContext initialContext = new InitialContext(properties);
final BlueRemote blueBeanRemote = (BlueRemote) initialContext.lookup("BlueBeanRemote");
assertNotNull(blueBeanRemote);
blueBeanRemote.hasOrangeRemote();
}
blue.stop();
orange.stop();
OpenEJB.destroy();
}
Aggregations