use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class StatefulTimeoutTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
// clear cache every 3 seconds
statefulContainerInfo.properties.setProperty("Frequency", "3");
assembler.createContainer(statefulContainerInfo);
final EjbJar ejbJar = new EjbJar();
Timeout timeout;
final StatefulBean bean1 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class);
timeout = new Timeout();
timeout.setTimeout(-1);
timeout.setUnit(TimeUnit.SECONDS);
bean1.setStatefulTimeout(timeout);
final StatefulBean bean0 = new StatefulBean("BeanZero", MyLocalBeanImpl.class);
timeout = new Timeout();
timeout.setTimeout(0);
timeout.setUnit(TimeUnit.SECONDS);
bean0.setStatefulTimeout(timeout);
final StatefulBean bean5 = new StatefulBean("Bean", MyLocalBeanImpl.class);
timeout = new Timeout();
timeout.setTimeout(5);
timeout.setUnit(TimeUnit.SECONDS);
bean5.setStatefulTimeout(timeout);
ejbJar.addEnterpriseBean(bean1);
ejbJar.addEnterpriseBean(bean0);
ejbJar.addEnterpriseBean(bean5);
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class StatelessInstanceManagerPoolingTest method setUp.
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
statelessContainerInfo.properties.setProperty("TimeOut", "100");
statelessContainerInfo.properties.setProperty("MaxSize", "10");
statelessContainerInfo.properties.setProperty("MinSize", "2");
statelessContainerInfo.properties.setProperty("StrictPooling", "true");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final StatelessBean bean = new StatelessBean(CounterBean.class);
bean.addBusinessLocal(Counter.class.getName());
bean.addBusinessRemote(RemoteCounter.class.getName());
bean.addPostConstruct("init");
bean.addPreDestroy("destroy");
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(bean);
instances.set(0);
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class StatelessInterceptorTest method setUp.
public void setUp() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
assertNotNull(ejbJar);
assembler.createApplication(ejbJar);
final Properties properties = new Properties(System.getProperties());
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
ctx = new InitialContext(properties);
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class DynamicDataSourceTest method route.
@Test
public void route() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// resources
for (int i = 1; i <= 3; i++) {
final String dbName = "database" + i;
final Resource resourceDs = new Resource(dbName, "DataSource");
final Properties p = resourceDs.getProperties();
p.put("JdbcDriver", "org.hsqldb.jdbcDriver");
p.put("JdbcUrl", "jdbc:hsqldb:mem:db" + i);
p.put("UserName", "sa");
p.put("Password", "");
p.put("JtaManaged", "true");
assembler.createResource(config.configureService(resourceDs, ResourceInfo.class));
}
final Resource resourceRouter = new Resource("My Router", "org.apache.openejb.router.test.DynamicDataSourceTest$DeterminedRouter", "org.router:DeterminedRouter");
resourceRouter.getProperties().setProperty("DatasourceNames", "database1 database2 database3");
resourceRouter.getProperties().setProperty("DefaultDataSourceName", "database1");
assembler.createResource(config.configureService(resourceRouter, ResourceInfo.class));
final Resource resourceRoutedDs = new Resource("Routed Datasource", "org.apache.openejb.resource.jdbc.Router", "RoutedDataSource");
resourceRoutedDs.getProperties().setProperty("Router", "My Router");
assembler.createResource(config.configureService(resourceRoutedDs, ResourceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
assembler.createContainer(statelessContainerInfo);
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(RoutedEJBBean.class));
ejbJar.addEnterpriseBean(new StatelessBean(UtilityBean.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
// Create an "ear"
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-dynamic-data-source");
appModule.getEjbModules().add(ejbModule);
// Create a persistence-units
final PersistenceUnit unit = new PersistenceUnit("router");
unit.addClass(Person.class);
unit.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
unit.setTransactionType(TransactionType.JTA);
unit.setJtaDataSource("Routed Datasource");
appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
for (int i = 1; i <= 3; i++) {
final PersistenceUnit u = new PersistenceUnit("db" + i);
u.addClass(Person.class);
u.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
u.setTransactionType(TransactionType.JTA);
u.setJtaDataSource("database" + i);
appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(u)));
}
assembler.createApplication(config.configureApplication(appModule));
// context
final Context ctx = new InitialContext();
// running persist on all "routed" databases
final List<String> databases = new ArrayList<String>();
databases.add("database1");
databases.add("database2");
databases.add("database3");
// convinient bean to create tables for each persistence unit
final Utility utility = (Utility) ctx.lookup("UtilityBeanLocal");
utility.initDatabase();
final RoutedEJB ejb = (RoutedEJB) ctx.lookup("RoutedEJBBeanLocal");
for (int i = 0; i < 18; i++) {
final String name = "record " + i;
final String db = databases.get(i % 3);
ejb.persist(i, name, db);
}
// assert database records number using jdbc
for (int i = 1; i <= 3; i++) {
final Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:db" + i, "sa", "");
final Statement st = connection.createStatement();
final ResultSet rs = st.executeQuery("select count(*) from \"DynamicDataSourceTest$Person\"");
rs.next();
assertEquals(6, rs.getInt(1));
st.close();
connection.close();
}
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class TimeoutAroundTest method _testTimeoutAround.
public void _testTimeoutAround() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
// Configure AroundTimeout by deployment plan
final Interceptor interceptorA = new Interceptor(SimpleInterceptorA.class);
interceptorA.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorA.class.getName(), "interceptorTimeoutAround"));
ejbJar.addInterceptor(interceptorA);
// Configure AroundTimeout by annotation
final Interceptor interceptorB = new Interceptor(SimpleInterceptorB.class);
ejbJar.addInterceptor(interceptorB);
// Override AroundTimeout annotation by deployment plan
final Interceptor interceptorC = new Interceptor(SimpleInterceptorC.class);
interceptorC.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorC.class.getName(), "interceptorTimeoutAround"));
ejbJar.addInterceptor(interceptorC);
// Configure aroundTimeout by deployment plan
final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
subBeanA.addAroundTimeout("beanTimeoutAround");
ejbJar.addEnterpriseBean(subBeanA);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorC));
// Configure aroundTimeout by annotation
final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
ejbJar.addEnterpriseBean(subBeanB);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorC));
// Override aroundTimeout annotation by deployment plan
final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
subBeanC.addAroundTimeout("beanTimeoutAround");
ejbJar.addEnterpriseBean(subBeanC);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorC));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
final InitialContext context = new InitialContext();
final List<Call> expectedResult = Arrays.asList(Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.BEAN_BEFORE_AROUNDTIMEOUT, Call.BEAN_TIMEOUT, Call.BEAN_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT);
{
final BeanInterface beanA = (BeanInterface) context.lookup("SubBeanALocal");
beanA.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanB = (BeanInterface) context.lookup("SubBeanBLocal");
beanB.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanC = (BeanInterface) context.lookup("SubBeanCLocal");
beanC.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
}
Aggregations