Search in sources :

Example 46 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class StatelessInvocationStatsTest method testBasic.

/**
 * This whole method is a template, feel free to split it anyway you like
 * Fine to have one big
 *
 * @throws Exception On error
 */
@Test
public void testBasic() throws Exception {
    // some pre-load to avoid to load the class lazily with the first invocation
    new CounterBean().red();
    new CounterBean().blue();
    new CounterBean().green();
    // end preload
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, OpenEJBInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("AccessTimeout", "100");
    statelessContainerInfo.properties.setProperty("MaxSize", "15");
    statelessContainerInfo.properties.setProperty("MinSize", "3");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    CounterBean.instances.set(0);
    final EjbJar ejbJar = new EjbJar("StatsModule");
    ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final javax.naming.Context context = new InitialContext();
    final CounterBean bean = (CounterBean) context.lookup("CounterBeanLocalBean");
    // Invoke each method once
    bean.red();
    bean.green();
    bean.blue();
    final MBeanServer server = LocalMBeanServer.get();
    final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsModule,StatelessSessionBean=CounterBean," + "j2eeType=Invocations,name=CounterBean");
    // Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
    /*
         * Invocation MBeanInfo
         *
         */
    final List<MBeanAttributeInfo> expectedAttributes = new ArrayList<>();
    expectedAttributes.add(new MBeanAttributeInfo("InvocationCount", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InvocationTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MonitoredMethods", "long", "", true, false, false));
    final Map<String, Object> expectedValues = new TreeMap<>();
    expectedValues.put("InvocationCount", (long) 6);
    expectedValues.put("InvocationTime", (long) 0);
    expectedValues.put("MonitoredMethods", (long) 4);
    final String[] methods = { "PostConstruct()", "blue()", "green()", "red()" };
    for (final String s : methods) {
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Count", "long", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".GeometricMean", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Kurtosis", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Max", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Mean", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Min", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile01", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile10", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile25", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile50", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile75", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile90", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile99", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".SampleSize", "int", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Skewness", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".StandardDeviation", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Sum", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Sumsq", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Variance", "double", "", true, false, false));
        if (s.equals("PostConstruct()")) {
            expectedValues.put(s + ".Count", (long) 3);
        } else {
            expectedValues.put(s + ".Count", (long) 1);
        }
        expectedValues.put(s + ".GeometricMean", 0.0);
        expectedValues.put(s + ".Kurtosis", Double.NaN);
        expectedValues.put(s + ".Max", 0.0);
        expectedValues.put(s + ".Mean", 0.0);
        expectedValues.put(s + ".Min", 0.0);
        expectedValues.put(s + ".Percentile01", 0.0);
        expectedValues.put(s + ".Percentile10", 0.0);
        expectedValues.put(s + ".Percentile25", 0.0);
        expectedValues.put(s + ".Percentile50", 0.0);
        expectedValues.put(s + ".Percentile75", 0.0);
        expectedValues.put(s + ".Percentile90", 0.0);
        expectedValues.put(s + ".Percentile99", 0.0);
        expectedValues.put(s + ".SampleSize", 2000);
        expectedValues.put(s + ".Skewness", Double.NaN);
        expectedValues.put(s + ".StandardDeviation", 0.0);
        expectedValues.put(s + ".Sum", 0.0);
        expectedValues.put(s + ".Sumsq", 0.0);
        expectedValues.put(s + ".Variance", 0.0);
    }
    final List<MBeanAttributeInfo> actualAttributes = new ArrayList<>();
    final Map<String, Object> actualValues = new TreeMap<>();
    final MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
    for (final MBeanAttributeInfo info : beanInfo.getAttributes()) {
        actualAttributes.add(info);
        actualValues.put(info.getName(), server.getAttribute(invocationsName, info.getName()));
    }
    // Verify invocation attributes and values
    Assert.assertEquals(expectedAttributes, actualAttributes);
    boolean ok = true;
    for (final Map.Entry<String, Object> entry : actualValues.entrySet()) {
        final Number value = (Number) expectedValues.get(entry.getKey());
        final Number real = (Number) actualValues.get(entry.getKey());
        if (!value.equals(real)) {
            // tolerating a 1 wide range
            Logger.getLogger(StatelessInvocationStatsTest.class.getName()).log(Level.WARNING, "Test tolerance: " + entry.getKey() + " => " + entry.getValue() + "/" + expectedValues.get(entry.getKey()));
            final Double abs = Math.abs(real.doubleValue() - value.doubleValue());
            if (abs.intValue() > 1) {
                ok = false;
            }
        }
    }
    Assert.assertTrue("Expected status to be true, but was: " + ok, ok);
    // Grab invocation mbean operations
    final MBeanParameterInfo[] invocationParameters1 = { new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""), new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"") };
    final MBeanParameterInfo[] invocationParameters2 = { new MBeanParameterInfo("p1", "int", "") };
    final List<MBeanOperationInfo> expectedOperations = new ArrayList<>();
    expectedOperations.add(new MBeanOperationInfo("FilterAttributes", "Filters the attributes that show up in the MBeanInfo.  The exclude is applied first, then any attributes that match the include are re-added.  It may be required to " + "disconnect and reconnect the JMX console to force a refresh of the MBeanInfo", invocationParameters1, "void", MBeanOperationInfo.UNKNOWN));
    for (final String s : methods) {
        expectedOperations.add(new MBeanOperationInfo(s + ".setSampleSize", "", invocationParameters2, "void", MBeanOperationInfo.UNKNOWN));
        expectedOperations.add(new MBeanOperationInfo(s + ".sortedValues", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
        expectedOperations.add(new MBeanOperationInfo(s + ".values", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
    }
    final List<MBeanOperationInfo> actualOperations1 = new ArrayList<>();
    actualOperations1.addAll(Arrays.asList(beanInfo.getOperations()));
    // Verify invocation operation information and remove bean.
    Assert.assertEquals(expectedOperations, actualOperations1);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) OpenEJBInitialContextFactory(org.apache.openejb.core.OpenEJBInitialContextFactory) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanOperationInfo(javax.management.MBeanOperationInfo) TreeMap(java.util.TreeMap) InitialContext(javax.naming.InitialContext) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) Map(java.util.Map) TreeMap(java.util.TreeMap) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 47 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class StatelessPoolStatsTest method deploy.

private CounterBean deploy(final String moduleId, final Properties properties) throws Exception {
    objectName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=" + moduleId + ",StatelessSessionBean=CounterBean,j2eeType=Pool,name=CounterBean");
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, org.apache.openejb.core.LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.putAll(properties);
    assembler.createContainer(statelessContainerInfo);
    final EjbJar ejbJar = new EjbJar(moduleId);
    ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final javax.naming.Context context = new InitialContext();
    return (CounterBean) context.lookup("CounterBeanLocalBean");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitialContext(javax.naming.InitialContext) ObjectName(javax.management.ObjectName) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 48 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class FullyInterceptedTest method module.

@Module
public EjbJar module() {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(FullyInterceptedBean.class));
    final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
    final InterceptorBinding b = assembly.addInterceptorBinding(new InterceptorBinding(bean));
    b.setExcludeDefaultInterceptors(true);
    b.setMethod(new NamedMethod("methodWithDefaultInterceptorsExcluded"));
    return ejbJar;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) NamedMethod(org.apache.openejb.jee.NamedMethod) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Example 49 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class InterceptorBindingEjbTest method ejbJar.

/**
 * aims to test that method level cdi interceptors are well managed (and not all merged in class level interceptors).
 *
 * @return the needed module
 */
@Module
public EjbModule ejbJar() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("ejb1", EJB1.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb2", EJB2.class));
    final Beans beans = new Beans();
    beans.addInterceptor(MarkedInterceptor.class);
    final EjbModule module = new EjbModule(ejbJar);
    module.setBeans(beans);
    return module;
}
Also used : Beans(org.apache.openejb.jee.Beans) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 50 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class MethodLevelInterceptorOnlyTest method module.

@Module
public EjbJar module() {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(MethodLevelInterceptorOnlySLSBean.class));
    final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
    assembly.addInterceptorBinding(new InterceptorBinding(bean)).setExcludeDefaultInterceptors(true);
    return ejbJar;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Aggregations

EjbJar (org.apache.openejb.jee.EjbJar)242 StatelessBean (org.apache.openejb.jee.StatelessBean)117 Assembler (org.apache.openejb.assembler.classic.Assembler)88 EjbModule (org.apache.openejb.config.EjbModule)81 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)76 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)60 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)60 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)50 Properties (java.util.Properties)49 InitialContext (javax.naming.InitialContext)43 SingletonBean (org.apache.openejb.jee.SingletonBean)42 AppModule (org.apache.openejb.config.AppModule)40 StatefulBean (org.apache.openejb.jee.StatefulBean)33 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)31 Module (org.apache.openejb.testing.Module)30 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)27 Test (org.junit.Test)26 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)25 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)24 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)21