repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
---|---|---|---|---|---|---|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/serverside/protocol/ProtocolSampleInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.serverside.protocol;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
public class ProtocolSampleInterceptor {
static final String PREFIX = "ProtocolInterceptor:";
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
return PREFIX + invocationContext.proceed();
}
}
| 1,458 | 40.685714 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/serverside/protocol/RemoteProtocolChangeTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.serverside.protocol;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.PropertyPermission;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.shared.integration.ejb.interceptor.serverside.AbstractServerInterceptorsSetupTask;
import org.jboss.as.test.shared.integration.ejb.interceptor.serverside.InterceptorModule;
import org.jboss.as.test.integration.ejb.interceptor.serverside.SampleBean;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* A test case verifying server-side interceptor execution after changing JBoss Remoting protocol.
*
* @author Sultan Zhantemirov
*/
@RunWith(Arquillian.class)
@ServerSetup(RemoteProtocolChangeTestCase.SetupTask.class)
public class RemoteProtocolChangeTestCase {
private static Context ctx;
@Deployment
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "remote-protocol-interceptor-test.jar");
jar.addClasses(SampleBean.class, TestSuiteEnvironment.class);
jar.addPackage(RemoteProtocolChangeTestCase.class.getPackage());
jar.addPackage(AbstractServerInterceptorsSetupTask.class.getPackage());
jar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission("management.address", "read"),
new PropertyPermission("node0", "read")
), "permissions.xml");
return jar;
}
@Test
@InSequence(1)
public void initialCheck() throws Exception {
final Hashtable<String, String> props = new Hashtable<>();
props.put(Context.PROVIDER_URL, "http-remoting://" + TestSuiteEnvironment.getServerAddress() + ":8080");
ctx = new InitialContext(props);
final SampleBean bean1 = (SampleBean) ctx.lookup("java:module/" + SampleBean.class.getSimpleName());
Assert.assertEquals(ProtocolSampleInterceptor.PREFIX + SampleBean.class.getSimpleName(), bean1.getSimpleName());
}
@Test
@InSequence(2)
public void otherRemoteProtocolCheck() throws Exception {
final Hashtable<String, String> props = new Hashtable<>();
props.put(Context.PROVIDER_URL, "remoting://" + TestSuiteEnvironment.getServerAddress() + ":8080");
ctx = new InitialContext(props);
final SampleBean bean2 = (SampleBean) ctx.lookup("java:module/" + SampleBean.class.getSimpleName());
Assert.assertEquals(ProtocolSampleInterceptor.PREFIX + SampleBean.class.getSimpleName(), bean2.getSimpleName());
}
static class SetupTask extends AbstractServerInterceptorsSetupTask.SetupTask {
@Override
public List<InterceptorModule> getModules() {
return Collections.singletonList(new InterceptorModule(
ProtocolSampleInterceptor.class,
"interceptor-module-protocol",
"module.xml",
RemoteProtocolChangeTestCase.class.getResource("module.xml"),
"server-side-interceptor-protocol.jar"
)
);
}
}
}
| 4,761 | 43.092593 | 120 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/serverside/secured/SecuredBeanTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.serverside.secured;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import jakarta.ejb.EJBAccessException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.shared.integration.ejb.interceptor.serverside.AbstractServerInterceptorsSetupTask;
import org.jboss.as.test.shared.integration.ejb.interceptor.serverside.InterceptorModule;
import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* A test case verifying server-side interceptor execution while accessing an EJB with @RolesAllowed, @DenyAll and @PermitAll security annotations.
* See https://issues.jboss.org/browse/WFLY-6143 for more details.
*
* @author <a href="mailto:[email protected]">Sultan Zhantemirov</a> (c) 2019 Red Hat, inc.
*/
@RunWith(Arquillian.class)
@ServerSetup({SecuredBeanTestCase.SetupTask.class, EjbSecurityDomainSetup.class})
public class SecuredBeanTestCase {
static final int EJB_INVOKED_METHODS_COUNT = 4;
@ArquillianResource
private static InitialContext ctx;
@Deployment
public static Archive<?> runAsDeployment() {
final Package currentPackage = SecuredBeanTestCase.class.getPackage();
// using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly
return ShrinkWrap.create(WebArchive.class, "ejb3security.war")
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addClass(Util.class)
.addClasses(SampleInterceptor.class)
.addPackage(AbstractServerInterceptorsSetupTask.class.getPackage())
.addPackage(SecuredBeanTestCase.class.getPackage())
.addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.xml")
.addAsManifestResource(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.controller-client,org.jboss.dmr\n"), "MANIFEST.MF")
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml");
}
@Test
@InSequence(1)
public void securedBeanAccessCheck() throws NamingException {
ctx = new InitialContext();
SecuredBean bean = (SecuredBean) ctx.lookup("java:module/" + SecuredBean.class.getSimpleName());
bean.permitAll("permitAll");
try {
bean.denyAll("denyAll");
Assert.fail("it was supposed to throw EJBAccessException");
}
catch (EJBAccessException ie){
// expected
}
}
@Test
@InSequence(2)
public void securedBeanRoleCheck() throws Exception {
final Callable<Void> callable = () -> {
ctx = new InitialContext();
SecuredBean bean = (SecuredBean) ctx.lookup("java:module/" + SecuredBean.class.getSimpleName());
try {
bean.roleEcho("role1access");
} catch (EJBAccessException ignored) {
}
try {
bean.role2Echo("access");
} catch (EJBAccessException e) {
// expected
}
Assert.assertEquals(0, SampleInterceptor.latch.getCount());
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
static class SetupTask extends AbstractServerInterceptorsSetupTask.SetupTask {
@Override
public List<InterceptorModule> getModules() {
return Collections.singletonList(new InterceptorModule(
SampleInterceptor.class,
"interceptor-module-secured",
"module.xml",
SecuredBeanTestCase.class.getResource("module.xml"),
"server-side-interceptor-secured.jar"
)
);
}
}
}
| 5,590 | 41.037594 | 157 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/serverside/secured/SecuredBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.serverside.secured;
import jakarta.annotation.Resource;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
@Stateless
public class SecuredBean {
@Resource
private SessionContext sessionContext;
@PermitAll
public String permitAll(String message) {
return message;
}
@DenyAll
public void denyAll(String message) {
}
@RolesAllowed("Role1")
public String roleEcho(final String message) {
return message;
}
@RolesAllowed("Role2")
public String role2Echo(final String message) {
return message;
}
}
| 1,811 | 30.789474 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/serverside/secured/SampleInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.serverside.secured;
import java.util.concurrent.CountDownLatch;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
public class SampleInterceptor {
public static final CountDownLatch latch = new CountDownLatch(SecuredBeanTestCase.EJB_INVOKED_METHODS_COUNT);
public SampleInterceptor() {
}
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
try {
return invocationContext.proceed();
} finally {
latch.countDown();
}
}
}
| 1,660 | 37.627907 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/XMLInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import java.util.ArrayList;
import jakarta.interceptor.InvocationContext;
import javax.sql.DataSource;
/**
* @author <a href="[email protected]">Kabir Khan</a>
*/
public class XMLInterceptor {
MySession2 session2;
DataSource ds;
MySession2Local session2Method;
DataSource dsMethod;
public void setSession2Method(MySession2Local session2Method) {
this.session2Method = session2Method;
}
public void setDsMethod(DataSource dsMethod) {
this.dsMethod = dsMethod;
}
public Object intercept(InvocationContext ctx) throws Exception {
session2.doit();
if (ds == null) { throw new RuntimeException("ds was null"); }
session2Method.doit();
if (dsMethod == null) { throw new RuntimeException("ds was null"); }
ArrayList list = new ArrayList();
list.add("MyInterceptor");
return list;
}
}
| 1,988 | 32.711864 | 76 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MySession2.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.ejb.Remote;
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
@Remote
public interface MySession2 {
boolean doit();
}
| 1,241 | 35.529412 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MyInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceUnit;
import javax.sql.DataSource;
import jakarta.transaction.TransactionManager;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
public class MyInterceptor extends MyBaseInterceptor {
@EJB
MySession2 session2;
@Resource(mappedName = "java:/TransactionManager")
TransactionManager tm;
@Resource(name = "DefaultDS", mappedName = "java:jboss/datasources/ExampleDS")
DataSource ds;
@PersistenceContext(unitName = "interceptors-test")
EntityManager em;
@PersistenceContext(unitName = "interceptors-test")
Session session;
@PersistenceUnit(unitName = "interceptors-test")
EntityManagerFactory factory;
@PersistenceUnit(unitName = "interceptors-test")
SessionFactory sessionFactory;
MySession2 session2Method;
TransactionManager tmMethod;
DataSource dsMethod;
EntityManager emMethod;
Session sessionMethod;
EntityManagerFactory factoryMethod;
SessionFactory sessionFactoryMethod;
@EJB
public void setSession2Method(MySession2 session2Method) {
this.session2Method = session2Method;
}
@Resource(mappedName = "java:/TransactionManager")
public void setTmMethod(TransactionManager tmMethod) {
this.tmMethod = tmMethod;
}
@Resource(name = "DefaultDS", mappedName = "java:DefaultDS")
public void setDsMethod(DataSource dsMethod) {
this.dsMethod = dsMethod;
}
@PersistenceContext(unitName = "interceptors-test")
public void setEmMethod(EntityManager emMethod) {
this.emMethod = emMethod;
}
@PersistenceContext(unitName = "interceptors-test")
public void setSessionMethod(Session sessionMethod) {
this.sessionMethod = sessionMethod;
}
@PersistenceUnit(unitName = "interceptors-test")
public void setFactoryMethod(EntityManagerFactory factoryMethod) {
this.factoryMethod = factoryMethod;
}
@PersistenceUnit(unitName = "interceptors-test")
public void setSessionFactoryMethod(SessionFactory sessionFactoryMethod) {
this.sessionFactoryMethod = sessionFactoryMethod;
}
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
session2.doit();
if (tm == null) { throw new RuntimeException("tm was null"); }
if (ds == null) { throw new RuntimeException("ds was null"); }
if (em == null) { throw new RuntimeException("em was null"); }
if (session == null) { throw new RuntimeException("session was null"); }
if (factory == null) { throw new RuntimeException("factory was null"); }
if (sessionFactory == null) { throw new RuntimeException("sessionFactory was null"); }
session2Method.doit();
if (tmMethod == null) { throw new RuntimeException("tm was null"); }
if (dsMethod == null) { throw new RuntimeException("ds was null"); }
if (emMethod == null) { throw new RuntimeException("em was null"); }
if (sessionMethod == null) { throw new RuntimeException("session was null"); }
if (factoryMethod == null) { throw new RuntimeException("factory was null"); }
if (sessionFactoryMethod == null) { throw new RuntimeException("sessionFactory was null"); }
return ctx.proceed();
}
}
| 4,738 | 38.165289 | 100 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MyBaseInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import java.util.ArrayList;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceUnit;
import javax.sql.DataSource;
import jakarta.transaction.TransactionManager;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
* @author <a href="[email protected]">Kabir Khan</a>
*/
public class MyBaseInterceptor {
@EJB
MySession2 baseSession2;
@Resource(mappedName = "java:/TransactionManager")
TransactionManager baseTm;
@Resource(name = "DefaultDS", mappedName = "java:jboss/datasources/ExampleDS")
DataSource baseDs;
@PersistenceContext(unitName = "interceptors-test")
EntityManager baseEm;
@PersistenceContext(unitName = "interceptors-test")
Session baseSession;
@PersistenceUnit(unitName = "interceptors-test")
EntityManagerFactory baseFactory;
@PersistenceUnit(unitName = "interceptors-test")
SessionFactory baseSessionFactory;
MySession2 baseSession2Method;
TransactionManager baseTmMethod;
DataSource baseDsMethod;
EntityManager baseEmMethod;
Session baseSessionMethod;
EntityManagerFactory baseFactoryMethod;
SessionFactory baseSessionFactoryMethod;
@EJB
public void setBaseSession2Method(MySession2 session2Method) {
this.baseSession2Method = session2Method;
}
@Resource(mappedName = "java:/TransactionManager")
public void setBaseTmMethod(TransactionManager tmMethod) {
this.baseTmMethod = tmMethod;
}
@Resource(name = "DefaultDS", mappedName = "java:DefaultDS")
public void setBaseDsMethod(DataSource dsMethod) {
this.baseDsMethod = dsMethod;
}
@PersistenceContext(unitName = "interceptors-test")
public void setBaseEmMethod(EntityManager emMethod) {
this.baseEmMethod = emMethod;
}
@PersistenceContext(unitName = "interceptors-test")
public void setBaseSessionMethod(Session sessionMethod) {
this.baseSessionMethod = sessionMethod;
}
@PersistenceUnit(unitName = "interceptors-test")
public void setBaseFactoryMethod(EntityManagerFactory factoryMethod) {
this.baseFactoryMethod = factoryMethod;
}
@PersistenceUnit(unitName = "interceptors-test")
public void setBaseSessionFactoryMethod(SessionFactory sessionFactoryMethod) {
this.baseSessionFactoryMethod = sessionFactoryMethod;
}
@AroundInvoke
public Object baseInvoke(InvocationContext ctx) throws Exception {
baseSession2.doit();
if (baseTm == null) { throw new RuntimeException("tm was null"); }
if (baseDs == null) { throw new RuntimeException("ds was null"); }
if (baseEm == null) { throw new RuntimeException("em was null"); }
if (baseSession == null) { throw new RuntimeException("session was null"); }
if (baseFactory == null) { throw new RuntimeException("factory was null"); }
if (baseSessionFactory == null) { throw new RuntimeException("sessionFactory was null"); }
baseSession2Method.doit();
if (baseTmMethod == null) { throw new RuntimeException("tm was null"); }
if (baseDsMethod == null) { throw new RuntimeException("ds was null"); }
if (baseEmMethod == null) { throw new RuntimeException("em was null"); }
if (baseSessionMethod == null) { throw new RuntimeException("session was null"); }
if (baseFactoryMethod == null) { throw new RuntimeException("factory was null"); }
if (baseSessionFactoryMethod == null) { throw new RuntimeException("sessionFactory was null"); }
ArrayList list = (ArrayList) ctx.proceed();
list.add(0, "MyBaseInterceptor");
return list;
}
}
| 5,001 | 39.016 | 104 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MySessionBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import java.util.ArrayList;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
@Stateless
@Interceptors(MyInterceptor.class)
public class MySessionBean implements MySessionRemote {
public ArrayList doit() {
throw new RuntimeException("SHOULD NEVER BE CALLED");
}
}
| 1,456 | 35.425 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MySessionRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import java.util.ArrayList;
import jakarta.ejb.Remote;
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
@Remote
public interface MySessionRemote {
ArrayList doit();
}
| 1,277 | 34.5 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MySession2Bean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
@Stateless
public class MySession2Bean implements MySession2, MySession2Local {
public boolean doit() {
return true;
}
}
| 1,321 | 35.722222 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/MySession2Local.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.ejb.Local;
/**
* @author <a href="[email protected]">Kabir Khan</a>
*/
@Local
public interface MySession2Local {
boolean doit();
}
| 1,244 | 34.571429 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/SimpleStatelessBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
/**
* SimpleStatelessBean
*
* @author Jaikiran Pai
*/
@Stateless
@Interceptors(SimpleInterceptor.class)
@Remote(InjectionTester.class)
public class SimpleStatelessBean implements InjectionTester {
@PersistenceContext(unitName = "interceptors-test")
private EntityManager em;
@Resource
private SessionContext sessionContext;
public void assertAllInjectionsDone() throws IllegalStateException {
if (em == null) {
throw new IllegalStateException("EntityManager was *not* injected in bean " + this.getClass().getName());
}
if (this.sessionContext == null) {
throw new IllegalStateException("SessionContext was *not* injected in interceptor "
+ this.getClass().getName());
}
}
}
| 2,128 | 34.483333 | 117 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/InjectionTester.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
/**
* InjectionTester
*
* @author Jaikiran Pai
*/
public interface InjectionTester {
/**
* Checks that all the expected fields/methods have been injected
*
* @throws IllegalStateException If any of the expected field/method was not injected
*/
void assertAllInjectionsDone() throws IllegalStateException;
}
| 1,426 | 36.552632 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/SimpleInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import jakarta.annotation.Resource;
import jakarta.ejb.EJBContext;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import jakarta.persistence.EntityManager;
import javax.sql.DataSource;
/**
* SimpleInterceptor
*
* @author Jaikiran Pai
*/
public class SimpleInterceptor {
@Resource(lookup = "java:jboss/datasources/ExampleDS")
private DataSource ds;
// an injection-target is configured for this field through ejb-jar.xml
private EJBContext ejbContextInjectedThroughEjbJarXml;
// an injection-target is configured for this field through ejb-jar.xml
private EntityManager persistenceCtxRefConfiguredInEJBJarXml;
@AroundInvoke
public Object aroundInvoke(InvocationContext invocationCtx) throws Exception {
if (ds == null) {
throw new IllegalStateException("Datasource was *not* injected in interceptor " + this.getClass().getName());
}
if (ejbContextInjectedThroughEjbJarXml == null) {
throw new IllegalStateException("EJBContext was *not* injected in interceptor " + this.getClass().getName());
}
if (persistenceCtxRefConfiguredInEJBJarXml == null) {
throw new IllegalStateException("EntityManager was *not* injected in interceptor " + this.getClass().getName());
}
return invocationCtx.proceed();
}
}
| 2,465 | 37.53125 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inject/InterceptorInjectionUnitTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.interceptor.inject;
import java.util.ArrayList;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Migration test from EJB Testsuite (interceptors, 2061) to AS7 [JIRA JBQA-5483].
* <p>
* Interceptor injection test.
* Bill Burke, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class InterceptorInjectionUnitTestCase {
@ArquillianResource
InitialContext ctx;
@Deployment
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "interceptor-inject-test.jar")
.addPackage(InterceptorInjectionUnitTestCase.class.getPackage())
.addAsManifestResource(InterceptorInjectionUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml")
.addAsManifestResource(InterceptorInjectionUnitTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
return jar;
}
static boolean deployed = false;
static int test = 0;
@Test
public void testInterceptAndInjection() throws Exception {
MySessionRemote test = (MySessionRemote) ctx.lookup("java:module/" + MySessionBean.class.getSimpleName());
ArrayList list = test.doit();
Assert.assertEquals("MyBaseInterceptor", list.get(0));
Assert.assertEquals("MyInterceptor", list.get(1));
}
/**
* Tests that the {@link SimpleStatelessBean} and its interceptor class {@link SimpleInterceptor}
* have all the expected fields/methods injected
*
* @throws Exception
*/
@Test
public void testInjection() throws Exception {
InjectionTester bean = (InjectionTester) ctx.lookup("java:module/" + SimpleStatelessBean.class.getSimpleName());
bean.assertAllInjectionsDone();
}
}
| 3,190 | 37.445783 | 130 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanSynchronizeSingleton.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.Singleton;
/**
* @author Ondrej Chaloupka
*/
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class AsyncBeanSynchronizeSingleton implements AsyncBeanSynchronizeSingletonRemote {
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static volatile CountDownLatch latch2 = new CountDownLatch(1);
public void reset() {
latch = new CountDownLatch(1);
latch2 = new CountDownLatch(1);
}
public void latchCountDown() {
latch.countDown();
}
public void latch2CountDown() {
latch2.countDown();
}
public void latchAwaitSeconds(int sec) throws InterruptedException {
if (!latch.await(sec, TimeUnit.SECONDS)) {
throw new RuntimeException("Await failed");
}
}
public void latch2AwaitSeconds(int sec) throws InterruptedException {
latch2.await(sec, TimeUnit.SECONDS);
}
}
| 2,195 | 33.857143 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncParentClass.java
|
package org.jboss.as.test.integration.ejb.async;
import jakarta.ejb.Asynchronous;
/**
* @author Ondrej Chaloupka
*/
@Asynchronous
public class AsyncParentClass {
public static volatile boolean voidMethodCalled = false;
}
| 229 | 18.166667 | 60 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncSingleton.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Singleton;
/**
* Singleton
*/
@Singleton
@Asynchronous
public class AsyncSingleton {
public static volatile boolean voidMethodCalled = false;
public static volatile boolean futureMethodCalled = false;
public void asyncMethod(CountDownLatch latch, CountDownLatch latch2) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
voidMethodCalled = true;
latch2.countDown();
}
public Future<Boolean> futureMethod(CountDownLatch latch) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
futureMethodCalled = true;
return new AsyncResult<Boolean>(true);
}
}
| 1,928 | 34.072727 | 102 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanSynchronizeSingletonRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import jakarta.ejb.Remote;
/**
* @author Ondrej Chaloupka
*/
@Remote
public interface AsyncBeanSynchronizeSingletonRemote {
void reset();
void latchCountDown();
void latch2CountDown();
void latchAwaitSeconds(int sec) throws InterruptedException;
void latch2AwaitSeconds(int sec) throws InterruptedException;
}
| 1,407 | 36.052632 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanRemote.java
|
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
/**
* Bean with asynchronous methods.
*
* @author Ondrej Chaloupka
*/
@Stateless
@Asynchronous
public class AsyncBeanRemote implements AsyncBeanRemoteInterface {
@EJB
AsyncBean asyncBean;
@Override
public void asyncMethod() throws InterruptedException {
AsyncBean.voidMethodCalled = false;
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
asyncBean.asyncMethod(latch, latch2);
latch.countDown();
latch2.await();
if(!AsyncBean.voidMethodCalled) {
throw new IllegalArgumentException("voidMethodCalled");
}
}
@Override
public Future<Boolean> futureMethod() throws InterruptedException, ExecutionException {
AsyncBean.futureMethodCalled = false;
final CountDownLatch latch = new CountDownLatch(1);
final Future<Boolean> future = asyncBean.futureMethod(latch);
latch.countDown();
return new AsyncResult<Boolean>(future.get());
}
}
| 1,334 | 29.340909 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncStateful.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateful;
/**
* Stateful bean
*/
@Stateful
@Asynchronous
public class AsyncStateful {
public static volatile boolean voidMethodCalled = false;
public static volatile boolean futureMethodCalled = false;
public void asyncMethod(CountDownLatch latch, CountDownLatch latch2) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
voidMethodCalled = true;
latch2.countDown();
}
public Future<Boolean> futureMethod(CountDownLatch latch) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
futureMethodCalled = true;
return new AsyncResult<Boolean>(true);
}
}
| 1,929 | 34.090909 | 102 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncChildBean.java
|
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Stateless;
@Stateless
public class AsyncChildBean extends AsyncParentClass {
public void asyncMethod(CountDownLatch latch, CountDownLatch latch2) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
voidMethodCalled = true;
latch2.countDown();
}
}
| 444 | 26.8125 | 102 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.EJB;
import jakarta.ejb.LocalBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
/**
* Stateless session bean invoked asynchronously.
*/
@Stateless
@Asynchronous
@LocalBean
public class AsyncBean implements AsyncBeanCancelRemoteInterface {
public static volatile boolean voidMethodCalled = false;
public static volatile boolean futureMethodCalled = false;
@Inject
private RequestScopedBean requestScopedBean;
@Resource
SessionContext ctx;
@EJB
AsyncBeanSynchronizeSingletonRemote synchronizeBean;
public void asyncMethod(CountDownLatch latch, CountDownLatch latch2) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
voidMethodCalled = true;
latch2.countDown();
}
public Future<Boolean> futureMethod(CountDownLatch latch) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
futureMethodCalled = true;
return new AsyncResult<Boolean>(true);
}
public Future<Integer> testRequestScopeActive(CountDownLatch latch) throws InterruptedException {
latch.await(5, TimeUnit.SECONDS);
requestScopedBean.setState(20);
return new AsyncResult<Integer>(requestScopedBean.getState());
}
public Future<String> asyncCancelMethod(CountDownLatch latch, CountDownLatch latch2) throws InterruptedException {
String result;
result = ctx.wasCancelCalled() ? "true" : "false";
latch.countDown();
latch2.await(5, TimeUnit.SECONDS);
result += ";";
result += ctx.wasCancelCalled() ? "true" : "false";
return new AsyncResult<String>(result);
}
public Future<String> asyncRemoteCancelMethod() throws InterruptedException {
String result;
result = ctx.wasCancelCalled() ? "true" : "false";
synchronizeBean.latchCountDown();
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
if (ctx.wasCancelCalled()) {
break;
}
Thread.sleep(50);
}
result += ";";
result += ctx.wasCancelCalled() ? "true" : "false";
return new AsyncResult<String>(result);
}
public Future<String> asyncMethodWithException(boolean isException) {
if (isException) {
throw new IllegalArgumentException(); //some exception is thrown
}
return new AsyncResult<String>("Hi");
}
}
| 3,818 | 33.098214 | 118 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncMethodTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that a simple async annotation works.
* Enhanced test by migration [ JIRA JBQA-5483 ].
*
* @author Stuart Douglas, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class AsyncMethodTestCase {
private static final String ARCHIVE_NAME = "AsyncTestCase";
private static final Integer WAIT_TIME_S = 10;
@ArquillianResource
private InitialContext iniCtx;
@ContainerResource
private InitialContext remoteContext;
@Deployment(name = "asynctest")
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addPackage(AsyncMethodTestCase.class.getPackage());
jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
jar.addAsManifestResource(AsyncMethodTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
protected <T> T lookup(Class<T> beanType) throws NamingException {
return beanType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanType.getSimpleName() + "!"
+ beanType.getName()));
}
/**
* Stateless - void returned
*/
@Test
public void testVoidAsyncStatelessMethod() throws Exception {
AsyncBean.voidMethodCalled = false;
AsyncBean bean = lookup(AsyncBean.class);
Assert.assertFalse(AsyncBean.voidMethodCalled);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
bean.asyncMethod(latch, latch2);
latch.countDown();
latch2.await();
Assert.assertTrue(AsyncBean.voidMethodCalled);
}
/**
* Stateless - future returned
*/
@Test
public void testFutureAsyncStatelessMethod() throws Exception {
AsyncBean.futureMethodCalled = false;
AsyncBean bean = lookup(AsyncBean.class);
final CountDownLatch latch = new CountDownLatch(1);
final Future<Boolean> future = bean.futureMethod(latch);
latch.countDown();
boolean result = future.get();
Assert.assertTrue(AsyncBean.futureMethodCalled);
Assert.assertTrue(result);
}
/**
* Stateless request scope
*/
@Test
public void testRequestScopeActive() throws Exception {
AsyncBean bean = lookup(AsyncBean.class);
final CountDownLatch latch = new CountDownLatch(1);
final Future<Integer> future = bean.testRequestScopeActive(latch);
latch.countDown();
int result = future.get();
Assert.assertEquals(20, result);
}
/**
* Stateful - void returned
*/
@Test
public void testVoidAsyncStatefulMethod() throws Exception {
AsyncStateful bean = lookup(AsyncStateful.class);
Assert.assertFalse(AsyncStateful.voidMethodCalled);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
bean.asyncMethod(latch, latch2);
latch.countDown();
latch2.await();
Assert.assertTrue(AsyncStateful.voidMethodCalled);
}
/**
* Stateful - future returned
*/
@Test
public void testFutureAsyncStatefulMethod() throws Exception {
AsyncStateful bean = lookup(AsyncStateful.class);
final CountDownLatch latch = new CountDownLatch(1);
final Future<Boolean> future = bean.futureMethod(latch);
latch.countDown();
boolean result = future.get();
Assert.assertTrue(AsyncStateful.futureMethodCalled);
Assert.assertTrue(result);
}
/**
* Singleton - void returned
*/
@Test
public void testVoidAsyncSingletonMethod() throws Exception {
AsyncSingleton singleton = lookup(AsyncSingleton.class);
Assert.assertFalse(AsyncSingleton.voidMethodCalled);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
singleton.asyncMethod(latch, latch2);
latch.countDown();
latch2.await();
Assert.assertTrue(AsyncSingleton.voidMethodCalled);
}
/**
* Singleton - future returned
*/
@Test
public void testFutureAsyncSingletonMethod() throws Exception {
AsyncSingleton singleton = lookup(AsyncSingleton.class);
final CountDownLatch latch = new CountDownLatch(1);
final Future<Boolean> future = singleton.futureMethod(latch);
latch.countDown();
boolean result = future.get();
Assert.assertTrue(AsyncSingleton.futureMethodCalled);
Assert.assertTrue(result);
}
/**
* Cancelling
*/
@Test
public void testCancelAsyncMethod() throws Exception {
AsyncBean bean = lookup(AsyncBean.class);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final Future<String> future = bean.asyncCancelMethod(latch, latch2);
latch.await(WAIT_TIME_S, TimeUnit.SECONDS);
Assert.assertFalse(future.isDone()); // we are in async method
Assert.assertFalse(future.isCancelled());
boolean wasCanceled = future.cancel(true); // we are running - task can't be canceled
if (wasCanceled) {
Assert.assertTrue("isDone() was expected to return true after a call to cancel() with mayBeInterrupting = true, returned true", future.isDone());
Assert.assertTrue("isCancelled() was expected to return true after a call to cancel() returned true", future.isCancelled());
}
latch2.countDown();
String result = future.get();
Assert.assertFalse(wasCanceled); // this should be false because task was not cancelled
Assert.assertEquals("false;true", result); // the bean knows that it was cancelled
}
@Test
@RunAsClient
public void testCancelRemoteAsyncMethod() throws Exception {
AsyncBeanCancelRemoteInterface bean = (AsyncBeanCancelRemoteInterface) remoteContext.lookup(ARCHIVE_NAME + "/" +
AsyncBean.class.getSimpleName() + "!" + AsyncBeanCancelRemoteInterface.class.getName());
AsyncBeanSynchronizeSingletonRemote singleton = (AsyncBeanSynchronizeSingletonRemote) remoteContext.lookup(ARCHIVE_NAME + "/" +
AsyncBeanSynchronizeSingleton.class.getSimpleName() + "!" + AsyncBeanSynchronizeSingletonRemote.class.getName());
singleton.reset();
final Future<String> future = bean.asyncRemoteCancelMethod();
singleton.latchAwaitSeconds(WAIT_TIME_S); // waiting for the bean method was already invocated
Assert.assertFalse("isDone() was expected to return false because the method is still active", future.isDone()); // we are in async method
Assert.assertFalse("isCancelled() was expected to return false because the method is still active", future.isCancelled());
boolean wasCanceled = future.cancel(true); // we are running - task can't be canceled
if (wasCanceled) {
Assert.assertTrue("isDone() was expected to return true after a call to cancel() with mayBeInterrupting = true, returned true", future.isDone());
Assert.assertTrue("isCancelled() was expected to return true after a call to cancel() returned true", future.isCancelled());
}
String result = future.get();
Assert.assertFalse(wasCanceled); // this should be false because task was not cancelled
Assert.assertEquals("false;true", result); // the bean knows that it was cancelled
}
/**
* Exception thrown
*/
@Test
public void testExceptionThrown() throws NamingException {
AsyncBean bean = lookup(AsyncBean.class);
Future<String> future = bean.asyncMethodWithException(true);
try {
future.get();
Assert.fail("ExecutionException was expected");
} catch (ExecutionException ee) {
// expecting this and we are able to get caused exception
Assert.assertNotNull(ee.getCause());
} catch (Exception e) {
Assert.fail("ExecutionException was expected and not " + e.getClass());
}
}
/**
* Asynchronous inherited from parent
*/
@Test
public void testVoidParentAsyncMethod() throws Exception {
AsyncChildBean bean = lookup(AsyncChildBean.class);
Assert.assertFalse(AsyncParentClass.voidMethodCalled);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
bean.asyncMethod(latch, latch2);
latch.countDown();
latch2.await();
Assert.assertTrue(AsyncParentClass.voidMethodCalled);
}
/**
* Async declaration in descriptor
*/
@Test
public void testAsyncDescriptor() throws Exception {
AsyncBeanDescriptor bean = lookup(AsyncBeanDescriptor.class);
Assert.assertFalse(AsyncBeanDescriptor.futureMethodCalled);
final CountDownLatch latch = new CountDownLatch(1);
bean.futureMethod(latch);
latch.await(WAIT_TIME_S, TimeUnit.SECONDS);
Assert.assertTrue(AsyncBeanDescriptor.futureMethodCalled);
}
/**
* Remote async void call
*/
@Test
@RunAsClient
public void testRemoteAsynchronousVoidCall() throws Exception {
AsyncBeanRemoteInterface bean = (AsyncBeanRemoteInterface) remoteContext.lookup(
ARCHIVE_NAME + "/" + AsyncBeanRemote.class.getSimpleName() + "!" + AsyncBeanRemoteInterface.class.getName());
bean.asyncMethod();
}
/**
* Remote async return future call
*/
@Test
@RunAsClient
public void testRemoteAsynchronousReturnFutureCall() throws Exception {
AsyncBeanRemoteInterface bean = (AsyncBeanRemoteInterface) remoteContext.lookup(
ARCHIVE_NAME + "/" + AsyncBeanRemote.class.getSimpleName() + "!" + AsyncBeanRemoteInterface.class.getName());
Future<Boolean> future = bean.futureMethod();
Assert.assertTrue("Supposing that future.get() method returns TRUE but it returned FALSE", future.get());
}
}
| 11,991 | 39.789116 | 157 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanCancelRemoteInterface.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.Future;
import jakarta.ejb.Remote;
/**
* Remote interface for testing cancel method asynchronously.
*/
@Remote
public interface AsyncBeanCancelRemoteInterface {
Future<String> asyncRemoteCancelMethod() throws InterruptedException;
}
| 1,342 | 37.371429 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/RequestScopedBean.java
|
package org.jboss.as.test.integration.ejb.async;
import jakarta.enterprise.context.RequestScoped;
/**
* @author Stuart Douglas
*/
@RequestScoped
public class RequestScopedBean {
private int state = 0;
public int getState() {
return state;
}
public void setState(final int state) {
this.state = state;
}
}
| 347 | 16.4 | 48 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanRemoteInterface.java
|
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import jakarta.ejb.Remote;
/**
* @author Ondrej Chaloupka
*/
@Remote
public interface AsyncBeanRemoteInterface {
void asyncMethod() throws InterruptedException;
Future<Boolean> futureMethod() throws InterruptedException, ExecutionException;
}
| 388 | 24.933333 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/AsyncBeanDescriptor.java
|
package org.jboss.as.test.integration.ejb.async;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import jakarta.ejb.AsyncResult;
public class AsyncBeanDescriptor {
public static volatile boolean futureMethodCalled = false;
public Future<Boolean> futureMethod(CountDownLatch latch) throws InterruptedException {
futureMethodCalled = true;
latch.countDown();
return new AsyncResult<Boolean>(true);
}
}
| 471 | 28.5 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/zerotimeout/ZeroTimeoutAsyncBeanRemoteInterface.java
|
package org.jboss.as.test.integration.ejb.async.zerotimeout;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Remote;
import java.util.concurrent.Future;
/**
* @author Daniel Cihak
*/
@Remote
@Asynchronous
public interface ZeroTimeoutAsyncBeanRemoteInterface {
Future<Boolean> futureMethod() throws InterruptedException;
}
| 335 | 20 | 63 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/zerotimeout/ZeroTimeoutAsyncBeanRemote.java
|
package org.jboss.as.test.integration.ejb.async.zerotimeout;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateless;
import java.util.concurrent.Future;
/**
* Bean with asynchronous methods.
*
* @author Daniel Cihak
*/
@Stateless
public class ZeroTimeoutAsyncBeanRemote implements ZeroTimeoutAsyncBeanRemoteInterface {
@Override
@Asynchronous
public Future<Boolean> futureMethod() throws InterruptedException {
Thread.sleep(5000);
return new AsyncResult<Boolean>(Boolean.TRUE);
}
}
| 560 | 23.391304 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/async/zerotimeout/ZeroTimeoutAsyncMethodTestCase.java
|
package org.jboss.as.test.integration.ejb.async.zerotimeout;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Tests calling Future on asynchronous method with zero time-out.
* Test for [ JBEAP-6826 ].
*
* @author Daniel Cihak
*/
@RunWith(Arquillian.class)
public class ZeroTimeoutAsyncMethodTestCase {
private static final String ARCHIVE_NAME = "ZeroTimeoutTestCase";
@ContainerResource
private InitialContext remoteContext;
@Deployment(name = "zerotimeouttestcase")
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addClasses(ZeroTimeoutAsyncMethodTestCase.class, ZeroTimeoutAsyncBeanRemote.class, ZeroTimeoutAsyncBeanRemoteInterface.class);
return jar;
}
private <T> T lookup(Class<? extends T> beanType, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(remoteContext.lookup(ARCHIVE_NAME + "/" + beanType.getSimpleName() + "!"
+ interfaceType.getName()));
}
/**
* Test call asynchronous method on remote bean with zero time-out, which means we demand the result immediately,
* but the asynchronous method invocation takes 5000 ms. Therefore the result is not available and TimeoutException is thrown.
*
* @throws Exception
*/
@Test
@RunAsClient
public void testCallAsyncFutureZeroTimeout() throws Exception {
ZeroTimeoutAsyncBeanRemoteInterface asyncBean = this.lookup(ZeroTimeoutAsyncBeanRemote.class, ZeroTimeoutAsyncBeanRemoteInterface.class);
try {
asyncBean.futureMethod().get(0, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Assert.assertTrue(e instanceof TimeoutException);
}
Assert.assertTrue(asyncBean.futureMethod().get(10000, TimeUnit.MILLISECONDS));
}
}
| 2,419 | 36.230769 | 145 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/SimpleEJBClientInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import java.util.Map;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBClientInvocationContext;
/**
* An EJB client side interceptor. The entries in a {@link Map} provided to the constructor are copied to the
* {@link EJBClientInvocationContext#getContextData()} in the {@link #handleInvocation(EJBClientInvocationContext)} before
* {@link EJBClientInvocationContext#sendRequest()} is called
*
* @author Jaikiran Pai
*/
public class SimpleEJBClientInterceptor implements EJBClientInterceptor {
private final Map<String, Object> data;
SimpleEJBClientInterceptor(final Map<String, Object> data) {
this.data = data;
}
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
// add all the data to the EJB client invocation context so that it becomes available to the server side
context.getContextData().putAll(data);
// proceed "down" the invocation chain
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
// we don't have anything special to do with the result so just return back the result
// "up" the invocation chain
return context.getResult();
}
}
| 2,401 | 39.033333 | 122 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/FailingContainerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.jboss.logging.Logger;
/**
* Simple interceptor, which throws an {@link IllegalArgumentException}.
*
* @author Josef Cacek
*/
public class FailingContainerInterceptor {
private static Logger LOGGER = Logger.getLogger(FailingContainerInterceptor.class);
// Private methods -------------------------------------------------------
@AroundInvoke
Object throwException(final InvocationContext invocationContext) throws Exception {
LOGGER.trace("Throwing exception");
throw new IllegalArgumentException("Blocking access to the bean.");
}
}
| 1,765 | 37.391304 | 87 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/MethodSpecificContainerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
/**
* Simple interceptor, which adds its classname in front of the result of {@link InvocationContext#proceed()}.
*
* @author Jaikiran Pai
*/
public class MethodSpecificContainerInterceptor {
@SuppressWarnings("unused")
@AroundInvoke
private Object iAmAroundInvoke(final InvocationContext invocationContext) throws Exception {
return this.getClass().getName() + " " + invocationContext.proceed();
}
}
| 1,608 | 38.243902 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/ContainerInterceptorOne.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.jboss.logging.Logger;
/**
* Simple interceptor, which adds its classname in front of the result of {@link InvocationContext#proceed()}. Result of the
* proceed() stays untouched in case the {@link InvocationContext#getContextData()} contains classname of this interceptor under
* the {@link FlowTrackingBean#CONTEXT_DATA_KEY} key.
*
* @author Jaikiran Pai
*/
public class ContainerInterceptorOne {
private static final Logger logger = Logger.getLogger(ContainerInterceptorOne.class);
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
logger.trace("Container interceptor invoked!!!");
final String skipInterceptor = (String) invocationContext.getContextData().get(FlowTrackingBean.CONTEXT_DATA_KEY);
if (skipInterceptor != null && this.getClass().getName().equals(skipInterceptor)) {
return invocationContext.proceed();
}
return this.getClass().getName() + " " + invocationContext.proceed();
}
}
| 2,214 | 42.431373 | 128 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/AnotherFlowTrackingBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
public class AnotherFlowTrackingBean extends FlowTrackingBean {
public String echoWithMethodSpecificContainerInterceptor(final String msg) {
return msg;
}
public String echoInSpecificOrderOfContainerInterceptors(final String msg) {
return msg;
}
public String failingEcho(final String msg) {
return msg;
}
}
| 1,564 | 32.297872 | 80 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/NonContainerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.jboss.logging.Logger;
/**
* Simple interceptor, which adds its classname in front of the result of {@link InvocationContext#proceed()}. Result of the
* proceed() stays untouched in case the {@link InvocationContext#getContextData()} contains classname of this interceptor under
* the {@link FlowTrackingBean#CONTEXT_DATA_KEY} key.
*
* @author Jaikiran Pai
*/
public class NonContainerInterceptor {
private static final Logger logger = Logger.getLogger(NonContainerInterceptor.class);
@AroundInvoke
public Object someMethod(InvocationContext invocationContext) throws Exception {
logger.trace("Invoked non-container interceptor!!!");
final String skipInterceptor = (String) invocationContext.getContextData().get(FlowTrackingBean.CONTEXT_DATA_KEY);
if (skipInterceptor != null && this.getClass().getName().equals(skipInterceptor)) {
return invocationContext.proceed();
}
return this.getClass().getName() + " " + invocationContext.proceed();
}
}
| 2,210 | 42.352941 | 128 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/FlowTracker.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
/**
* @author Jaikiran Pai
*/
public interface FlowTracker {
String echo(String message);
}
| 1,189 | 36.1875 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/FlowTrackingBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptors;
import jakarta.interceptor.InvocationContext;
import org.jboss.logging.Logger;
/**
* A {@link FlowTracker} implementation. There are 2 Jakarta Interceptors used - {@link NonContainerInterceptor} and the class itself
* ({@link #aroundInvoke(InvocationContext)}).
*
* @author Jaikiran Pai
*/
@Stateless
@Interceptors(NonContainerInterceptor.class)
@Remote(FlowTracker.class)
@LocalBean
public class FlowTrackingBean implements FlowTracker {
private static final Logger logger = Logger.getLogger(FlowTrackingBean.class);
public static final String CONTEXT_DATA_KEY = "foo-bar";
@AroundInvoke
protected Object aroundInvoke(InvocationContext invocationContext) throws Exception {
logger.trace("@AroundInvoke on bean invoked");
final String skipInterceptor = (String) invocationContext.getContextData().get(FlowTrackingBean.CONTEXT_DATA_KEY);
if (skipInterceptor != null && this.getClass().getName().equals(skipInterceptor)) {
return invocationContext.proceed();
}
return this.getClass().getName() + " " + invocationContext.proceed();
}
public String echo(final String msg) {
logger.trace("EJB invoked!!!");
return msg;
}
}
| 2,485 | 36.666667 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/ClassLevelContainerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
/**
* Simple interceptor, which only adds its classname in front of the result of {@link InvocationContext#proceed()}
*
* @author Jaikiran Pai
*/
public class ClassLevelContainerInterceptor {
@SuppressWarnings("unused")
@AroundInvoke
private Object iAmAround(final InvocationContext invocationContext) throws Exception {
return this.getClass().getName() + " " + invocationContext.proceed();
}
}
| 1,601 | 39.05 | 114 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/ContainerInterceptorsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor;
import static org.junit.Assert.fail;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import static org.hamcrest.CoreMatchers.containsString;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.ejb.container.interceptor.incorrect.IncorrectContainerInterceptor;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that the <code>container-interceptors</code> configured in jboss-ejb3.xml and processed and applied correctly to the
* relevant EJBs.
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class ContainerInterceptorsTestCase {
private static final String EJB_JAR_NAME = "ejb-container-interceptors";
@ArquillianResource
Deployer deployer;
@Deployment
public static JavaArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EJB_JAR_NAME + ".jar");
jar.addPackage(ContainerInterceptorsTestCase.class.getPackage());
jar.addAsManifestResource(ContainerInterceptorsTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
/**
* Deployment which should fail. It contains an interceptor with 2 methods annotated with the @AroundInvoke.
*
* @return
*/
@Deployment(name = "incorrect-deployment", managed = false)
public static JavaArchive createIncorrectDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "incorrect-deployment.jar");
jar.addPackage(IncorrectContainerInterceptor.class.getPackage());
jar.addAsManifestResource(IncorrectContainerInterceptor.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
@Test
public void testMultipleAnnotatedInvokeAroundClass() throws Throwable {
try {
deployer.deploy("incorrect-deployment");
fail("Deployment should fail");
} catch (Exception ex) {
final StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
assertThat(sw.toString(), containsString("WFLYEE0109"));
}
}
/**
* Tests that the container-interceptor(s) are invoked when an EJB method on a local view is invoked
*
* @throws Exception
*/
@Test
public void testInvocationOnLocalView() throws Exception {
final FlowTrackingBean
bean = InitialContext.doLookup("java:module/" + FlowTrackingBean.class
.getSimpleName() + "!"
+ FlowTrackingBean.class
.getName());
final String message = "foo";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked.
final String expectedResultForFirstInvocation = ContainerInterceptorOne.class.getName() + " "
+ NonContainerInterceptor.class.getName() + " " + FlowTrackingBean.class.getName() + " " + message;
final String firstResult = bean.echo(message);
Assert.assertEquals (
"Unexpected result after first invocation on bean", expectedResultForFirstInvocation, firstResult);
final String secondMessage = "bar";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked.
final String expectedResultForSecondInvocation = ContainerInterceptorOne.class.getName() + " "
+ NonContainerInterceptor.class.getName() + " " + FlowTrackingBean.class.getName() + " " + secondMessage;
final String secondResult = bean.echo(secondMessage);
Assert.assertEquals (
"Unexpected result after second invocation on bean", expectedResultForSecondInvocation,
secondResult);
}
/**
* Tests that the container-interceptor(s) are invoked when an EJB method on a remote view is invoked
*
* @throws Exception
*/
@Test
public void testInvocationOnRemoteView() throws Exception {
final FlowTracker bean = InitialContext.doLookup("java:module/" + FlowTrackingBean.class.getSimpleName() + "!"
+ FlowTracker.class.getName());
final String message = "foo";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked.
final String expectedResultForFirstInvocation = ContainerInterceptorOne.class.getName() + " "
+ NonContainerInterceptor.class.getName() + " " + FlowTrackingBean.class.getName() + " " + message;
final String firstResult = bean.echo(message);
Assert.assertEquals("Unexpected result after first invocation on remote view of bean",
expectedResultForFirstInvocation, firstResult);
final String secondMessage = "bar";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked.
final String expectedResultForSecondInvocation = ContainerInterceptorOne.class.getName() + " "
+ NonContainerInterceptor.class.getName() + " " + FlowTrackingBean.class.getName() + " " + secondMessage;
final String secondResult = bean.echo(secondMessage);
Assert.assertEquals("Unexpected result after second invocation on remote view of bean",
expectedResultForSecondInvocation, secondResult);
}
/**
* Tests that the container-interceptor(s) have access to the data that's passed by a remote client via the
* {@link jakarta.interceptor.InvocationContext#getContextData()}
*/
@Test
// force real remote invocation so that the RemotingConnectionEJBReceiver is used instead of a LocalEJBReceiver
@RunAsClient
public void testDataPassingForContainerInterceptorsOnRemoteView() throws Exception {
// create some data that the client side interceptor will pass along during the EJB invocation
final Map<String, Object> interceptorData = new HashMap<String, Object>();
interceptorData.put(FlowTrackingBean.CONTEXT_DATA_KEY, ContainerInterceptorOne.class.getName());
final SimpleEJBClientInterceptor clientInterceptor = new SimpleEJBClientInterceptor(interceptorData);
// get hold of the EJBClientContext and register the client side interceptor
EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(clientInterceptor);
final Hashtable<String, Object> jndiProps = new Hashtable<String, Object>();
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiCtx = new InitialContext(jndiProps);
ejbClientContext.runCallable(() -> {
final FlowTracker bean = (FlowTracker) jndiCtx.lookup("ejb:/" + EJB_JAR_NAME + "/"
+ FlowTrackingBean.class.getSimpleName() + "!" + FlowTracker.class.getName());
final String message = "foo";
// we passed ContainerInterceptorOne as the value of the context data for the invocation, which means that we want the ContainerInterceptorOne
// to be skipped, so except that interceptor, the rest should be invoked.
final String expectedResultForFirstInvocation = NonContainerInterceptor.class.getName() + " "
+ FlowTrackingBean.class.getName() + " " + message;
final String firstResult = bean.echo(message);
Assert.assertEquals("Unexpected result invoking on bean when passing context data via EJB client interceptor",
expectedResultForFirstInvocation, firstResult);
// Now try another invocation, this time skip a different interceptor
interceptorData.clear();
interceptorData.put(FlowTrackingBean.CONTEXT_DATA_KEY, NonContainerInterceptor.class.getName());
final String secondMessage = "bar";
// we passed NonContainerInterceptor as the value of the context data for the invocation, which means that we want the NonContainerInterceptor
// to be skipped, so except that interceptor, the rest should be invoked.
final String expectedResultForSecondInvocation = ContainerInterceptorOne.class.getName() + " "
+ FlowTrackingBean.class.getName() + " " + secondMessage;
final String secondResult = bean.echo(secondMessage);
Assert.assertEquals("Unexpected result invoking on bean when passing context data via EJB client interceptor",
expectedResultForSecondInvocation, secondResult);
return null;
});
}
/**
* Tests that class level and method level container-interceptors (and other eligible interceptors) are invoked during an
* EJB invocation
*
* @throws Exception
*/
@Test
public void testClassAndMethodLevelContainerInterceptor() throws Exception {
final AnotherFlowTrackingBean bean = InitialContext.doLookup("java:module/"
+ AnotherFlowTrackingBean.class.getSimpleName() + "!" + AnotherFlowTrackingBean.class.getName());
final String message = "foo";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked.
final String expectedResultForFirstInvocation = ContainerInterceptorOne.class.getName() + " "
+ ClassLevelContainerInterceptor.class.getName() + " " + MethodSpecificContainerInterceptor.class.getName()
+ " " + NonContainerInterceptor.class.getName() + " " + AnotherFlowTrackingBean.class.getName() + " " + message;
// invoke on the specific method which has the container-interceptor eligible
final String firstResult = bean.echoWithMethodSpecificContainerInterceptor(message);
Assert.assertEquals("Unexpected result after invocation on bean", expectedResultForFirstInvocation, firstResult);
// now let's invoke on a method for which that method level container interceptor isn't applicable
final String expectedResultForSecondInvocation = ContainerInterceptorOne.class.getName() + " "
+ ClassLevelContainerInterceptor.class.getName() + " " + NonContainerInterceptor.class.getName() + " "
+ AnotherFlowTrackingBean.class.getName() + " " + message;
final String secondResult = bean.echo(message);
Assert.assertEquals("Unexpected result after invocation on bean", expectedResultForSecondInvocation, secondResult);
}
/**
* Tests that the explicit ordering specified for container-interceptors in the jboss-ejb3.xml is honoured
*
* @throws Exception
*/
@Test
public void testContainerInterceptorOrdering() throws Exception {
final AnotherFlowTrackingBean bean = InitialContext.doLookup("java:module/"
+ AnotherFlowTrackingBean.class.getSimpleName() + "!" + AnotherFlowTrackingBean.class.getName());
final String message = "foo";
// all interceptors (container-interceptor and Jakarta Interceptors) are expected to be invoked in the order specified in the jboss-ejb3.xml
final String expectedResultForFirstInvocation = ClassLevelContainerInterceptor.class.getName() + " "
+ MethodSpecificContainerInterceptor.class.getName() + " " + ContainerInterceptorOne.class.getName() + " "
+ NonContainerInterceptor.class.getName() + " " + AnotherFlowTrackingBean.class.getName() + " " + message;
// invoke on the specific method which has the interceptor-order specified
final String firstResult = bean.echoInSpecificOrderOfContainerInterceptors(message);
Assert.assertEquals("Unexpected result after invocation on bean", expectedResultForFirstInvocation, firstResult);
}
/**
* Tests that exception thrown in a container-interceptor is propagated.
*
* @throws Exception
*/
@Test
public void testFailingContainerInterceptor() throws Exception {
final AnotherFlowTrackingBean bean = InitialContext.doLookup("java:module/"
+ AnotherFlowTrackingBean.class.getSimpleName() + "!" + AnotherFlowTrackingBean.class.getName());
try {
bean.failingEcho("test");
fail("Should fail");
} catch (IllegalArgumentException e) {
//OK
}
}
}
| 13,896 | 49.718978 | 154 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/incorrect/IncorrectContainerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor.incorrect;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.jboss.logging.Logger;
/**
* Incorrect interceptor - contains 2 methods annotated with the {@link AroundInvoke}.
*
* @author Josef Cacek
*/
public class IncorrectContainerInterceptor {
private static Logger LOGGER = Logger.getLogger(IncorrectContainerInterceptor.class);
// Private methods -------------------------------------------------------
@AroundInvoke
Object method1(final InvocationContext invocationContext) throws Exception {
LOGGER.trace("method1 invoked");
return invocationContext.proceed();
}
@AroundInvoke
Object method2(final InvocationContext invocationContext) throws Exception {
LOGGER.trace("method2 invoked");
return invocationContext.proceed();
}
}
| 1,942 | 36.365385 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/incorrect/SimpleBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.container.interceptor.incorrect;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.logging.Logger;
/**
* A SimpleBean.
*
* @author Josef Cacek
*/
@Stateless
@LocalBean
public class SimpleBean {
private static Logger LOGGER = Logger.getLogger(SimpleBean.class);
// Public methods --------------------------------------------------------
/**
* Simply returns given String.
*
* @param message
* @return
* @see org.jboss.as.test.integration.ejb.container.interceptor.FlowTracker#echo(java.lang.String)
*/
public String echo(final String message) {
LOGGER.trace("echo() called");
return message;
}
}
| 1,763 | 31.666667 | 102 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/overlap/ScheduleRetryFailSingletonBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.overlap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.Schedule;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timer;
import org.jboss.logging.Logger;
/**
* SingletonBean to test that the schedule continue after a second timeout happen
* during the singleton is still retrying the timeout.<br/>
* See JIRA AS7-2995.
*
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
@Singleton
@AccessTimeout(unit = TimeUnit.MILLISECONDS, value = 100) // make the test faster
public class ScheduleRetryFailSingletonBean {
private static final Logger LOGGER = Logger.getLogger(ScheduleRetryFailSingletonBean.class);
private static final CountDownLatch started = new CountDownLatch(1);
private static final CountDownLatch alive = new CountDownLatch(4);
/**
* count the number of invoked timeouts
*/
private static int counter;
@SuppressWarnings("unused")
@Schedule(second = "*", minute = "*", hour = "*", persistent = false)
private void timeout(final Timer timer) {
int wait = 0;
counter++;
LOGGER.trace("Executing TimerTestBean " + timer);
switch(counter) {
case 1:
started.countDown();
throw new RuntimeException("Force retry for test");
case 2:
// ensure that the timeout retry is running if longer than schedule
wait = 1300;
break;
default:
break;
}
alive.countDown();
LOGGER.trace("count=" + counter + " Sleeping "+wait+"ms");
try {
Thread.sleep(wait);
} catch (InterruptedException e) {}
LOGGER.trace("Finished executing TimerTestBean nextTimeOut=" + timer.getNextTimeout());
}
/**
* Latch to test whether the first timeout is executed.
*
* @return latch which is blocked until the first schedule
*/
public static CountDownLatch startLatch() {
return started;
}
/**
* Latch to test whether a timeout is fired after overlapping with a timeout retry.
* The test should wait a minimum of 4 seconds.
*
* @return latch which is blocked until a timeout happen after retry
*/
public static CountDownLatch aliveLatch() {
return alive;
}
}
| 4,503 | 37.495726 | 96 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/overlap/OverlapTimerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.overlap;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
@RunWith(Arquillian.class)
public class OverlapTimerTestCase {
private static final int TIMER_CALL_WAITING1_S = 3;
private static final int TIMER_CALL_WAITING2_S = 5;
@Deployment
public static Archive<?> createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "overlap-timer-test.jar");
ejbJar.addPackage(OverlapTimerTestCase.class.getPackage());
return ejbJar;
}
@Test
public void testContinuedAfterOverlap() throws Exception {
Assert.assertTrue("Schedule timeout method was not invoked within 3 seconds!", ScheduleRetryFailSingletonBean.startLatch().await(TIMER_CALL_WAITING1_S, TimeUnit.SECONDS));
Assert.assertTrue("Schedule timer is not alive after overlapped invocation!",ScheduleRetryFailSingletonBean.aliveLatch().await(TIMER_CALL_WAITING2_S, TimeUnit.SECONDS));
}
}
| 2,405 | 40.482759 | 179 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/security/TimerServiceCallerPrincipleTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.security;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that {@link jakarta.ejb.EJBContext#getCallerPrincipal()} returns the unauthenticated identity in a timeout method.
*
* AS7-3154
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServiceCallerPrincipleTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceGetCallerPrinciple.war");
war.addPackage(TimerServiceCallerPrincipleTestCase.class.getPackage());
return war;
}
@Test
public void testGetCallerPrincipleInTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimerGetCallerPrincipleBean bean = (TimerGetCallerPrincipleBean) ctx.lookup("java:module/" + TimerGetCallerPrincipleBean.class.getSimpleName());
bean.createTimer();
Assert.assertEquals("anonymous", TimerGetCallerPrincipleBean.awaitTimerCall());
}
}
| 2,427 | 36.9375 | 152 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/security/TimerGetCallerPrincipleBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.security;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class TimerGetCallerPrincipleBean implements TimedObject {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_TIMEOUT_TIME_MS = 100;
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile String principle = null;
@Resource
private TimerService timerService;
@Resource
private EJBContext ejbContext;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
public static String awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return principle;
}
@Override
public void ejbTimeout(final Timer timer) {
principle = ejbContext.getCallerPrincipal().getName();
latch.countDown();
}
}
| 2,324 | 31.746479 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/security/runas/TimeoutMethodWithRunAsAnnotationTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.security.runas;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
/**
* @author Tomasz Adamski
*/
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.auth.permission.ChangeRoleMapperPermission;
import org.wildfly.security.permission.ElytronPermission;
@RunWith(Arquillian.class)
public class TimeoutMethodWithRunAsAnnotationTestCase {
private static final Logger log = Logger.getLogger(TimeoutMethodWithRunAsAnnotationTestCase.class.getName());
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "myJar.jar");
jar.addPackage(TimeoutMethodWithRunAsAnnotationTestCase.class.getPackage());
jar.addAsManifestResource(createPermissionsXmlAsset(
new ElytronPermission("setRunAsPrincipal"),
new ChangeRoleMapperPermission("ejb")
), "permissions.xml");
return jar;
}
@Test
public void testTimeoutMethodWithRunAsAnnotation() throws Exception {
final TimerBean timerBean = InitialContext.doLookup("java:module/TimerBean");
timerBean.startTimer();
Assert.assertTrue(TimerBean.awaitTimerCall());
Assert.assertTrue(SecureBean.getSecureMethodRun());
}
}
| 2,735 | 40.454545 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/security/runas/TimerBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.security.runas;
/**
* @author Tomasz Adamski
*/
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
@Stateless(name = "TimerBean")
@RunAs("bob")
@PermitAll
public class TimerBean {
private static final int TIMEOUT = 100;
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
@Resource
private SessionContext ctx;
@EJB
private SecureBean secureBean;
public void startTimer() {
timerService.createSingleActionTimer(TIMEOUT, new TimerConfig());
}
@Timeout
private void timeout() {
secureBean.secureMethod();
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,500 | 29.876543 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/security/runas/SecureBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.security.runas;
/**
* @author Tomasz Adamski
*/
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
@Stateless
public class SecureBean {
private static volatile boolean secureMethodRun = false;
@Resource
private SessionContext ctx;
@RolesAllowed("bob")
public void secureMethod() {
secureMethodRun=true;
}
public static boolean getSecureMethodRun(){
return secureMethodRun;
}
}
| 1,604 | 31.1 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/DatabasePersistentCalendarTimerManagementTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.AbstractTimerBean;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.AbstractTimerManagementTestCase;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.CalendarTimerBean;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.SimpleFace;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.Serializable;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(DatabaseTimerServerSetup.class)
public class DatabasePersistentCalendarTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, CalendarTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
ejbJar.addAsManifestResource(DatabasePersistentCalendarTimerManagementTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return CalendarTimerBean.class.getSimpleName();
}
private Serializable info = "PersistentCalendarTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return true;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertTrue("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 4,006 | 30.551181 | 143 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/OracleDatabaseTimerServerSetup.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.as.test.shared.SnapshotRestoreSetupTask;
import org.jboss.dmr.ModelNode;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
class OracleDatabaseTimerServerSetup extends SnapshotRestoreSetupTask {
@Override
public void doSetup(final ManagementClient managementClient, final String containerId) throws Exception {
ServerReload.BeforeSetupTask.INSTANCE.setup(managementClient, containerId);
ModelNode op = new ModelNode();
op.get(OP).set(ADD);
op.get(OP_ADDR).add(SUBSYSTEM, "ejb3");
op.get(OP_ADDR).add("service", "timer-service");
op.get(OP_ADDR).add("database-data-store", "dbstore");
op.get("datasource-jndi-name").set("java:jboss/datasources/ExampleDS");
op.get("database").set("oracle");
op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
}
}
| 2,717 | 47.535714 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/OracleDatabaseTimerServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.ejb.TimerConfig;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Date;
/**
* Tests @Timeout method called with the Oracle database persistent timer
* Test for [ WFLY-16290 ].
*
* @author Daniel Cihak
*/
@RunWith(Arquillian.class)
@ServerSetup(OracleDatabaseTimerServerSetup.class)
public class OracleDatabaseTimerServiceTestCase {
private static int TIMER_INIT_TIME_MS = 100;
private static int TIMER_TIMEOUT_TIME_MS = 100;
private static String INFO_MSG_FOR_CHECK = "info";
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testOracleTimer.war");
war.addPackage(OracleDatabaseTimerServiceTestCase.class.getPackage());
war.addAsWebInfResource(OracleDatabaseTimerServiceTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return war;
}
@Test
public void testTimedObjectTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimedObjectTimerServiceBean bean = (TimedObjectTimerServiceBean) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
bean.resetTimerServiceCalled();
bean.getTimerService().createTimer(TIMER_TIMEOUT_TIME_MS, INFO_MSG_FOR_CHECK);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
bean.resetTimerServiceCalled();
long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(INFO_MSG_FOR_CHECK);
bean.getTimerService().createSingleActionTimer(new Date(ts), timerConfig);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
Assert.assertEquals(INFO_MSG_FOR_CHECK, bean.getTimerInfo());
Assert.assertFalse(bean.isCalendar());
Assert.assertTrue(bean.isPersistent());
}
}
| 3,409 | 41.098765 | 152 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/DatabaseTimerServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import java.util.Date;
import jakarta.ejb.TimerConfig;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an @Timeout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@ServerSetup(DatabaseTimerServerSetup.class)
public class DatabaseTimerServiceTestCase {
private static int TIMER_INIT_TIME_MS = 100;
private static int TIMER_TIMEOUT_TIME_MS = 100;
private static String INFO_MSG_FOR_CHECK = "info";
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceSimple.war");
war.addPackage(DatabaseTimerServiceTestCase.class.getPackage());
war.addAsWebInfResource(DatabaseTimerServiceTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return war;
}
@Test
public void testTimedObjectTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimedObjectTimerServiceBean bean = (TimedObjectTimerServiceBean) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
bean.resetTimerServiceCalled();
bean.getTimerService().createTimer(TIMER_TIMEOUT_TIME_MS, INFO_MSG_FOR_CHECK);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
bean.resetTimerServiceCalled();
long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(INFO_MSG_FOR_CHECK);
bean.getTimerService().createSingleActionTimer(new Date(ts), timerConfig);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
Assert.assertEquals(INFO_MSG_FOR_CHECK, bean.getTimerInfo());
Assert.assertFalse(bean.isCalendar());
Assert.assertTrue(bean.isPersistent());
}
}
| 3,372 | 39.638554 | 152 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/DatabaseTimerServerSetup.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
/**
* @author Stuart Douglas
*/
class DatabaseTimerServerSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
ServerReload.BeforeSetupTask.INSTANCE.setup(managementClient, containerId);
ModelNode op = new ModelNode();
op.get(OP).set(ADD);
op.get(OP_ADDR).add(SUBSYSTEM, "ejb3");
op.get(OP_ADDR).add("service", "timer-service");
op.get(OP_ADDR).add("database-data-store", "dbstore");
op.get("datasource-jndi-name").set("java:jboss/datasources/ExampleDS");
op.get("database").set("hsql");
op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
ModelNode op = new ModelNode();
op.get(OP).set(REMOVE);
op.get(OP_ADDR).add(SUBSYSTEM, "ejb3");
op.get(OP_ADDR).add("service", "timer-service");
op.get(OP_ADDR).add("database-data-store", "dbstore");
op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
}
}
| 3,534 | 47.424658 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/DatabasePersistentIntervalTimerManagementTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.AbstractTimerBean;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.AbstractTimerManagementTestCase;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.IntervalTimerBean;
import org.jboss.as.test.integration.ejb.timerservice.mgmt.SimpleFace;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.Serializable;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(DatabaseTimerServerSetup.class)
public class DatabasePersistentIntervalTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, IntervalTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
ejbJar.addAsManifestResource(DatabasePersistentCalendarTimerManagementTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return IntervalTimerBean.class.getSimpleName();
}
private Serializable info = "PersistentIntervalTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return true;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertFalse("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 4,006 | 30.801587 | 143 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/database/TimedObjectTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.database;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class TimedObjectTimerServiceBean implements TimedObject {
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Resource
private SessionContext sessionContext;
private TimerService timerService;
private static String timerInfo;
private static boolean isPersistent;
private static boolean isCalendar;
public synchronized TimerService getTimerService() {
if (timerService == null) {
timerService = (TimerService) sessionContext.lookup("java:comp/TimerService");
}
return timerService;
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
public void resetTimerServiceCalled() {
timerServiceCalled = false;
latch = new CountDownLatch(1);
}
public String getTimerInfo() {
return timerInfo;
}
public boolean isPersistent() {
return isPersistent;
}
public boolean isCalendar() {
return isCalendar;
}
@Override
public void ejbTimeout(final Timer timer) {
timerInfo = new String((String) timer.getInfo());
isPersistent = timer.isPersistent();
isCalendar = timer.isCalendarTimer();
timerServiceCalled = true;
latch.countDown();
}
}
| 2,988 | 30.463158 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/TimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.CoreMatchers.containsString;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class TimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, TimerBean.class, AbstractTimerBean.class, SimpleFace.class);
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
this.bean.waitOnTimeout();
Assert.assertEquals("Timer ticks should register some ++!", 1, this.bean.getTimerTicks());
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
this.bean.createTimer();
this.suspendTimer();
final long ticksCount = this.bean.getTimerTicks();
this.waitOverTimer();
Assert.assertEquals("Timer ticks should not change after suspension!", ticksCount, this.bean.getTimerTicks());
this.activateTimer();
this.bean.waitOnTimeout();
Assert.assertEquals("Timer ticks should register some ++!", ticksCount + 1, this.bean.getTimerTicks());
try {
getTimerDetails();
} catch (OperationFailedException ofe) {
final ModelNode failureDescription = ofe.getFailureDescription();
MatcherAssert.assertThat("Wrong failure description", failureDescription.toString(), containsString("WFLYCTL0216"));
}
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
this.bean.createTimer();
this.cancelTimer();
try {
getTimerDetails();
} catch (OperationFailedException ofe) {
final ModelNode failureDescription = ofe.getFailureDescription();
MatcherAssert.assertThat("Wrong failure description", failureDescription.toString(), containsString("WFLYCTL0216"));
}
}
@Test
@InSequence(4)
public void testWildcard() throws Exception {
assertNoTimers();
this.bean.createTimer();
final PathAddress address = PathAddress.pathAddress(getTimerAddressBase(), PathElement.pathElement("timer", "*"));
final ModelNode operation = Util.createOperation("suspend", address);
ModelNode response = executeForResult(operation);
Assert.assertFalse(Operations.isSuccessfulOutcome(response));
MatcherAssert.assertThat("Wrong failure description", Operations.getFailureDescription(response).toString(), containsString("WFLYEJB0526"));
this.waitOverTimer();
}
protected String getBeanClassName() {
return TimerBean.class.getSimpleName();
}
private Serializable info = "PersistentIntervalTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
// its persistent by default
return true;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertFalse("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 4,371 | 32.374046 | 148 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/PersistentIntervalTimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class PersistentIntervalTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, IntervalTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return IntervalTimerBean.class.getSimpleName();
}
private Serializable info = "PersistentIntervalTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return true;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertFalse("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 2,415 | 23.907216 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/CalendarTimerBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import jakarta.ejb.Remote;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
/**
* @author: baranowb
*/
@Stateless
@Remote(SimpleFace.class)
public class CalendarTimerBean extends AbstractTimerBean {
@Override
public void createTimer() {
ScheduleExpression scheduleExpression = new ScheduleExpression();
scheduleExpression.second(getSeconds());
scheduleExpression.hour("*");
scheduleExpression.minute("*");
final TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(persistent);
timerConfig.setInfo(info);
super.timerService.createCalendarTimer(scheduleExpression, timerConfig);
}
private String getSeconds() {
final Calendar calendar = Calendar.getInstance();
final int base = calendar.get(Calendar.SECOND);
int current = base;
List<Integer> list = new ArrayList<Integer>();
final int boundary = base + 60;
final int delay = AbstractTimerBean.delay / 1000;
for (; current < boundary;) {
list.add(current % 60);
current += delay;
}
final int limit = list.size() - 1;
StringBuilder stringBuilder = new StringBuilder();
for (int index = 0; index < list.size(); index++) {
stringBuilder.append(list.get(index));
if (index < limit) {
stringBuilder.append(",");
}
}
return stringBuilder.toString();
}
@Override
public String getComparableTimerDetail() {
for (Timer t : this.timerService.getTimers()) {
return t.getSchedule().getSecond();
}
return null;
}
}
| 1,907 | 29.285714 | 80 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/SimpleFace.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
public interface SimpleFace {
void clean();
void createTimer();
int getTimerCount();
int getTimerTicks();
void waitOnTimeout() throws InterruptedException;
void setPersistent(boolean persistent);
void setInfo(Serializable info);
void setDelay(int delay);
String getComparableTimerDetail();
}
| 429 | 16.2 | 60 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/IntervalTimerBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.ejb.TimerConfig;
/**
* @author: baranowb
*/
@Stateless
@Remote(SimpleFace.class)
public class IntervalTimerBean extends AbstractTimerBean {
@Override
public void createTimer() {
final TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(persistent);
timerConfig.setInfo(info);
super.timerService.createIntervalTimer(delay, delay, timerConfig);
}
}
| 548 | 23.954545 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/TimerBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author: baranowb
*/
@Stateless
@Remote(SimpleFace.class)
public class TimerBean extends AbstractTimerBean {
@Override
public void createTimer() {
super.timerService.createTimer(delay, info);
}
}
| 346 | 17.263158 | 60 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/PersistentCalendarTimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
@Ignore("Intermittently fails")
public class PersistentCalendarTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, CalendarTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return CalendarTimerBean.class.getSimpleName();
}
private Serializable info = "PersistentCalendarTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return true;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertTrue("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 2,471 | 23.969697 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/AbstractTimerBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
import org.jboss.logging.Logger;
public abstract class AbstractTimerBean implements SimpleFace {
protected final Logger logger = Logger.getLogger(getClass());
protected static int timerTicks = 0;
protected static int delay = 5000;
protected static Serializable info;
protected static boolean persistent;
protected static CountDownLatch latch;
@Resource
protected TimerService timerService;
@Override
public void clean() {
for (Timer t : this.timerService.getTimers()) {
t.cancel();
}
timerTicks = 0;
}
@Override
public int getTimerTicks() {
return timerTicks;
}
@Override
public int getTimerCount() {
return this.timerService.getTimers().size();
}
@Override
public void waitOnTimeout() throws InterruptedException {
latch = new CountDownLatch(1);
latch.await(delay * 2, TimeUnit.MILLISECONDS);
}
@Timeout
public void booom(Timer t) {
new Exception().printStackTrace();
timerTicks++;
if (latch != null)
latch.countDown();
}
@Override
public void setPersistent(boolean persistent) {
AbstractTimerBean.persistent = persistent;
}
@Override
public void setInfo(Serializable info) {
AbstractTimerBean.info = info;
}
@Override
public void setDelay(int delay) {
AbstractTimerBean.delay = delay;
}
@Override
public String getComparableTimerDetail() {
return null;
}
}
| 1,845 | 22.666667 | 65 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/NonPersistentIntervalTimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class NonPersistentIntervalTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, IntervalTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return IntervalTimerBean.class.getSimpleName();
}
private Serializable info = "NonPersistentIntervalTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return false;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertFalse("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 2,422 | 23.979381 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/NonPersistentCalendarTimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.Serializable;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* Test non persistent interval timer.
*
* @author: baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class NonPersistentCalendarTimerManagementTestCase extends AbstractTimerManagementTestCase {
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, getArchiveName());
ejbJar.addClasses(AbstractTimerManagementTestCase.class, CalendarTimerBean.class, AbstractTimerBean.class, SimpleFace.class);
return ejbJar;
}
@After
public void clean() {
super.clean();
}
@Before
public void setup() throws Exception {
super.setup();
}
@Test
@InSequence(1)
public void testResourceExistence() throws Exception {
super.testResourceExistence();
}
@Test
@InSequence(2)
public void testSuspendAndActivate() throws Exception {
super.testSuspendAndActivate();
}
@Test
@InSequence(3)
public void testCancel() throws Exception {
super.testCancel();
}
@Test
@InSequence(4)
public void testTrigger() throws Exception {
super.testTrigger();
}
@Test
@InSequence(5)
public void testSuspendAndTrigger() throws Exception {
super.testSuspendAndTrigger();
}
protected String getBeanClassName() {
return CalendarTimerBean.class.getSimpleName();
}
private Serializable info = "NonPersistentCalendarTimerCLITestCase";
@Override
protected Serializable getInfo() {
return info;
}
@Override
protected boolean isPersistent() {
return false;
}
@Override
protected void assertCalendar(final ModelNode timerDetails) {
Assert.assertTrue("Calendar", this.isCalendarTimer(timerDetails));
}
}
| 2,421 | 23.969072 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/mgmt/AbstractTimerManagementTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.mgmt;
import java.io.IOException;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Set;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.junit.Assert;
/**
*
* Base test class for timer mgmt operations
*
* @author: baranowb
*/
public abstract class AbstractTimerManagementTestCase {
@ContainerResource
protected ManagementClient managementClient;
private static final String APP_NAME = "ejb-mgmt-timers";
protected SimpleFace bean;
protected PathAddress timerAddress;
protected String timerId;
public static String getArchiveName() {
return APP_NAME + ".jar";
}
public void clean() {
if (bean != null) {
try {
bean.clean();
} catch (Exception e) {
}
}
this.timerId = null;
this.bean = null;
}
public void setup() throws Exception {
this.lookupBean();
this.bean.setPersistent(isPersistent());
this.bean.setInfo(getInfo());
this.bean.setDelay(getDelay());
}
protected void lookupBean() throws Exception {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
this.bean = (SimpleFace) context.lookup("ejb:/" + APP_NAME + "/" + getBeanClassName()
+ "!org.jboss.as.test.integration.ejb.timerservice.mgmt.SimpleFace");
}
protected String getBeanClassName() {
return IntervalTimerBean.class.getSimpleName();
}
public void testResourceExistence() throws Exception {
assertNoTimers();
this.bean.createTimer();
ModelNode timerDetails = getTimerDetails();
Assert.assertEquals("Persistent", this.isPersistent(), this.isPersistent(timerDetails));
Assert.assertEquals("Serializable Info", this.getInfo(), this.getInfo(timerDetails));
Assert.assertTrue("Active", this.isActive(timerDetails));
assertCalendar(timerDetails);
final int left = this.getTimeRemaining(timerDetails);
final int to = getDelay();
Assert.assertTrue("Not enough time? '"+left+"'<='"+to+"'", left <= to);
if(this.isCalendarTimer(timerDetails)){
final ModelNode schedule = timerDetails.get("schedule");
checkCalendardSchedule("year", "*", true, schedule);
checkCalendardSchedule("month", "*", true, schedule);
checkCalendardSchedule("day-of-month", "*", true, schedule);
checkCalendardSchedule("day-of-week", "*", true, schedule);
checkCalendardSchedule("hour", "*", true, schedule);
checkCalendardSchedule("minute", "*", true, schedule);
checkCalendardSchedule("second", getCalendarTimerDetail(), true, schedule);
checkCalendardSchedule("timezone", null, false, schedule);
checkCalendardSchedule("start", null, false, schedule);
checkCalendardSchedule("end", null, false, schedule);
}
}
public void testSuspendAndActivate() throws Exception {
assertNoTimers();
this.bean.createTimer();
this.bean.waitOnTimeout();
this.suspendTimer();
final long ticksCount = this.bean.getTimerTicks();
this.waitOverTimer();
Assert.assertEquals("Timer ticks should not change after suspension!", ticksCount, this.bean.getTimerTicks());
this.activateTimer();
this.bean.waitOnTimeout();
}
public void testCancel() throws Exception {
assertNoTimers();
this.bean.createTimer();
this.bean.waitOnTimeout();
getTimerDetails();
this.cancelTimer();
try {
getTimerDetails();
} catch (OperationFailedException ofe) {
final ModelNode failureDescription = ofe.getFailureDescription();
Assert.assertTrue(failureDescription.toString(), failureDescription.toString().contains("WFLYCTL0216"));
}
}
public void testTrigger() throws Exception {
assertNoTimers();
this.bean.createTimer();
Assert.assertEquals("Wrong initial timer ticks!", 0, this.bean.getTimerTicks());
triggerTimer();
Assert.assertEquals("Wrong after trigger timer ticks!", 1, this.bean.getTimerTicks());
this.bean.waitOnTimeout();
Assert.assertEquals("Timer should fire twice!", 2, this.bean.getTimerTicks());
}
public void testSuspendAndTrigger() throws Exception {
assertNoTimers();
this.bean.createTimer();
Assert.assertEquals("Wrong initial timer ticks!", 0, this.bean.getTimerTicks());
triggerTimer();
this.suspendTimer();
int ticksCount = this.bean.getTimerTicks();
Assert.assertTrue("Timer should fire at least once!", ticksCount >= 1);
this.waitOverTimer();
Assert.assertEquals("The tick count should not increase while the timer was suspended!",
ticksCount, this.bean.getTimerTicks());
this.activateTimer();
this.bean.waitOnTimeout();
Assert.assertTrue("Number of ticks should increase after timer activation!",
this.bean.getTimerTicks() > ticksCount);
}
protected void suspendTimer() throws Exception {
final PathAddress address = getTimerAddress();
final ModelNode operation = Util.createOperation("suspend", address);
executeForResult(operation, true);
}
protected void activateTimer() throws Exception {
final PathAddress address = getTimerAddress();
final ModelNode operation = Util.createOperation("activate", address);
executeForResult(operation, true);
}
protected void triggerTimer() throws Exception {
final PathAddress address = getTimerAddress();
final ModelNode operation = Util.createOperation("trigger", address);
executeForResult(operation, true);
}
protected void cancelTimer() throws Exception {
final PathAddress address = getTimerAddress();
final ModelNode operation = Util.createOperation("cancel", address);
executeForResult(operation, true);
}
protected ModelNode getTimerDetails() throws Exception {
final PathAddress address = getTimerAddress();
final ModelNode operation = Util.createOperation("read-resource", address);
operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(Boolean.toString(true));
return executeForResult(operation, false);
}
protected PathAddress getTimerAddressBase() {
return PathAddress.pathAddress(
PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, APP_NAME + ".jar"),
PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "ejb3"),
PathElement.pathElement("stateless-session-bean", getBeanClassName()),
PathElement.pathElement("service", "timer-service"));
}
protected PathAddress getTimerAddress() throws Exception {
if (this.timerAddress != null) {
return this.timerAddress;
}
final PathAddress address = getTimerAddressBase();
final ModelNode operation = Util.createOperation("read-resource", address);
operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true);
final ModelNode result = managementClient.getControllerClient().execute(operation);
Assert.assertEquals(result.toString(), ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME)
.asString());
final ModelNode tmp = result.get("result").get("timer");
final Set<String> lst = tmp.keys();
Assert.assertEquals(1, lst.size());
this.timerId = lst.iterator().next();
this.timerAddress = PathAddress.pathAddress(address, PathElement.pathElement("timer", this.timerId));
return this.timerAddress;
}
protected boolean isActive(final ModelNode timerDetails) {
return timerDetails.get("active").asString().equalsIgnoreCase("true");
}
protected boolean isCalendarTimer(final ModelNode timerDetails) {
return timerDetails.get("calendar-timer").asString().equalsIgnoreCase("true");
}
protected boolean isPersistent(final ModelNode timerDetails) {
return timerDetails.get("persistent").asString().equalsIgnoreCase("true");
}
protected Serializable getInfo(final ModelNode timerDetails) {
// TODO this is just wrong
return timerDetails.get("info").asString();
}
protected int getTimeRemaining(final ModelNode timerDetails) {
return timerDetails.get("time-remaining").asInt();
}
protected ModelNode getSchedule(final ModelNode timerDetails) {
return timerDetails.get("schedule");
}
protected void checkCalendardSchedule(final String name, final String expected, final boolean mustBeDefined, final ModelNode schedule ){
final ModelNode target = schedule.get(name);
if(mustBeDefined){
Assert.assertEquals("The '"+name+"' has wrong value!",expected, target.asString());
} else {
Assert.assertEquals("The '"+name+"' should be undefined!",ModelType.UNDEFINED, target.getType());
}
}
protected int getDelay() {
return 3000;
}
protected void waitOverTimer() throws Exception {
Thread.currentThread().sleep(this.getDelay() + 1000);
}
protected void assertNoTimers() {
Assert.assertEquals("No timers should be present!", 0, this.bean.getTimerCount());
}
protected abstract Serializable getInfo();
protected abstract boolean isPersistent();
protected abstract void assertCalendar(final ModelNode timerDetails);
protected String getCalendarTimerDetail(){
return this.bean.getComparableTimerDetail();
}
protected ModelNode executeForResult(ModelNode operation) throws OperationFailedException, IOException {
return this.managementClient.getControllerClient().execute(operation);
}
private ModelNode executeForResult(ModelNode operation, boolean useOpForFailureMsg) throws OperationFailedException, IOException {
final ModelNode response = this.managementClient.getControllerClient().execute(operation);
if (!Operations.isSuccessfulOutcome(response)) {
if (useOpForFailureMsg) {
throw new OperationFailedException("Failed executing " + operation.toString());
} else {
throw new OperationFailedException(response.asString());
}
}
return response.get(ModelDescriptionConstants.RESULT);
}
}
| 11,482 | 39.291228 | 140 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/CDIInterceptor.java
|
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
@Interceptor
@Intercepted
public class CDIInterceptor {
@AroundTimeout
public Object aroundTimeout(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(CDIInterceptor.class);
return context.proceed();
}
}
| 496 | 21.590909 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/MethodInterceptorChild.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class MethodInterceptorChild extends MethodInterceptorParent {
@AroundTimeout
public Object aroundTimeoutChild(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(MethodInterceptorChild.class);
return context.proceed();
}
}
| 1,498 | 37.435897 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/InterceptorChild.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class InterceptorChild extends InterceptorParent {
@AroundTimeout
public Object aroundTimeout(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(InterceptorChild.class);
return context.proceed();
}
}
| 1,475 | 36.846154 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/InterceptorParent.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class InterceptorParent {
@AroundTimeout
public Object aroundTimeoutParent(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(InterceptorParent.class);
return context.proceed();
}
}
| 1,457 | 36.384615 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/MethodInterceptorParent.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class MethodInterceptorParent {
@AroundTimeout
public Object aroundTimeout(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(MethodInterceptorParent.class);
return context.proceed();
}
}
| 1,464 | 36.564103 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/BeanChild.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import jakarta.ejb.Stateless;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.Interceptors;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
@Stateless
@Interceptors(InterceptorChild.class)
@Intercepted
public class BeanChild extends BeanParent {
@AroundTimeout
public Object aroundTimeoutChild(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(BeanChild.class);
return context.proceed();
}
}
| 1,592 | 35.204545 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/Intercepted.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import jakarta.interceptor.InterceptorBinding;
/**
* @author Stuart Douglas
*/
@Retention(RetentionPolicy.RUNTIME)
@InterceptorBinding
public @interface Intercepted {
}
| 1,344 | 36.361111 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/TimerServiceInterceptorOrderTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an @Timout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServiceInterceptorOrderTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceInterceptorOrder.war");
war.addPackage(TimerServiceInterceptorOrderTestCase.class.getPackage());
war.addAsWebInfResource(TimerServiceInterceptorOrderTestCase.class.getPackage(), "beans.xml", "beans.xml");
return war;
}
@Test
public void testArountTimeoutInterceptorOrder() throws NamingException {
InterceptorOrder.reset();
InitialContext ctx = new InitialContext();
BeanChild bean = (BeanChild) ctx.lookup("java:module/" + BeanChild.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(BeanParent.awaitTimerCall());
InterceptorOrder.assertEquals(InterceptorParent.class, InterceptorChild.class, MethodInterceptorParent.class, MethodInterceptorChild.class, CDIInterceptor.class, BeanParent.class, BeanChild.class);
}
}
| 2,642 | 39.661538 | 205 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/BeanParent.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.Interceptors;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class BeanParent {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_TIMEOUT_TIME_MS = 100;
// has to be greater than timeout time
private static final int TIMER_CALL_WAITING_MS = 30000;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
@AroundTimeout
public Object aroundTimeoutParent(final InvocationContext context) throws Exception {
InterceptorOrder.intercept(BeanParent.class);
return context.proceed();
}
@Timeout
@Interceptors(MethodInterceptorChild.class)
private void timeout(Timer timer) {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,581 | 33.426667 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/aroundtimeout/InterceptorOrder.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.aroundtimeout;
import org.junit.Assert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Stuart Douglas
*/
public class InterceptorOrder {
private static final List<Class<?>> order = new ArrayList<Class<?>>();
public static void reset() {
order.clear();
}
public static void intercept(Class<?> type) {
order.add(type);
}
public static void assertEquals(Class ... expected) {
Assert.assertEquals(Arrays.asList(expected), order);
}
}
| 1,608 | 29.942308 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cancelation/CalendarTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.cancelation;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerHandle;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class CalendarTimerServiceBean {
// should to be greater then one second (1000ms)
private static final int TIMER_CALL_QUICK_WAITING_MS = 1200;
private static final CountDownLatch latch = new CountDownLatch(1);
private static volatile boolean timerServiceCalled = false;
boolean first = true;
private final CountDownLatch timerEntry = new CountDownLatch(1);
private final CountDownLatch timerExit = new CountDownLatch(1);
public TimerHandle createTimer() {
ScheduleExpression expression = new ScheduleExpression();
expression.second("*");
expression.minute("*");
expression.hour("*");
expression.dayOfMonth("*");
expression.year("*");
return timerService.createCalendarTimer(expression).getHandle();
}
@Resource
private TimerService timerService;
@Timeout
public void timeout() {
if (first) {
timerEntry.countDown();
try {
timerExit.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
first = false;
} else {
timerServiceCalled = true;
latch.countDown();
}
}
public int getTimerCount() {
return timerService.getTimers().size();
}
public static boolean quickAwaitTimerCall() {
try {
latch.await(TIMER_CALL_QUICK_WAITING_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
public CountDownLatch getTimerEntry() {
return timerEntry;
}
public CountDownLatch getTimerExit() {
return timerExit;
}
}
| 3,348 | 30.895238 | 76 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cancelation/SimpleTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.cancelation;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerHandle;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class SimpleTimerServiceBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_INIT_TIME_MS = 100;
private static final int TIMER_TIMEOUT_TIME_MS = 100;
// should to be greater then (timer init time + timeout time)
private static final int TIMER_CALL_QUICK_WAITING_MS = 1000;
private static volatile boolean timerServiceCalled = false;
boolean first = true;
private final CountDownLatch timerEntry = new CountDownLatch(1);
private final CountDownLatch timerExit = new CountDownLatch(1);
@Resource
private TimerService timerService;
public TimerHandle createTimer() {
return timerService.createTimer(TIMER_INIT_TIME_MS, TIMER_TIMEOUT_TIME_MS, null).getHandle();
}
@Timeout
public void timeout() {
if (first) {
timerEntry.countDown();
try {
timerExit.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
first = false;
} else {
timerServiceCalled = true;
latch.countDown();
}
}
public int getTimerCount() {
return timerService.getTimers().size();
}
public static boolean quickAwaitTimerCall() {
try {
latch.await(TIMER_CALL_QUICK_WAITING_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
public CountDownLatch getTimerEntry() {
return timerEntry;
}
public CountDownLatch getTimerExit() {
return timerExit;
}
}
| 3,235 | 31.686869 | 101 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cancelation/TimerServiceCancellationTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.cancelation;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.TimerHandle;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test that timer cancellation works as expected, even when there is a race between the timeout method and the
* cancellation itself
*
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServiceCancellationTestCase {
// countlatchdown waiting time
private static int TIMER_CALL_WAITING_S = 30;
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "timerCancelTest.jar");
jar.addPackage(TimerServiceCancellationTestCase.class.getPackage());
return jar;
}
@Test
public void testCancelSimpleWhileTimeoutActive() throws NamingException, InterruptedException {
InitialContext ctx = new InitialContext();
SimpleTimerServiceBean bean = (SimpleTimerServiceBean)ctx.lookup("java:module/" + SimpleTimerServiceBean.class.getSimpleName());
TimerHandle handle = bean.createTimer();
Assert.assertTrue(bean.getTimerEntry().await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS));
//now the timeout is in progress cancel the timer
handle.getTimer().cancel();
bean.getTimerExit().countDown();
Assert.assertFalse(SimpleTimerServiceBean.quickAwaitTimerCall());
Assert.assertEquals(0, bean.getTimerCount());
}
@Test
public void testCancelCalendarWhileTimeoutActive() throws NamingException, InterruptedException {
InitialContext ctx = new InitialContext();
CalendarTimerServiceBean bean = (CalendarTimerServiceBean)ctx.lookup("java:module/" + CalendarTimerServiceBean.class.getSimpleName());
TimerHandle handle = bean.createTimer();
Assert.assertTrue(bean.getTimerEntry().await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS));
//now the timeout is in progress cancel the timer
handle.getTimer().cancel();
bean.getTimerExit().countDown();
Assert.assertFalse(CalendarTimerServiceBean.quickAwaitTimerCall());
Assert.assertEquals(0, bean.getTimerCount());
}
}
| 2,558 | 37.19403 | 142 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/simple/SimpleTimerServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.simple;
import java.util.Date;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an @Timeout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class SimpleTimerServiceTestCase {
private static int TIMER_INIT_TIME_MS = 100;
private static int TIMER_TIMEOUT_TIME_MS = 100;
private static String INFO_MSG_FOR_CHECK = "info";
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceSimple.war");
war.addPackage(SimpleTimerServiceTestCase.class.getPackage());
return war;
}
@Test
@InSequence(1)
public void testAnnotationTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
AnnotationTimerServiceBean bean = (AnnotationTimerServiceBean) ctx.lookup("java:module/" + AnnotationTimerServiceBean.class.getSimpleName());
bean.resetTimerServiceCalled();
bean.getTimerService().createTimer(TIMER_TIMEOUT_TIME_MS, INFO_MSG_FOR_CHECK);
Assert.assertTrue(AnnotationTimerServiceBean.awaitTimerCall());
bean.resetTimerServiceCalled();
long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
bean.getTimerService().createTimer(new Date(ts), INFO_MSG_FOR_CHECK);
Assert.assertTrue(AnnotationTimerServiceBean.awaitTimerCall());
Assert.assertEquals(INFO_MSG_FOR_CHECK, bean.getTimerInfo());
Assert.assertFalse(bean.isCalendar());
Assert.assertTrue(bean.isPersistent());
}
@Test
@InSequence(2)
public void testTimedObjectTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimedObjectTimerServiceBean bean = (TimedObjectTimerServiceBean) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
bean.resetTimerServiceCalled();
bean.getTimerService().createTimer(TIMER_TIMEOUT_TIME_MS, INFO_MSG_FOR_CHECK);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
bean.resetTimerServiceCalled();
long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(INFO_MSG_FOR_CHECK);
bean.getTimerService().createSingleActionTimer(new Date(ts), timerConfig);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
Assert.assertEquals(INFO_MSG_FOR_CHECK, bean.getTimerInfo());
Assert.assertFalse(bean.isCalendar());
Assert.assertTrue(bean.isPersistent());
}
@Test
@InSequence(3)
public void testIntervalTimer() throws NamingException {
InitialContext ctx = new InitialContext();
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(INFO_MSG_FOR_CHECK);
AnnotationTimerServiceBean bean1 = (AnnotationTimerServiceBean) ctx.lookup("java:module/" + AnnotationTimerServiceBean.class.getSimpleName());
bean1.resetTimerServiceCalled();
long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
Timer timer1 = bean1.getTimerService().createIntervalTimer(new Date(ts), TIMER_TIMEOUT_TIME_MS, timerConfig);
Assert.assertTrue(AnnotationTimerServiceBean.awaitTimerCall());
bean1.resetTimerServiceCalled();
Assert.assertTrue(AnnotationTimerServiceBean.awaitTimerCall());
//verifies that timer1 equals itself and does not equal null
Assert.assertTrue(timer1.equals(timer1));
Assert.assertFalse(timer1.equals(null));
timer1.cancel();
TimedObjectTimerServiceBean bean2 = (TimedObjectTimerServiceBean) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
bean2.resetTimerServiceCalled();
Timer timer2 = bean2.getTimerService().createIntervalTimer(TIMER_INIT_TIME_MS, TIMER_TIMEOUT_TIME_MS, timerConfig);
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
bean2.resetTimerServiceCalled();
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
timer2.cancel();
}
}
| 5,709 | 42.257576 | 153 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/simple/AnnotationTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.simple;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
import org.jboss.logging.Logger;
/**
* @author Stuart Douglas
*/
@Stateless
public class AnnotationTimerServiceBean {
private static final Logger log = Logger.getLogger(AnnotationTimerServiceBean.class);
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static volatile boolean timerServiceCalled = false;
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile String timerInfo;
private static volatile boolean isPersistent;
private static volatile boolean isCalendar;
@Resource
private SessionContext sessionContext;
private TimerService timerService;
public synchronized TimerService getTimerService() {
if(timerService == null) {
timerService = (TimerService) sessionContext.lookup("java:comp/TimerService");
}
return timerService;
}
public void resetTimerServiceCalled() {
timerServiceCalled = false;
latch = new CountDownLatch(1);
}
public String getTimerInfo() {
return timerInfo;
}
public boolean isPersistent() {
return isPersistent;
}
public boolean isCalendar() {
return isCalendar;
}
@Timeout
public void timeout(Timer timer) {
log.trace("Timer is: " + timer + ", timer info is: " + timer.getInfo());
timerInfo = new String((String) timer.getInfo());
isPersistent = timer.isPersistent();
isCalendar = timer.isCalendarTimer();
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 3,179 | 31.121212 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/simple/TimedObjectTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.simple;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class TimedObjectTimerServiceBean implements TimedObject {
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Resource
private SessionContext sessionContext;
private TimerService timerService;
private static volatile String timerInfo;
private static volatile boolean isPersistent;
private static volatile boolean isCalendar;
public synchronized TimerService getTimerService() {
if (timerService == null) {
timerService = (TimerService) sessionContext.lookup("java:comp/TimerService");
}
return timerService;
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
public void resetTimerServiceCalled() {
timerServiceCalled = false;
latch = new CountDownLatch(1);
}
public String getTimerInfo() {
return timerInfo;
}
public boolean isPersistent() {
return isPersistent;
}
public boolean isCalendar() {
return isCalendar;
}
@Override
public void ejbTimeout(final Timer timer) {
timerInfo = new String((String) timer.getInfo());
isPersistent = timer.isPersistent();
isCalendar = timer.isCalendarTimer();
timerServiceCalled = true;
latch.countDown();
}
}
| 3,013 | 30.726316 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cdi/requestscope/CdiBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.cdi.requestscope;
import jakarta.enterprise.context.RequestScoped;
/**
* @author Stuart Douglas
*/
@RequestScoped
public class CdiBean {
public static final String MESSAGE = "Hello";
public String getMessage() {
return MESSAGE;
}
}
| 1,330 | 33.128205 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cdi/requestscope/AnnotationTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.cdi.requestscope;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerService;
import jakarta.inject.Inject;
/**
* @author Stuart Douglas
*/
@Stateless
public class AnnotationTimerServiceBean {
private static final int TIMER_TIMEOUT_TIME_MS = 100;
// has to be greater than timeout time
private static final int TIMER_CALL_WAITING_MS = 30000;
private static final CountDownLatch latch = new CountDownLatch(1);
private static volatile String cdiMessage = null;
@Inject
private CdiBean cdiBean;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
public void timeout() {
cdiMessage = cdiBean.getMessage();
latch.countDown();
}
public static String awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return cdiMessage;
}
}
| 2,284 | 30.736111 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/cdi/requestscope/CDIRequestScopeTimerServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.cdi.requestscope;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that an @Timeout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class CDIRequestScopeTimerServiceTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceSimple.war");
war.addPackage(CDIRequestScopeTimerServiceTestCase.class.getPackage());
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
@Test
public void testRequestScopeActive() throws NamingException {
InitialContext ctx = new InitialContext();
AnnotationTimerServiceBean bean = (AnnotationTimerServiceBean) ctx.lookup("java:module/" + AnnotationTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertEquals(CdiBean.MESSAGE, AnnotationTimerServiceBean.awaitTimerCall());
}
}
| 2,470 | 37.609375 | 149 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/gettimers/GetTimersTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.test.integration.ejb.timerservice.gettimers;
import java.util.Collection;
import java.util.Map;
import jakarta.ejb.Timer;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test case for https://issues.jboss.org/browse/WFLY-5221
*
* @author Tomas Hofman ([email protected])
*/
@RunWith(Arquillian.class)
public class GetTimersTestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "gettimers.jar");
jar.addPackage(GetTimersTestCase.class.getPackage());
return jar;
}
@Test
public void testGetTimers() throws NamingException {
InitialContext ctx = new InitialContext();
StartupBean starterBean = (StartupBean) ctx.lookup("java:module/" + StartupBean.class.getSimpleName());
AbstractTimerBean bean1 = (AbstractTimerBean) ctx.lookup("java:module/" + TimerBeanOne.class.getSimpleName());
AbstractTimerBean bean2 = (AbstractTimerBean) ctx.lookup("java:module/" + TimerBeanTwo.class.getSimpleName());
try {
Map<String, Collection<Timer>> beanTimersMap = starterBean.startTimers();
assertTimersPrefix(beanTimersMap.get(TimerBeanOne.class.getSimpleName()), TimerBeanOne.class.getSimpleName());
assertTimersPrefix(beanTimersMap.get(TimerBeanTwo.class.getSimpleName()), TimerBeanTwo.class.getSimpleName());
} finally {
bean1.stopTimers();
bean2.stopTimers();
Assert.assertEquals(0, bean1.getTimers().size());
Assert.assertEquals(0, bean2.getTimers().size());
}
}
public void assertTimersPrefix(Collection<Timer> timers, String bean) {
for (Timer timer : timers) {
Assert.assertTrue(String.format("Bean %s returned timer %s which doesn't belong to this bean.",
bean, timer.getInfo()),
timer.getInfo().toString().startsWith(bean));
}
}
}
| 3,377 | 38.741176 | 122 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/gettimers/TimerBeanTwo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.test.integration.ejb.timerservice.gettimers;
import jakarta.ejb.Stateless;
/**
* @author Tomas Hofman ([email protected])
*/
@Stateless
public class TimerBeanTwo extends AbstractTimerBean {
}
| 1,254 | 35.911765 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/gettimers/AbstractTimerBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.test.integration.ejb.timerservice.gettimers;
import java.util.Collection;
import jakarta.annotation.Resource;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
import org.jboss.logging.Logger;
/**
* @author Tomas Hofman ([email protected])
*/
public abstract class AbstractTimerBean {
public static final int NUMBER_OF_TIMERS = 5;
private Logger logger = Logger.getLogger(getClass());
@Resource
private TimerService timerService;
public void startTimers() {
logger.trace("Initially had these timers:");
for (Timer timer: timerService.getTimers()) {
logger.trace(" " + timer.getInfo());
}
for (int i = 0; i < NUMBER_OF_TIMERS; i++) {
String name = getClass().getSimpleName() + "#" + i;
logger.debugf("Starting timer %s", name);
timerService.createTimer(100000, 100000, name); // doesn't really need any timeouts to happen
}
}
public Collection<Timer> getTimers() {
return timerService.getTimers();
}
public void stopTimers() {
logger.debug("Stopping all timers.");
for (Timer timer: timerService.getTimers()) {
logger.debugf("Stopping timer %s.", timer.getInfo().toString());
timer.cancel();
}
}
@Timeout
public void timeout(Timer timer) {
logger.infof("Timeout %s", timer.getInfo());
}
}
| 2,503 | 31.519481 | 105 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/gettimers/TimerBeanOne.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.test.integration.ejb.timerservice.gettimers;
import jakarta.ejb.Stateless;
/**
* @author Tomas Hofman ([email protected])
*/
@Stateless
public class TimerBeanOne extends AbstractTimerBean {
}
| 1,254 | 35.911765 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/gettimers/StartupBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.test.integration.ejb.timerservice.gettimers;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timer;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
/**
* @author Tomas Hofman ([email protected])
*/
@Singleton
public class StartupBean {
@EJB
TimerBeanOne timerBeanOne;
@EJB
TimerBeanTwo timerBeanTwo;
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
public Map<String, Collection<Timer>> startTimers() {
Map<String, Collection<Timer>> beanTimersMap = new HashMap<String, Collection<Timer>>();
timerBeanOne.startTimers();
beanTimersMap.put(TimerBeanOne.class.getSimpleName(), timerBeanOne.getTimers());
timerBeanTwo.startTimers();
beanTimersMap.put(TimerBeanTwo.class.getSimpleName(), timerBeanTwo.getTimers());
return beanTimersMap;
}
}
| 2,035 | 33.508475 | 96 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/SingletonScheduleBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Schedule;
import jakarta.ejb.Singleton;
/**
* User: jpai
*/
@Singleton
public class SingletonScheduleBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Schedule(second="*", minute = "*", hour = "*")
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 1,910 | 31.948276 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/SimpleScheduleBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Schedule;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import org.jboss.logging.Logger;
/**
* @author Stuart Douglas
*/
@Stateless
public class SimpleScheduleBean {
@Resource
private TimerService timerService;
private static final Logger log = Logger.getLogger(SimpleScheduleBean.class);
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
private static String timerInfo;
private static boolean isPersistent;
private static boolean isCalendar;
private static String timezone;
public String getTimerInfo() {
return timerInfo;
}
public boolean isPersistent() {
return isPersistent;
}
public boolean isCalendar() {
return isCalendar;
}
public String getTimezone() {
return timezone;
}
@Schedule(second="*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague")
public void timeout(Timer timer) {
timerInfo = (String) timer.getInfo();
log.trace("timer info= " + timerInfo);
isPersistent = timer.isPersistent();
isCalendar = timer.isCalendarTimer();
timezone = timer.getSchedule().getTimezone();
log.trace(timer.getSchedule().getEnd());
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
@Timeout
private void noop(Timer timer) {
}
/**
* Verifies that changing timezone in a schedule expression after the timer creation
* should not affect the previously created timer.
*/
public void verifyTimezone() {
final String[] zoneIds = {
"Europe/Andorra",
"Asia/Dubai",
"Asia/Kabul",
"America/Antigua",
"America/Anguilla",
"Africa/Johannesburg",
"Africa/Lusaka",
"Africa/Harare"
};
final ScheduleExpression exp = new ScheduleExpression().year(9999);
final ArrayList<Timer> timers = new ArrayList<>();
for (String z : zoneIds) {
exp.timezone(z);
timers.add(timerService.createCalendarTimer(exp, new TimerConfig(z, false)));
}
RuntimeException e = null;
for (Timer t : timers) {
final Serializable info = t.getInfo();
final String timezone = t.getSchedule().getTimezone();
if (!info.equals(timezone)) {
e = new RuntimeException(
String.format("Expecting schedule expression timezone: %s, but got: %s", info, timezone));
break;
}
}
for (Timer t : timers) {
try {
t.cancel();
} catch (Exception ignore) {
}
}
if (e != null) {
throw e;
}
}
}
| 4,620 | 31.542254 | 114 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/SimpleSchedulesBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Schedule;
import jakarta.ejb.Schedules;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class SimpleSchedulesBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
private static String timerInfo;
private static boolean isPersistent;
private static boolean isCalendar;
@Resource
private TimerService timerService;
public String getTimerInfo() {
return timerInfo;
}
public boolean isPersistent() {
return isPersistent;
}
public boolean isCalendar() {
return isCalendar;
}
@Schedules({
@Schedule(second="0/2", minute = "*", hour = "*", info = "info"),
@Schedule(second="1/2", minute = "*", hour = "*", info = "info"),
@Schedule(second="1/0", info = "S0", year = "9999", persistent = false),
@Schedule(minute = "1/0", info = "M0", year = "9999", persistent = false),
@Schedule(hour = "0/0", info = "H0", year = "9999", persistent = false)
})
public void timeout(Timer timer) {
timerInfo = (String) timer.getInfo();
isPersistent = timer.isPersistent();
isCalendar = timer.isCalendarTimer();
timerServiceCalled = true;
latch.countDown();
}
public Collection<Timer> getTimers() {
return timerService.getTimers();
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 3,068 | 32 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/SimpleScheduleSecondTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that persistent timers created out of @Schedule work fine
*
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class SimpleScheduleSecondTestCase {
@Deployment
public static Archive<?> deploy() {
return SimpleScheduleFirstTestCase.createDeployment(SimpleScheduleSecondTestCase.class);
}
/**
* The timer should be restored and the @Schedule must timeout
*/
@Test
public void testScheduleMethodTimeout() throws NamingException {
InitialContext ctx = new InitialContext();
SimpleScheduleBean bean = (SimpleScheduleBean)ctx.lookup("java:module/" + SimpleScheduleBean.class.getSimpleName());
Assert.assertTrue(SimpleScheduleBean.awaitTimerCall());
final SingletonScheduleBean singletonBean = (SingletonScheduleBean) ctx.lookup("java:module/" + SingletonScheduleBean.class.getSimpleName());
Assert.assertTrue(SingletonScheduleBean.awaitTimerCall());
}
}
| 2,353 | 36.967742 | 149 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/SimpleScheduleFirstTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an @Timout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class SimpleScheduleFirstTestCase {
@Deployment
public static Archive<?> deploy() {
return createDeployment(SimpleScheduleFirstTestCase.class);
}
public static Archive<?> createDeployment(final Class<?> testClass) {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testSchedule.war");
war.addClasses(SimpleScheduleBean.class, SimpleSchedulesBean.class, SingletonScheduleBean.class);
war.addClass(testClass);
return war;
}
@Test
public void testScheduleAnnotation() throws NamingException {
InitialContext ctx = new InitialContext();
SimpleScheduleBean bean = (SimpleScheduleBean) ctx.lookup("java:module/" + SimpleScheduleBean.class.getSimpleName());
Assert.assertTrue(SimpleScheduleBean.awaitTimerCall());
Assert.assertEquals("info", bean.getTimerInfo());
Assert.assertEquals("Europe/Prague", bean.getTimezone());
Assert.assertTrue(bean.isCalendar());
Assert.assertFalse(bean.isPersistent());
final SingletonScheduleBean singletonBean = (SingletonScheduleBean) ctx.lookup("java:module/" + SingletonScheduleBean.class.getSimpleName());
Assert.assertTrue(SingletonScheduleBean.awaitTimerCall());
}
@Test
public void testScheduleTimezone() throws NamingException {
InitialContext ctx = new InitialContext();
SimpleScheduleBean bean = (SimpleScheduleBean) ctx.lookup("java:module/" + SimpleScheduleBean.class.getSimpleName());
bean.verifyTimezone();
}
@Test
public void testSchedulesAnnotation() throws NamingException {
InitialContext ctx = new InitialContext();
SimpleSchedulesBean bean = (SimpleSchedulesBean) ctx.lookup("java:module/" + SimpleSchedulesBean.class.getSimpleName());
Assert.assertTrue(SimpleSchedulesBean.awaitTimerCall());
Assert.assertEquals(5, bean.getTimers().size());
Assert.assertEquals("info", bean.getTimerInfo());
Assert.assertTrue(bean.isCalendar());
Assert.assertTrue(bean.isPersistent());
}
}
| 3,721 | 39.021505 | 149 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/schedule/descriptor/DescriptorScheduleBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.timerservice.schedule.descriptor;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Timer;
/**
* Ejb with it's timers managed by a descriptor
*
* @author Stuart Douglas
*/
public class DescriptorScheduleBean {
private static volatile String timerInfo;
private static volatile Date start;
private static int TIMER_CALL_WAITING_S = 30;
private static volatile CountDownLatch latch = new CountDownLatch(1);
public void descriptorScheduledMethod(final Timer timer) {
timerInfo = (String) timer.getInfo();
start = timer.getSchedule().getStart();
latch.countDown();
}
public static boolean awaitTimer(){
try {
final boolean success = latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
if (!success)
throw new IllegalStateException("Timeout method was not called");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerInfo != null;
}
public static Date getStart() {
return start;
}
public static String getTimerInfo() {
return timerInfo;
}
}
| 2,282 | 32.573529 | 88 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.