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/timerservice/schedule/descriptor/DescriptorScheduleTestCase.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 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 DescriptorScheduleTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testDescriptorSchedule.war");
war.addPackage(DescriptorScheduleTestCase.class.getPackage());
war.addAsWebInfResource(DescriptorScheduleTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return war;
}
@Test
public void testDescriptorBasedSchedule() throws NamingException {
InitialContext ctx = new InitialContext();
DescriptorScheduleBean bean = (DescriptorScheduleBean) ctx.lookup("java:module/" + DescriptorScheduleBean.class.getSimpleName());
Assert.assertTrue(DescriptorScheduleBean.awaitTimer());
Assert.assertEquals("INFO", DescriptorScheduleBean.getTimerInfo());
Assert.assertEquals(new Date(90, 0, 1, 0, 0, 0), DescriptorScheduleBean.getStart());
}
}
| 2,577 | 38.661538 | 137 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PrivateTxTimeoutBean.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.tx.timeout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import org.jboss.ejb3.annotation.TransactionTimeout;
/**
* @author Tomasz Adamski
*/
@Stateless
@Remote(TimeoutBeanRemoteView.class)
public class PrivateTxTimeoutBean extends AbstractTxBean implements TimeoutBeanRemoteView {
private static final int TIMER_CALL_WAITING_S = 30;
private static final int DURATION = 100;
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;
@Resource
private SessionContext sessionContext;
@Resource
private TimerService timerService;
@Override
public void startTimer() {
timerService.createSingleActionTimer(DURATION, new TimerConfig());
}
@Timeout
@TransactionTimeout(value = 5)
private void timeout(final Timer timer) {
timeout = checkTimeoutValue();
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;
}
public static int getTimeout(){
return timeout;
}
}
| 2,703 | 30.44186 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/TimeoutBeanRemoteView.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.tx.timeout;
public interface TimeoutBeanRemoteView {
void startTimer();
}
| 1,150 | 41.62963 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/TxTimeoutTimerServiceTestCase.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.tx.timeout;
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;
/**
* Tests that transaction annotations are applied to timeout method regardless of it's access modifier.
*
* @author Tomasz Adamski
*/
@RunWith(Arquillian.class)
public class TxTimeoutTimerServiceTestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "Jar.jar");
jar.addPackage(TxTimeoutTimerServiceTestCase.class.getPackage());
return jar;
}
@Test
public void testPublicTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimeoutBeanRemoteView bean = (TimeoutBeanRemoteView) ctx.lookup("java:module/"
+ PublicTxTimoutBean.class.getSimpleName());
bean.startTimer();
Assert.assertTrue(PublicTxTimoutBean.awaitTimerCall());
Assert.assertEquals(5, PublicTxTimoutBean.getTimeout());
}
@Test
public void testPrivateTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
TimeoutBeanRemoteView bean = (TimeoutBeanRemoteView) ctx.lookup("java:module/"
+ PrivateTxTimeoutBean.class.getSimpleName());
bean.startTimer();
Assert.assertTrue(PrivateTxTimeoutBean.awaitTimerCall());
Assert.assertEquals(5, PrivateTxTimeoutBean.getTimeout());
}
@Test
public void testPublicScheduleMethod() throws NamingException {
Assert.assertTrue(PublicTxScheduleBean.awaitTimerCall());
Assert.assertEquals(5, PublicTxScheduleBean.getTimeout());
}
@Test
public void testPrivateScheduleMethod() throws NamingException {
Assert.assertTrue(PrivateTxScheduleBean.awaitTimerCall());
Assert.assertEquals(5, PrivateTxScheduleBean.getTimeout());
}
}
| 3,252 | 37.72619 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/AbstractTxBean.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.tx.timeout;
import jakarta.annotation.Resource;
import jakarta.transaction.TransactionManager;
import org.wildfly.transaction.client.LocalTransaction;
/**
* @author Tomasz Adamski
*/
public abstract class AbstractTxBean {
@Resource(lookup = "java:jboss/TransactionManager")
private TransactionManager transactionManager;
private LocalTransaction transaction;
protected int checkTimeoutValue() {
try {
transaction = (LocalTransaction) transactionManager.getTransaction();
return transaction.getTransactionTimeout();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
| 1,735 | 35.166667 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PrivateTxScheduleBean.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.tx.timeout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import org.jboss.ejb3.annotation.TransactionTimeout;
/**
* @author Tomasz Adamski
*/
@Stateless
public class PrivateTxScheduleBean extends AbstractTxBean {
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 volatile int timeout = 0;
@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague")
@TransactionTimeout(value = 5)
private void timeout(Timer timer) {
timeout = checkTimeoutValue();
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;
}
public static int getTimeout() {
return timeout;
}
}
| 2,282 | 33.590909 | 116 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PublicTxTimoutBean.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.tx.timeout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import org.jboss.ejb3.annotation.TransactionTimeout;
/**
* @author Tomasz Adamski
*/
@Stateless
@Remote(TimeoutBeanRemoteView.class)
public class PublicTxTimoutBean extends AbstractTxBean implements TimeoutBeanRemoteView {
private static final int TIMER_CALL_WAITING_S = 30;
private static final int DURATION = 100;
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static volatile boolean timerServiceCalled = false;
private static volatile int timeout = 0;
@Resource
private SessionContext sessionContext;
@Resource
private TimerService timerService;
@Override
public void startTimer() {
timerService.createSingleActionTimer(DURATION, new TimerConfig());
}
@Timeout
@TransactionTimeout(value = 5)
public void timeout(final Timer timer) {
timeout = checkTimeoutValue();
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;
}
public static int getTimeout(){
return timeout;
}
}
| 2,702 | 29.715909 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PublicTxScheduleBean.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.tx.timeout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import org.jboss.ejb3.annotation.TransactionTimeout;
/**
* @author Tomasz Adamski
*/
@Stateless
public class PublicTxScheduleBean extends AbstractTxBean {
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 volatile int timeout = 0;
@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague")
@TransactionTimeout(value = 5)
public void timeout(Timer timer) {
timeout = checkTimeoutValue();
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;
}
public static int getTimeout() {
return timeout;
}
}
| 2,280 | 33.560606 | 116 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/retry/RollbackRetryBean.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.tx.retry;
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.Timeout;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class RollbackRetryBean {
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 = 10;
private static volatile int count = 0;
@Resource
private TimerService timerService;
@Resource
private EJBContext context;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
public void timeout() {
if(count == 0) {
//this should be retried
count++;
context.setRollbackOnly();
} else {
count++;
latch.countDown();
}
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return count > 1;
}
}
| 2,340 | 29.402597 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/retry/TimerRetryTestCase.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.tx.retry;
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;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that an @Timout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerRetryTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "timerRetryTestCase.war");
war.addPackage(TimerRetryTestCase.class.getPackage());
return war;
}
@Test
public void testRollbackRetry() throws NamingException {
InitialContext ctx = new InitialContext();
RollbackRetryBean bean = (RollbackRetryBean) ctx.lookup("java:module/" + RollbackRetryBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(RollbackRetryBean.awaitTimerCall());
}
@Test
public void testExceptionRetry() throws NamingException {
InitialContext ctx = new InitialContext();
ExceptionRetryBean bean = (ExceptionRetryBean) ctx.lookup("java:module/" + ExceptionRetryBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(ExceptionRetryBean.awaitTimerCall());
}
}
| 2,595 | 35.56338 | 125 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/retry/ExceptionRetryBean.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.tx.retry;
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;
/**
* @author Stuart Douglas
*/
@Stateless
public class ExceptionRetryBean {
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 = 10;
private static volatile int count = 0;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
public void timeout() {
if (count == 0) {
//this should be retried
count++;
throw new RuntimeException("First call failed");
} else {
count++;
latch.countDown();
}
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return count > 1;
}
}
| 2,286 | 30.328767 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/expired/SingletonBean.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.expired;
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.NoMoreTimeoutsException;
import jakarta.ejb.NoSuchObjectLocalException;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import org.jboss.logging.Logger;
/**
* @author Jaikiran Pai
*/
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class SingletonBean {
private static final Logger log = Logger.getLogger(SingletonBean.class);
private static int TIMER_CALL_WAITING_S = 5;
@Resource
private TimerService timerService;
private Timer timer;
private CountDownLatch timeoutNotifyingLatch;
private CountDownLatch timeoutWaiter;
public void createSingleActionTimer(final long delay, final TimerConfig config,
CountDownLatch timeoutNotifyingLatch, CountDownLatch timeoutWaiter) {
this.timer = this.timerService.createSingleActionTimer(delay, config);
this.timeoutNotifyingLatch = timeoutNotifyingLatch;
this.timeoutWaiter = timeoutWaiter;
}
@Timeout
private void onTimeout(final Timer timer) throws InterruptedException {
log.trace("Timeout invoked for " + this + " on timer " + timer);
this.timeoutNotifyingLatch.countDown();
log.debug("Waiting for timer will be permitted to continue");
this.timeoutWaiter.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
log.debug("End of onTimeout on singleton");
}
public Timer getTimer() {
return this.timer;
}
public void invokeTimeRemaining() throws NoMoreTimeoutsException, NoSuchObjectLocalException {
this.timer.getTimeRemaining();
}
public void invokeGetNext() throws NoMoreTimeoutsException, NoSuchObjectLocalException {
this.timer.getNextTimeout();
}
}
| 3,144 | 34.738636 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/expired/ExpiredTimerTestCase.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.expired;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.EJB;
import jakarta.ejb.NoMoreTimeoutsException;
import jakarta.ejb.NoSuchObjectLocalException;
import jakarta.ejb.TimerConfig;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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;
/**
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class ExpiredTimerTestCase {
private static final int TIMER_CALL_WAITING_S = 5;
private static final int TIMER_TIMEOUT_TIME_MS = 300;
private static final Logger log = Logger.getLogger(ExpiredTimerTestCase.class);
@EJB(mappedName = "java:module/SingletonBean")
private SingletonBean bean;
@Deployment
public static Archive<?> createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "expired-timer-test.jar");
jar.addPackage(ExpiredTimerTestCase.class.getPackage());
return jar;
}
@Test
public void testInvocationOnExpiredTimer() throws Exception {
final CountDownLatch timeoutNotifier = new CountDownLatch(1);
final CountDownLatch timeoutWaiter = new CountDownLatch(1);
this.bean.createSingleActionTimer(TIMER_TIMEOUT_TIME_MS, new TimerConfig(null, false), timeoutNotifier, timeoutWaiter);
// wait for the timeout to be invoked
final boolean timeoutInvoked = timeoutNotifier.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
Assert.assertTrue("timeout method was not invoked (within " + TIMER_CALL_WAITING_S + " seconds)", timeoutInvoked);
// the timer stays in timeout method - checking how the invoke of method getNext and getTimeRemaining behave
try {
bean.invokeTimeRemaining();
Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
} catch (NoMoreTimeoutsException e) {
log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getTimeRemaining");
}
try {
bean.invokeGetNext();
Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
} catch (NoMoreTimeoutsException e) {
log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getNextTimeout");
}
// the timeout can finish
timeoutWaiter.countDown();
// as we can't be exactly sure when the timeout method is finished in this moment
// we invoke in a loop, can check the exception type.
int count = 0;
boolean passed = false;
while (count < 20 && !passed) {
try {
bean.invokeTimeRemaining();
Assert.fail("Expected to fail on invoking on an expired timer");
} catch (NoSuchObjectLocalException nsole) {
// expected
log.trace("Got the expected exception " + nsole);
passed = true;
} catch (NoMoreTimeoutsException e) {
//this will be thrown if the timer is still active
Thread.sleep(100);
count++;
}
}
if(!passed) {
Assert.fail("Got NoMoreTimeoutsException rather than NoSuchObjectLocalException");
}
}
}
| 4,668 | 39.25 | 127 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/count/SimpleTimerBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.count;
import org.jboss.logging.Logger;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import java.util.Collection;
import java.util.Date;
/**
* @author: Jaikiran Pai
*/
@Stateless
@LocalBean
public class SimpleTimerBean {
static final String SCHEDULE_ONE_INFO = "foo-bar";
static final String SCHEDULE_TWO_INFO = "schedule-two";
private static final Logger logger = Logger.getLogger(SimpleTimerBean.class);
@Resource
private TimerService timerService;
@Schedule(second="*", minute = "*", hour = "*", year = "2100", persistent = false, info = SCHEDULE_ONE_INFO)
private void scheduleOne(final Timer timer) {
}
@Schedule(second="*", minute = "*", hour = "*", year = "2100", persistent = true, info = SCHEDULE_TWO_INFO)
private void scheduleTwo(final Timer timer) {
}
public void createTimerForNextDay(final boolean persistent, final String info) {
this.timerService.createSingleActionTimer(new Date(System.currentTimeMillis() + (60 * 60 * 24 * 1000)) , new TimerConfig(info, persistent));
logger.trace("Created a timer persistent = " + persistent + " info = " + info);
}
public Collection<Timer> getAllActiveTimersInEJBModule() {
return this.timerService.getAllTimers();
}
}
| 1,496 | 29.55102 | 148 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/count/StatefulBean.java
|
package org.jboss.as.test.integration.ejb.timerservice.count;
import java.util.Collection;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateful;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author: Jaikiran Pai
*/
@Stateful(passivationCapable = false)
@LocalBean
public class StatefulBean {
@Resource // we inject timerservice in a stateful bean so as to use (only) the TimerService.getAllTimers() method from the SFSB
private TimerService timerService;
public Collection<Timer> getAllActiveTimersInEJBModule() {
return this.timerService.getAllTimers();
}
}
| 651 | 25.08 | 131 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/count/ActiveTimerServiceCountTestCase.java
|
package org.jboss.as.test.integration.ejb.timerservice.count;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import jakarta.ejb.Timer;
import javax.naming.InitialContext;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Testcase for the {@link jakarta.ejb.TimerService#getAllTimers()} API introduced in EJB 3.2 spec
*
* @author: Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class ActiveTimerServiceCountTestCase {
private static final String APP_NAME = "ejb-3.2-active-timers";
private static final String MODULE_ONE_NAME = "ejb-3.2-active-timers-one";
private static final String MODULE_TWO_NAME = "ejb-3.2-active-timers-two";
@Deployment
public static Archive createDeployment() {
final JavaArchive ejbJarOne = ShrinkWrap.create(JavaArchive.class, MODULE_ONE_NAME + ".jar");
ejbJarOne.addClasses(ActiveTimerServiceCountTestCase.class, SimpleTimerBean.class, OtherTimerBeanInSameModule.class, StatefulBean.class);
final JavaArchive ejbJarTwo = ShrinkWrap.create(JavaArchive.class, MODULE_TWO_NAME + ".jar");
ejbJarTwo.addClasses(TimerBeanInOtherModule.class);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
ear.addAsModules(ejbJarOne, ejbJarTwo);
return ear;
}
/**
* Tests that the {@link jakarta.ejb.TimerService#getAllTimers()} API introduced in EJB 3.2 works as expected
*
* @throws Exception
*/
@Test
public void testActiveTimersCountInEJBModule() throws Exception {
final SimpleTimerBean timerBean = InitialContext.doLookup("java:module/" + SimpleTimerBean.class.getSimpleName() + "!" + SimpleTimerBean.class.getName());
final String infoOne = "gangnam style";
timerBean.createTimerForNextDay(false, infoOne);
final String infoTwo = "PSY";
timerBean.createTimerForNextDay(true, infoTwo);
final OtherTimerBeanInSameModule otherTimerBean = InitialContext.doLookup("java:module/" + OtherTimerBeanInSameModule.class.getSimpleName() + "!" + OtherTimerBeanInSameModule.class.getName());
final String infoThree = "hello world!";
otherTimerBean.createTimerForNextDay(false, infoThree);
final TimerBeanInOtherModule timerBeanInOtherModule = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_TWO_NAME + "/" + TimerBeanInOtherModule.class.getSimpleName() + "!" + TimerBeanInOtherModule.class.getName());
final String infoForTimerBeanInOtherModule = "irrelevant";
timerBeanInOtherModule.createTimerForNextDay(false, infoForTimerBeanInOtherModule);
final Collection<Timer> activeTimers = new ArrayList<>(timerBean.getAllActiveTimersInEJBModule());
// now start testing
Assert.assertFalse("No active timers found in EJB module " + MODULE_ONE_NAME, activeTimers.isEmpty());
// now make sure that the active timers are indeed the one we expected
Assert.assertTrue("@Schedule timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers", this.removeScheduleOneTimerOfSimpleTimerBean(activeTimers));
Assert.assertTrue("@Schedule timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers", this.removeScheduleTwoTimerOfSimpleTimerBean(activeTimers));
Assert.assertTrue("@Schedule timer on " + OtherTimerBeanInSameModule.class.getSimpleName() + " not found in active timers", this.removeSheduleOneTimerOfOtherTimerBean(activeTimers));
Assert.assertTrue("Programmatic timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers", this.removeProgramaticTimer(activeTimers, infoOne, false));
Assert.assertTrue("Programmatic timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers", this.removeProgramaticTimer(activeTimers, infoTwo, true));
Assert.assertTrue("Programmatic timer on " + OtherTimerBeanInSameModule.class.getSimpleName() + " not found in active timers", this.removeProgramaticTimer(activeTimers, infoThree, false));
// make sure there isn't an unexpected timer in the active timers
for (final Timer remainingTimer : activeTimers) {
Assert.assertNotEquals("Unexpectedly found a timer from other EJB module " + MODULE_TWO_NAME, TimerBeanInOtherModule.SCHEDULE_ONE_INFO.equals(remainingTimer.getInfo()));
Assert.assertNotEquals("Unexpectedly found a timer from other EJB module " + MODULE_TWO_NAME, infoForTimerBeanInOtherModule.equals(remainingTimer.getInfo()));
}
// Now fetch the same info, this time from the SFSB. We expect the same number of active timers in the module.
final StatefulBean statefulBean = InitialContext.doLookup("java:module/" + StatefulBean.class.getSimpleName() + "!" + StatefulBean.class.getName());
final Collection<Timer> activeTimersReturnedFromSFSB = new ArrayList<>(statefulBean.getAllActiveTimersInEJBModule());
Assert.assertFalse("No active timers found in EJB module " + MODULE_ONE_NAME + " when queried from a stateful bean", activeTimersReturnedFromSFSB.isEmpty());
// now make sure that the active timers are indeed the one we expected
Assert.assertTrue("@Schedule timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeScheduleOneTimerOfSimpleTimerBean(activeTimersReturnedFromSFSB));
Assert.assertTrue("@Schedule timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeScheduleTwoTimerOfSimpleTimerBean(activeTimersReturnedFromSFSB));
Assert.assertTrue("@Schedule timer on " + OtherTimerBeanInSameModule.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeSheduleOneTimerOfOtherTimerBean(activeTimersReturnedFromSFSB));
Assert.assertTrue("Programmatic timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeProgramaticTimer(activeTimersReturnedFromSFSB, infoOne, false));
Assert.assertTrue("Programmatic timer on " + SimpleTimerBean.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeProgramaticTimer(activeTimersReturnedFromSFSB, infoTwo, true));
Assert.assertTrue("Programmatic timer on " + OtherTimerBeanInSameModule.class.getSimpleName() + " not found in active timers when queried from a stateful bean", this.removeProgramaticTimer(activeTimersReturnedFromSFSB, infoThree, false));
// make sure there isn't an unexpected timer in the active timers
for (final Timer remainingTimer : activeTimersReturnedFromSFSB) {
Assert.assertNotEquals("Unexpectedly found a timer from other EJB module " + MODULE_TWO_NAME + " when queried from a stateful bean", TimerBeanInOtherModule.SCHEDULE_ONE_INFO.equals(remainingTimer.getInfo()));
Assert.assertNotEquals("Unexpectedly found a timer from other EJB module " + MODULE_TWO_NAME + " when queried from a stateful bean", infoForTimerBeanInOtherModule.equals(remainingTimer.getInfo()));
}
}
private boolean removeScheduleOneTimerOfSimpleTimerBean(final Collection<Timer> timers) {
for (final Timer activeTimer : timers) {
// see if it's @Schedule one in SimpleTimerBean
final Serializable info = activeTimer.getInfo();
if (SimpleTimerBean.SCHEDULE_ONE_INFO.equals(info)) {
Assert.assertTrue("Unexpected timer type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isCalendarTimer());
Assert.assertFalse("Unexpected persistence type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
private boolean removeScheduleTwoTimerOfSimpleTimerBean(final Collection<Timer> timers) {
for (final Timer activeTimer : timers) {
// see if it's @Schedule two in SimpleTimerBean
final Serializable info = activeTimer.getInfo();
if (SimpleTimerBean.SCHEDULE_TWO_INFO.equals(info)) {
Assert.assertTrue("Unexpected timer type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isCalendarTimer());
Assert.assertTrue("Unexpected persistence type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
private boolean removeSheduleOneTimerOfOtherTimerBean(final Collection<Timer> timers) {
for (final Timer activeTimer : timers) {
// see if it's @Schedule one in OtherTimerBeanInSameModule
final Serializable info = activeTimer.getInfo();
if (OtherTimerBeanInSameModule.SCHEDULE_ONE_INFO.equals(info)) {
Assert.assertTrue("Unexpected timer type of timer on " + OtherTimerBeanInSameModule.class.getSimpleName(), activeTimer.isCalendarTimer());
Assert.assertFalse("Unexpected persistence type of timer on " + OtherTimerBeanInSameModule.class.getSimpleName(), activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
private boolean removeProgramaticTimer(final Collection<Timer> timers, final String timerInfo, final boolean persistent) {
for (final Timer activeTimer : timers) {
// see if it's the programatic timer we are looking for
final Serializable info = activeTimer.getInfo();
if (timerInfo.equals(info)) {
Assert.assertFalse("Unexpected timer type of timer", activeTimer.isCalendarTimer());
Assert.assertEquals("Unexpected persistence type of timer", persistent, activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
}
| 10,759 | 63.819277 | 246 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/count/TimerBeanInOtherModule.java
|
package org.jboss.as.test.integration.ejb.timerservice.count;
import org.jboss.logging.Logger;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import java.util.Date;
/**
* @author: Jaikiran Pai
*/
@Stateless
@LocalBean
public class TimerBeanInOtherModule {
static final String SCHEDULE_ONE_INFO = "foo-bar";
private static final Logger logger = Logger.getLogger(TimerBeanInOtherModule.class);
@Resource
private TimerService timerService;
@Schedule(second="*", minute = "*", hour = "*", persistent = false, info = SCHEDULE_ONE_INFO)
private void scheduleOne(final Timer timer) {
}
public void createTimerForNextDay(final boolean persistent, final String info) {
this.timerService.createSingleActionTimer(new Date(System.currentTimeMillis() + (60 * 60 * 24 * 1000)), new TimerConfig(info, persistent));
logger.trace("Created a timer persistent = " + persistent + " info = " + info);
}
}
| 1,114 | 29.972222 | 147 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/count/OtherTimerBeanInSameModule.java
|
package org.jboss.as.test.integration.ejb.timerservice.count;
import org.jboss.logging.Logger;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import java.util.Date;
/**
* @author: Jaikiran Pai
*/
@Stateless
@LocalBean
public class OtherTimerBeanInSameModule {
static final String SCHEDULE_ONE_INFO = "foo-bar";
private static final Logger logger = Logger.getLogger(OtherTimerBeanInSameModule.class);
@Resource
private TimerService timerService;
@Schedule(second="*", minute = "*", hour = "*", year = "2100", persistent = false, info = SCHEDULE_ONE_INFO)
private void scheduleOne(final Timer timer) {
}
public void createTimerForNextDay(final boolean persistent, final String info) {
this.timerService.createSingleActionTimer(new Date(System.currentTimeMillis() + (60 * 60 * 24 * 1000)) , new TimerConfig(info, persistent));
logger.trace("Created a timer persistent = " + persistent + " info = " + info);
}
}
| 1,139 | 29.810811 | 148 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/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.persistence;
import jakarta.annotation.Resource;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* @author Stuart Douglas
*/
@Singleton
public class CalendarTimerServiceBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
static final String MESSAGE = "Hello";
private static volatile String message = null;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createCalendarTimer(new ScheduleExpression().second("*").minute("*").hour("*").dayOfMonth("*").year("*"), new TimerConfig(MESSAGE, true));
}
@Timeout
public void timeout(Timer timer) {
message = (String) timer.getInfo();
latch.countDown();
}
public static String awaitTimerCall() {
try {
//on a slow machine this may take a while
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return message;
}
}
| 2,392 | 32.236111 | 159 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/TimerServicePersistenceSecondTestCase.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.persistence;
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;
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 TimerServicePersistenceSecondTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, TimerServicePersistenceFirstTestCase.ARCHIVE_NAME);
war.addPackage(TimerServicePersistenceSecondTestCase.class.getPackage());
return war;
}
/**
* The timer should be restored and the method should timeout, even without setting up the timer in this deployment
*/
@Test
public void testTimerServiceCalled() throws NamingException {
Assert.assertTrue(SimpleTimerServiceBean.awaitTimerCall());
}
/**
* The timer should not be restored, as it was cancelled
*/
@Test
public void testTimerServiceNotCalled() throws NamingException {
Assert.assertFalse(CancelledTimerServiceBean.quickAwaitTimerCall());
}
/**
* The timer should not be restored, it was non-persistent one
*/
@Test
public void testTimerServiceNonPersistent() throws NamingException {
Assert.assertFalse(NonPersistentTimerServiceBean.quickAwaitTimerCall());
}
@Test
public void testPersistentCalendarTimer() throws NamingException {
Assert.assertEquals(CalendarTimerServiceBean.MESSAGE, CalendarTimerServiceBean.awaitTimerCall());
}
}
| 2,907 | 35.35 | 119 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/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.persistence;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Singleton
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;
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_INIT_TIME_MS, TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
//on a slow machine this may take a while
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,290 | 32.202899 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/NonPersistentTimerServiceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, 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.persistence;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
/**
* @author Ondrej Chaloupka
*/
@Singleton
public class NonPersistentTimerServiceBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_QUICK_WAITING_S = 2;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createIntervalTimer(100, 100, timerConfig);
}
@Timeout
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean quickAwaitTimerCall() {
try {
latch.await(TIMER_CALL_QUICK_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,257 | 31.724638 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/TimerServicePersistenceFirstTestCase.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.persistence;
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.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Two phase test for timer serialization. This test case creates a persistent timer, and the second phase restores it.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServicePersistenceFirstTestCase {
/**
* must match between the two tests.
*/
public static final String ARCHIVE_NAME = "testTimerServicePersistence.war";
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME);
war.addPackage(TimerServicePersistenceFirstTestCase.class.getPackage());
return war;
}
@Test
public void testSimplePersistentTimer() throws NamingException {
InitialContext ctx = new InitialContext();
SimpleTimerServiceBean bean = (SimpleTimerServiceBean)ctx.lookup("java:module/" + SimpleTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(SimpleTimerServiceBean.awaitTimerCall());
}
@Test
public void testPersistentCalendarTimer() throws NamingException {
InitialContext ctx = new InitialContext();
CalendarTimerServiceBean bean = (CalendarTimerServiceBean)ctx.lookup("java:module/" + CalendarTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertEquals(CalendarTimerServiceBean.MESSAGE, CalendarTimerServiceBean.awaitTimerCall());
}
@Test
public void createAndCancelTimerService() throws NamingException {
InitialContext ctx = new InitialContext();
CancelledTimerServiceBean bean = (CancelledTimerServiceBean)ctx.lookup("java:module/" + CancelledTimerServiceBean.class.getSimpleName());
TimerHandle handle = bean.createTimer();
Assert.assertTrue(CancelledTimerServiceBean.awaitTimerCall());
Assert.assertEquals("info", handle.getTimer().getInfo());
handle.getTimer().cancel();
}
@Test
public void createNonPersistentTimer() throws NamingException {
InitialContext ctx = new InitialContext();
NonPersistentTimerServiceBean bean = (NonPersistentTimerServiceBean)ctx.lookup("java:module/" + NonPersistentTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(NonPersistentTimerServiceBean.quickAwaitTimerCall());
}
}
| 3,833 | 39.787234 | 157 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/CancelledTimerServiceBean.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.persistence;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerHandle;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Singleton
public class CancelledTimerServiceBean {
private static final CountDownLatch latch = new CountDownLatch(1);
private static final int TIMER_CALL_WAITING_S = 30;
private static final int TIMER_CALL_QUICK_WAITING_S = 2;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public TimerHandle createTimer() {
ScheduleExpression expression = new ScheduleExpression();
expression.second("*");
expression.minute("*");
expression.hour("*");
expression.dayOfMonth("*");
expression.year("*");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(new String("info"));
return timerService.createCalendarTimer(expression, timerConfig).getHandle();
}
@Timeout
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
//on a slow machine this may take a while
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
public static boolean quickAwaitTimerCall() {
try {
latch.await(TIMER_CALL_QUICK_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,955 | 32.590909 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/legacy/LegacyTimerFormatTestCase.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.persistence.legacy;
import java.io.File;
import java.io.InputStream;
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.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.FileUtils;
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 the old non-xml class based serialization format can still be read
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@ServerSetup(LegacyTimerFormatTestCase.LegacyTimerFormatTestCaseSetup.class)
public class LegacyTimerFormatTestCase {
private static final String TIMER_LOCATION = "standalone/data/timer-service-data/leagacy-timer-persistence.leagacy-timer-persistence.LegacyTimerServiceBean/9ec70618-f985-420d-807a-364a2bcb1a81";
public static class LegacyTimerFormatTestCaseSetup implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
String home = System.getProperty("jboss.home");
File target = new File(home, TIMER_LOCATION);
InputStream in = LegacyTimerFormatTestCase.class.getResourceAsStream("legacy-timer-data");
try {
FileUtils.copyFile(in, target);
} finally {
in.close();
}
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
}
}
/**
* must match between the two tests.
*/
public static final String ARCHIVE_NAME = "leagacy-timer-persistence.war";
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME);
war.addPackage(LegacyTimerFormatTestCase.class.getPackage());
return war;
}
@Test
public void createTimerService() throws NamingException {
Assert.assertTrue(LegacyTimerServiceBean.awaitTimerCall());
}
}
| 3,394 | 36.307692 | 198 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/persistence/legacy/LegacyTimerServiceBean.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.persistence.legacy;
import jakarta.annotation.Resource;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* @author Stuart Douglas
*/
@Singleton
public class LegacyTimerServiceBean {
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;
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_INIT_TIME_MS, TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
//on a slow machine this may take a while
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
}
| 2,296 | 32.779412 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/view/LocalInterface.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.view;
import jakarta.ejb.Local;
/**
* @author Stuart Douglas
*/
@Local
public interface LocalInterface {
void createTimer();
}
| 1,207 | 34.529412 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/view/ViewTimerServiceTestCase.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.view;
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;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that an @Timeout method works when it is not part of any bean views
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class ViewTimerServiceTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceView.war");
war.addPackage(ViewTimerServiceTestCase.class.getPackage());
return war;
}
@Test
public void testAnnotationTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
LocalInterface bean = (LocalInterface) ctx.lookup("java:module/" + AnnotationTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(AnnotationTimerServiceBean.awaitTimerCall());
}
@Test
public void testTimedObjectTimeoutMethod() throws NamingException {
InitialContext ctx = new InitialContext();
LocalInterface bean = (LocalInterface) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
bean.createTimer();
Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
}
}
| 2,640 | 36.728571 | 126 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/view/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.view;
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;
/**
* @author Stuart Douglas
*/
@Stateless
public class AnnotationTimerServiceBean implements LocalInterface {
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 boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
@Timeout
private 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;
}
}
| 2,185 | 31.626866 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/view/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.view;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
@Local(LocalInterface.class)
public class TimedObjectTimerServiceBean implements TimedObject, LocalInterface {
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 boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_TIMEOUT_TIME_MS, null);
}
public static boolean awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
@Override
public void ejbTimeout(final Timer timer) {
timerServiceCalled = true;
latch.countDown();
}
}
| 2,303 | 32.391304 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/suspend/TimerServiceSuspendTestCase.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.suspend;
import java.io.FilePermission;
import java.io.IOException;
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.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.dmr.ModelNode;
import org.jboss.remoting3.security.RemotingPermission;
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;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Tests suspend/resume for non-calendar based timers
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServiceSuspendTestCase {
@ArquillianResource
private ManagementClient managementClient;
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceSimple.war");
war.addPackage(TimerServiceSuspendTestCase.class.getPackage());
war.addAsManifestResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller-client, org.jboss.remoting\n"), "MANIFEST.MF");
war.addAsManifestResource(createPermissionsXmlAsset(
new RemotingPermission("createEndpoint"),
new RemotingPermission("connect"),
new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")
), "permissions.xml");
return war;
}
@Test
public void testSuspendWithIntervalTimer() throws NamingException, IOException, InterruptedException {
SuspendTimerServiceBean.resetTimerServiceCalled();
InitialContext ctx = new InitialContext();
SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
ModelNode op = new ModelNode();
Timer timer = null;
try {
try {
timer = bean.getTimerService().createIntervalTimer(100, 100, new TimerConfig("", false));
Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
SuspendTimerServiceBean.resetTimerServiceCalled();
Thread.sleep(200);
Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
} finally {
if (timer != null) {
timer.cancel();
Thread.sleep(100);
}
}
}
/**
* This test makes sure that interval timers that are scheduled while a timer is suspended do not back up, and only a single
* run will occur when the container is resumed
*/
@Test
public void testIntervalTimersDoNotBackUp() throws NamingException, IOException, InterruptedException {
SuspendTimerServiceBean.resetTimerServiceCalled();
InitialContext ctx = new InitialContext();
SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
Timer timer = null;
try {
long start = 0;
ModelNode op = new ModelNode();
try {
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
//create the timer while the container is suspended
start = System.currentTimeMillis();
timer = bean.getTimerService().createIntervalTimer(100, 100, new TimerConfig("", false));
Thread.sleep(5000);
Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
Thread.sleep(300); //if they were backed up we give them some time to run
int timerServiceCount = SuspendTimerServiceBean.getTimerServiceCount();
Assert.assertTrue("Interval " + (System.currentTimeMillis() - start) + " count " + timerServiceCount, timerServiceCount < 40);
} finally {
if (timer != null) {
timer.cancel();
Thread.sleep(100);
}
}
}
/**
* Tests that a single action timer that executes when the container is suspended will run as normal once it is resumed
*/
@Test
public void testSingleActionTimerWhenSuspended() throws NamingException, IOException, InterruptedException {
SuspendTimerServiceBean.resetTimerServiceCalled();
InitialContext ctx = new InitialContext();
SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
Timer timer = null;
try {
long start = 0;
ModelNode op = new ModelNode();
try {
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
//create the timer while the container is suspended
start = System.currentTimeMillis();
timer = bean.getTimerService().createSingleActionTimer(1, new TimerConfig("", false));
Thread.sleep(1000);
Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
Assert.assertEquals(1, SuspendTimerServiceBean.awaitTimerServiceCount());
} finally {
if (timer != null) {
try {
timer.cancel();
Thread.sleep(100);
} catch(Exception e) {
//as the timer has already expired this may throw an exception
}
}
}
}
}
| 8,031 | 40.833333 | 151 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/suspend/SuspendTimerServiceBean.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.suspend;
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 SuspendTimerServiceBean {
private static final Logger log = Logger.getLogger(SuspendTimerServiceBean.class);
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static volatile int timerServiceCount = 0;
private static final int TIMER_CALL_WAITING_S = 30;
private static volatile String timerInfo;
@Resource
private SessionContext sessionContext;
private TimerService timerService;
public synchronized TimerService getTimerService() {
if(timerService == null) {
timerService = (TimerService) sessionContext.lookup("java:comp/TimerService");
}
return timerService;
}
public static void resetTimerServiceCalled() {
timerServiceCount = 0;
latch = new CountDownLatch(1);
}
public String getTimerInfo() {
return timerInfo;
}
@Timeout
public synchronized void timeout(Timer timer) {
log.trace("Timer is: " + timer + ", timer info is: " + timer.getInfo());
timerInfo = (String) timer.getInfo();
timerServiceCount++;
latch.countDown();
}
public static int awaitTimerServiceCount() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCount;
}
public static int getTimerServiceCount() {
return timerServiceCount;
}
}
| 2,924 | 31.142857 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/InfoB.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.serialization;
import java.io.Serializable;
/**
* @author Stuart Douglas
*/
public class InfoB implements Serializable {
public InfoC infoC = new InfoC();
}
| 1,236 | 37.65625 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/TimerServiceSerializationFirstTestCase.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.serialization;
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.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
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;
/**
* Two phase test for timer serialization. This test serializes a class in the info field where there does not exist a single
* module class loader that has access to every class in the serialized object graph.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class TimerServiceSerializationFirstTestCase {
/**
* must match between the two tests.
*/
public static final String ARCHIVE_NAME = "testTimerServiceSerialization.ear";
@Deployment
public static Archive<?> deploy() {
return createTestArchive(TimerServiceSerializationFirstTestCase.class);
}
public static Archive<?> createTestArchive(Class<?> testClass) {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, ARCHIVE_NAME);
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "a.jar");
jar.addClasses(InfoA.class, TimerServiceSerializationBean.class, testClass);
jar.addAsManifestResource(new StringAsset("Class-Path: b.jar \n"), "MANIFEST.MF");
ear.addAsModule(jar);
jar = ShrinkWrap.create(JavaArchive.class, "b.jar");
jar.addClasses(InfoB.class);
jar.addAsManifestResource(new StringAsset("Class-Path: c.jar \n"), "MANIFEST.MF");
jar.addAsManifestResource(new StringAsset(EJB_JAR), "ejb-jar.xml");
ear.addAsModule(jar);
jar = ShrinkWrap.create(JavaArchive.class, "c.jar");
jar.addClasses(InfoC.class);
jar.addAsManifestResource(new StringAsset(EJB_JAR), "ejb-jar.xml");
ear.addAsModule(jar);
ear.addAsManifestResource(new StringAsset(
"<jboss-deployment-structure><ear-subdeployments-isolated>true</ear-subdeployments-isolated></jboss-deployment-structure>"),
"jboss-deployment-structure.xml");
return ear;
}
@Test
public void testCreateTimerWithInfo() throws NamingException {
InitialContext ctx = new InitialContext();
TimerServiceSerializationBean bean = (TimerServiceSerializationBean) ctx.lookup("java:module/" + TimerServiceSerializationBean.class.getSimpleName());
bean.createTimer();
InfoA info = TimerServiceSerializationBean.awaitTimerCall();
Assert.assertNotNull(info);
Assert.assertNotNull(info.infoB);
Assert.assertNotNull(info.infoB.infoC);
}
public static final String EJB_JAR = "<ejb-jar xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd\"\n" +
" version=\"3.1\">\n" +
"</ejb-jar>";
}
| 4,325 | 41.411765 | 158 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/InfoA.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.serialization;
import java.io.Serializable;
/**
* @author Stuart Douglas
*/
public class InfoA implements Serializable{
public InfoB infoB = new InfoB();
}
| 1,236 | 36.484848 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/TimerServiceSerializationSecondTestCase.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.serialization;
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.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 TimerServiceSerializationSecondTestCase {
@Deployment
public static Archive<?> deploy() {
return TimerServiceSerializationFirstTestCase.createTestArchive(TimerServiceSerializationSecondTestCase.class);
}
/**
* The timer should be restored and the method should timeout, even without setting up the timer in this deployment
*/
@Test
public void testTimerServiceRestoredWithCorrectInfo() throws NamingException {
InitialContext ctx = new InitialContext();
TimerServiceSerializationBean bean = (TimerServiceSerializationBean) ctx.lookup("java:module/" + TimerServiceSerializationBean.class.getSimpleName());
InfoA info = TimerServiceSerializationBean.awaitTimerCall();
Assert.assertNotNull(info);
Assert.assertNotNull(info.infoB);
Assert.assertNotNull(info.infoB.infoC);
}
}
| 2,420 | 37.428571 | 158 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/TimerServiceSerializationBean.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.serialization;
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.Timer;
import jakarta.ejb.TimerService;
/**
* @author Stuart Douglas
*/
@Stateless
public class TimerServiceSerializationBean {
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_WAITING_S = 30;
private static volatile InfoA info;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(TIMER_INIT_TIME_MS, TIMER_TIMEOUT_TIME_MS, new InfoA());
}
@Timeout
public void timeout(Timer timer) {
info = (InfoA) timer.getInfo();
latch.countDown();
}
public static InfoA awaitTimerCall() {
try {
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return info;
}
}
| 2,320 | 32.157143 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/timerservice/serialization/InfoC.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.serialization;
import java.io.Serializable;
/**
* @author Stuart Douglas
*/
public class InfoC implements Serializable {
}
| 1,198 | 37.677419 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/compression/CompressableDataBean.java
|
package org.jboss.as.test.integration.ejb.compression;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author: Jaikiran Pai
*/
@Stateless
@Remote(MethodOverrideDataCompressionRemoteView.class)
public class CompressableDataBean implements MethodOverrideDataCompressionRemoteView {
@Override
public String echoWithRequestCompress(String msg) {
return msg;
}
@Override
public String echoWithNoExplicitDataCompressionHintOnMethod(String msg) {
return msg;
}
@Override
public String echoWithResponseCompress(String msg) {
return msg;
}
}
| 617 | 20.310345 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/compression/CompressionTestCase.java
|
package org.jboss.as.test.integration.ejb.compression;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
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.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;
/**
* Tests that the {@link org.jboss.ejb.client.annotation.CompressionHint} on remote view classes and the view methods is taken into account during EJB invocations
*
* @author: Jaikiran Pai
* @see https://issues.jboss.org/browse/EJBCLIENT-76
*/
@RunWith(Arquillian.class)
@RunAsClient
public class CompressionTestCase {
private static final String MODULE_NAME = "ejb-invocation-compression-test";
@Deployment
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(CompressionTestCase.class.getPackage());
return jar;
}
/**
* Tests that EJB invocations that are marked with a compression hint can be invoked without any problems. This test doesn't actually poke in to verify if the data
* was actually compressed, because that's supposed to be transparent to the bean. All this test does is to make sure that when the hint is in place, the invocations can pass.
*
* @throws Exception
*/
@Test
public void testCompressedInvocation() throws Exception {
// set the system property which enables annotation scan on the client view
System.setProperty("org.jboss.ejb.client.view.annotation.scan.enabled", "true");
try {
// create a proxy for invocation
final Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiCtx = new InitialContext(props);
final MethodOverrideDataCompressionRemoteView bean = (MethodOverrideDataCompressionRemoteView) jndiCtx.lookup("ejb:" + "" + "/" + MODULE_NAME + "/" + "" + "/" + CompressableDataBean.class.getSimpleName() + "!" + MethodOverrideDataCompressionRemoteView.class.getName());
final String message = "some message";
// only request compression
final String echoWithRequestCompressed = bean.echoWithRequestCompress(message);
Assert.assertEquals("Unexpected response for invocation with only request compressed", message, echoWithRequestCompressed);
// only response compressed
final String echoWithResponseCompressed = bean.echoWithResponseCompress(message);
Assert.assertEquals("Unexpected response for invocation with only response compressed", message, echoWithResponseCompressed);
// both request and response compressed based on the annotation at the view class level
final String echoWithRequestAndResponseCompressed = bean.echoWithNoExplicitDataCompressionHintOnMethod(message);
Assert.assertEquals("Unexpected response for invocation with both request and response compressed", message, echoWithRequestAndResponseCompressed);
} finally {
// remove the system property which enables annotation scan on the client view
System.getProperties().remove("org.jboss.ejb.client.view.annotation.scan.enabled");
}
}
}
| 3,574 | 48.652778 | 281 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/compression/MethodOverrideDataCompressionRemoteView.java
|
package org.jboss.as.test.integration.ejb.compression;
import org.jboss.ejb.client.annotation.CompressionHint;
/**
* @author: Jaikiran Pai
*/
@CompressionHint
public interface MethodOverrideDataCompressionRemoteView {
@CompressionHint(compressRequest = false)
String echoWithResponseCompress(final String msg);
@CompressionHint(compressResponse = false)
String echoWithRequestCompress(final String msg);
String echoWithNoExplicitDataCompressionHintOnMethod(String msg);
}
| 500 | 24.05 | 69 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/EjbJarRuntimeResourcesTestCase.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.management.deployments;
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.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.runner.RunWith;
/**
* Tests management resources exposed by EJBs in a root-level jar deployment.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EjbJarRuntimeResourcesTestCase extends EjbJarRuntimeResourceTestBase {
static final PathAddress BASE_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, JAR_NAME));
@Deployment
public static Archive<?> deploy() {
return getEJBJar();
}
public EjbJarRuntimeResourcesTestCase() {
super(BASE_ADDRESS);
}
}
| 2,071 | 37.37037 | 141 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/ManagedMDB.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import jakarta.ejb.Schedule;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.jms.JMSDestinationDefinition;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Bean to use in tests of management resources for MDBs.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@JMSDestinationDefinition(
name="java:/queue/ManagedMDB-queue",
interfaceName = "jakarta.jms.Queue"
)
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/queue/ManagedMDB-queue")
})
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
public class ManagedMDB implements MessageListener {
@Override
public void onMessage(Message message) {
// no-op
}
@Timeout
@Schedule(second="15", persistent = false, info = "timer1")
public void timeout(final Timer timer) {
// no-op
}
}
| 2,375 | 33.941176 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/EjbJarRuntimeResourceTestBase.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.management.deployments;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTRIBUTES;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.MESSAGE_DRIVEN;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.SINGLETON;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.STATEFUL;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.STATELESS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.List;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.TransactionManagementType;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
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.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
/**
* Base class for tests of management resources exposed by runtime EJB components.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class EjbJarRuntimeResourceTestBase {
protected static final String SECURITY_DOMAIN = "security-domain";
protected static final String MODULE_NAME = "ejb-management";
protected static final String JAR_NAME = MODULE_NAME + ".jar";
private static final String COMPONENT_CLASS_NAME = "component-class-name";
private static final String DECLARED_ROLES = "declared-roles";
private static final String POOL_NAME = "pool-name";
private static final String RUN_AS_ROLE = "run-as-role";
private static final String TIMER_ATTRIBUTE = "timers";
private static final String[] POOL_ATTRIBUTES =
{"pool-available-count", "pool-create-count", "pool-current-size", POOL_NAME, "pool-max-size", "pool-remove-count"};
private static final String[] TIMER_ATTRIBUTES = {"time-remaining", "next-timeout", "calendar-timer"};
private static final String[] SCHEDULE_ATTRIBUTES = {"day-of-month", "day-of-week", "hour", "minute", "year", "timezone", "start", "end"};
private static final String JNDI_NAMES = "jndi-names";
private static final String BUSINESS_LOCAL = "business-local";
private static final String BUSINESS_REMOTE = "business-remote";
private static final String TIMEOUT_METHOD = "timeout-method";
private static final String ASYNC_METHODS = "async-methods";
private static final String TRANSACTION_TYPE = "transaction-type";
// MDB specific resource names
private static final String ACTIVATION_CONFIG = "activation-config";
private static final String MESSAGING_TYPE = "messaging-type";
private static final String MESSAGE_DESTINATION_TYPE = "message-destination-type";
private static final String MESSAGE_DESTINATION_LINK = "message-destination-link";
// STATEFUL specific resource names
private static final String STATEFUL_TIMEOUT = "stateful-timeout";
private static final String AFTER_BEGIN_METHOD = "after-begin-method";
private static final String BEFORE_COMPLETION_METHOD = "before-completion-method";
private static final String AFTER_COMPLETION_METHOD = "after-completion-method";
private static final String PASSIVATION_CAPABLE = "passivation-capable";
private static final String REMOVE_METHODS = "remove-methods";
private static final String RETAIN_IF_EXCEPTION = "retain-if-exception";
private static final String BEAN_METHOD = "bean-method";
// SINGLETON specific resource names
private static final String DEPENDS_ON = "depends-on";
private static final String INIT_ON_STARTUP = "init-on-startup";
private static final String CONCURRENCY_MANAGEMENT_TYPE = "concurrency-management-type";
@ContainerResource
private ManagementClient managementClient;
public static Archive<?> getEJBJar() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, JAR_NAME);
jar.addPackage(EjbJarRuntimeResourcesTestCase.class.getPackage());
jar.addClass(TimeoutUtil.class);
jar.addAsManifestResource(EjbJarRuntimeResourcesTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addAsManifestResource(EjbJarRuntimeResourcesTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
private final PathAddress baseAddress;
protected EjbJarRuntimeResourceTestBase(final PathAddress baseAddress) {
this.baseAddress = baseAddress;
}
@Test
public void testMDB() throws Exception {
testComponent(MESSAGE_DRIVEN, ManagedMDB.class.getSimpleName(), true);
}
@Test
public void testNoTimerMDB() throws Exception {
testComponent(MESSAGE_DRIVEN, NoTimerMDB.class.getSimpleName(), false);
}
@Test
public void testSLSB() throws Exception {
testComponent(STATELESS, ManagedStatelessBean.class.getSimpleName(), true);
}
@Test
public void testNoTimerSLSB() throws Exception {
testComponent(STATELESS, NoTimerStatelessBean.class.getSimpleName(), false);
}
@Test
public void testSingleton() throws Exception {
testComponent(SINGLETON, ManagedSingletonBean.class.getSimpleName(), true);
}
@Test
public void testNoTimerSingleton() throws Exception {
testComponent(SINGLETON, NoTimerSingletonBean.class.getSimpleName(), false);
}
@Test
public void testSFSB() throws Exception {
testComponent(STATEFUL, ManagedStatefulBean.class.getSimpleName(), false);
}
/*
TODO implement a test of entity beans
@Test
public void testEntityBean() throws Exception {
testComponent(ENTITY, ???.class.getSimpleName());
}
*/
private void testComponent(String type, String name, boolean expectTimer) throws Exception {
ModelNode address = getComponentAddress(type, name).toModelNode();
address.protect();
ModelNode resourceDescription = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_DESCRIPTION_OPERATION, address);
ModelNode resource = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertTrue(resourceDescription.get(ATTRIBUTES, COMPONENT_CLASS_NAME).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, COMPONENT_CLASS_NAME, DESCRIPTION).getType());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, COMPONENT_CLASS_NAME, TYPE).asType());
final ModelNode componentClassNameNode = resource.get(COMPONENT_CLASS_NAME);
assertTrue(componentClassNameNode.isDefined());
final String componentClassName = componentClassNameNode.asString();
validateSecurity(address, resourceDescription, resource);
if (!STATEFUL.equals(type) && !SINGLETON.equals(type)) {
validatePool(address, resourceDescription, resource);
} else {
for (String attr : POOL_ATTRIBUTES) {
assertFalse(resourceDescription.get(ModelDescriptionConstants.ATTRIBUTES).has(attr));
assertFalse(resource.has(attr));
}
}
if (STATELESS.equals(type) || SINGLETON.equals(type) || MESSAGE_DRIVEN.equals(type)) {
validateTimer(address, resourceDescription, resource, expectTimer);
assertEquals(TransactionManagementType.CONTAINER.name(), resource.get(TRANSACTION_TYPE).asString());
} else {
assertFalse(resourceDescription.get(ModelDescriptionConstants.ATTRIBUTES).has(TIMER_ATTRIBUTE));
assertFalse(resource.has(TIMER_ATTRIBUTE));
// stateful beans are configured to have bean managed transaction
assertEquals(TransactionManagementType.BEAN.name(), resource.get(TRANSACTION_TYPE).asString());
// STATEFUL specific resources
if (componentClassName.equals("org.jboss.as.test.integration.ejb.management.deployments.ManagedStatefulBean")) {
assertTrue(resource.get(PASSIVATION_CAPABLE).asBoolean());
assertFalse(resource.get(AFTER_BEGIN_METHOD).isDefined());
assertFalse(resource.get(BEFORE_COMPLETION_METHOD).isDefined());
assertFalse(resource.get(AFTER_COMPLETION_METHOD).isDefined());
} else {
assertFalse(resource.get(PASSIVATION_CAPABLE).asBoolean());
assertEquals("2 HOURS", resource.get(STATEFUL_TIMEOUT).asString());
assertEquals("private void afterBegin()", resource.get(AFTER_BEGIN_METHOD).asString());
assertEquals("private void beforeCompletion()", resource.get(BEFORE_COMPLETION_METHOD).asString());
assertEquals("private void afterCompletion()", resource.get(AFTER_COMPLETION_METHOD).asString());
final ModelNode removeMethodsNode = resource.get(REMOVE_METHODS);
final List<ModelNode> removeMethodsList = removeMethodsNode.asList();
// ManagedStatefulBean contains 1 remove method (inherited)
// ManagedStatefulBean2 declares 2 remove methods and inherit 1
assertTrue(removeMethodsList.size() == 1 || removeMethodsList.size() == 3);
for (ModelNode m : removeMethodsList) {
final String beanMethod = m.get(BEAN_METHOD).asString();
final boolean retainIfException = m.get(RETAIN_IF_EXCEPTION).asBoolean();
if (beanMethod.contains("void removeTrue()")) {
assertTrue(retainIfException);
} else if (beanMethod.contains("void removeFalse()") || beanMethod.contains("void remove()")) {
assertFalse(retainIfException);
} else {
fail("Unknown stateful bean remove method: " + beanMethod);
}
}
}
}
// SINGLETON specific resource
if (SINGLETON.equals(type)) {
final ModelNode concurrencyTypeNode = resource.get(CONCURRENCY_MANAGEMENT_TYPE);
final ModelNode initOnStartUpNode = resource.get(INIT_ON_STARTUP);
final ModelNode dependsOnNode = resource.get(DEPENDS_ON);
if (componentClassName.equals("org.jboss.as.test.integration.ejb.management.deployments.ManagedSingletonBean")) {
assertFalse(initOnStartUpNode.asBoolean());
assertFalse(dependsOnNode.isDefined());
assertFalse(concurrencyTypeNode.isDefined());
} else {
assertTrue(initOnStartUpNode.asBoolean());
assertEquals(ConcurrencyManagementType.BEAN.name(), concurrencyTypeNode.asString());
final List<ModelNode> dependsOnList = dependsOnNode.asList();
assertEquals(1, dependsOnList.size());
for (ModelNode d : dependsOnList) {
if (!d.asString().equals("ManagedSingletonBean")) {
fail("Unknown value of depends-on: " + d.asString());
}
}
}
}
// MDB specific resources
if (MESSAGE_DRIVEN.equals(type)) {
assertEquals("jakarta.jms.MessageListener", resource.get(MESSAGING_TYPE).asString());
if (componentClassName.equals("org.jboss.as.test.integration.ejb.management.deployments.NoTimerMDB")) {
assertEquals("jakarta.jms.Queue", resource.get(MESSAGE_DESTINATION_TYPE).asString());
assertEquals("queue/NoTimerMDB-queue", resource.get(MESSAGE_DESTINATION_LINK).asString());
}
final ModelNode activationConfigNode = resource.get(ACTIVATION_CONFIG);
assertTrue(activationConfigNode.isDefined());
final List<Property> activationConfigProps = activationConfigNode.asPropertyList();
assertTrue(activationConfigProps.size() >= 2);
for (Property p : activationConfigProps) {
final String pName = p.getName();
final String pValue = p.getValue().asString();
switch (pName) {
case "destinationType":
assertEquals("jakarta.jms.Queue", pValue);
break;
case "destination":
assertTrue(pValue.startsWith("java:/queue/"));
break;
case "acknowledgeMode":
assertEquals("Auto-acknowledge", pValue);
break;
default:
fail("Unknown activation config property: " + pName);
break;
}
}
} else {
// resources for stateless, stateful and singleton
if (expectTimer) {
// the @Asynchronous method is declared on the bean super class AbstractManagedBean
// Beans named NoTimer* do not extend AbstractManagedBean and so do not have async methods.
final ModelNode asyncMethodsNode = resource.get(ASYNC_METHODS);
final List<ModelNode> asyncMethodsList = asyncMethodsNode.asList();
assertEquals(1, asyncMethodsList.size());
for (ModelNode m : asyncMethodsList) {
if (!m.asString().contains("void async(int, int)")) {
fail("Unknown async methods: " + m.asString());
}
}
}
final ModelNode businessRemoteNode = resource.get(BUSINESS_REMOTE);
final List<ModelNode> businessRemoteList = businessRemoteNode.asList();
assertEquals(1, businessRemoteList.size());
for (ModelNode r : businessRemoteList) {
if (!r.asString().equals("org.jboss.as.test.integration.ejb.management.deployments.BusinessInterface")) {
fail("Unknown business remote interface: " + r.asString());
}
}
final ModelNode businessLocalNode = resource.get(BUSINESS_LOCAL);
final List<ModelNode> businessLocalList = businessLocalNode.asList();
assertEquals(1, businessLocalList.size());
for (ModelNode l : businessLocalList) {
if (!l.asString().equals(componentClassName)) {
fail("Unknown business local interface: " + l.asString());
}
}
final ModelNode jndiNamesNode = resource.get(JNDI_NAMES);
final List<ModelNode> jndiNamesList = jndiNamesNode.asList();
//each session bean has 2 business interfaces (remote and local), in
//3 scopes (global, app & module), plus jboss-specific names
assertTrue(jndiNamesList.size() >= 6);
for (ModelNode j : jndiNamesList) {
final String n = j.asString();
if (!(n.startsWith("java:global/") || n.startsWith("java:app/") || n.startsWith("java:module/")
|| n.startsWith("ejb:/") || n.startsWith("java:jboss/"))) {
fail("Unknown jndi name for " + name + ": " + n);
}
}
}
}
private void validateSecurity(ModelNode address, ModelNode resourceDescription, ModelNode resource) {
assertTrue(resourceDescription.get(ATTRIBUTES, SECURITY_DOMAIN).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, SECURITY_DOMAIN, DESCRIPTION).getType());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, SECURITY_DOMAIN, TYPE).asType());
assertTrue(resource.get(SECURITY_DOMAIN).isDefined());
assertEquals("other", resource.get(SECURITY_DOMAIN).asString());
assertTrue(resourceDescription.get(ATTRIBUTES, RUN_AS_ROLE).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, RUN_AS_ROLE, DESCRIPTION).getType());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, RUN_AS_ROLE, TYPE).asType());
assertTrue(resource.get(RUN_AS_ROLE).isDefined());
assertEquals("Role3", resource.get(RUN_AS_ROLE).asString());
assertTrue(resourceDescription.get(ATTRIBUTES, DECLARED_ROLES).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, DECLARED_ROLES, DESCRIPTION).getType());
assertEquals(ModelType.LIST, resourceDescription.get(ATTRIBUTES, DECLARED_ROLES, TYPE).asType());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, DECLARED_ROLES, VALUE_TYPE).asType());
assertTrue(resource.get(DECLARED_ROLES).isDefined());
assertEquals(ModelType.LIST, resource.get(DECLARED_ROLES).getType());
final List<ModelNode> roles = resource.get(DECLARED_ROLES).asList();
for (int i = 1; i < 4; i++) {
assertTrue(roles.contains(new ModelNode().set("Role" + i)));
}
assertEquals(3, roles.size());
}
private void validatePool(ModelNode address, ModelNode resourceDescription, ModelNode resource) {
for (String attr : POOL_ATTRIBUTES) {
final ModelType expectedType = POOL_NAME.equals(attr) ? ModelType.STRING : ModelType.INT;
assertTrue(resourceDescription.get(ATTRIBUTES, attr).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, attr, DESCRIPTION).getType());
assertEquals(expectedType, resourceDescription.get(ATTRIBUTES, attr, TYPE).asType());
assertTrue(attr + " is not defined", resource.get(attr).isDefined());
assertEquals(expectedType, resource.get(attr).getType());
}
}
private void validateTimer(ModelNode address, ModelNode resourceDescription, ModelNode resource, boolean expectTimer) {
assertTrue(resourceDescription.get(ATTRIBUTES, TIMER_ATTRIBUTE).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, TIMER_ATTRIBUTE, DESCRIPTION).getType());
assertEquals(ModelType.LIST, resourceDescription.get(ATTRIBUTES, TIMER_ATTRIBUTE, TYPE).asType());
assertEquals(ModelType.OBJECT, resourceDescription.get(ATTRIBUTES, TIMER_ATTRIBUTE, VALUE_TYPE).getType());
final ModelNode timerAttr = resource.get(TIMER_ATTRIBUTE);
assertTrue(timerAttr.isDefined());
final List<ModelNode> timers = timerAttr.asList();
if (!expectTimer) {
assertEquals(0, timers.size());
} else {
assertEquals(1, timers.size());
final ModelNode timer = timers.get(0);
assertTrue(timer.get("persistent").isDefined());
assertFalse(timer.get("persistent").asBoolean());
assertTrue(timer.get("schedule", "second").isDefined());
assertEquals("15", timer.get("schedule", "second").asString());
assertTrue(timer.get("info").isDefined());
assertEquals("timer1", timer.get("info").asString());
for (String field : TIMER_ATTRIBUTES) {
assertTrue(field, timer.has(field));
}
for (String field : SCHEDULE_ATTRIBUTES) {
assertTrue(field, timer.get("schedule").has(field));
}
}
if (expectTimer) {
assertTrue(resource.get(TIMEOUT_METHOD).asString().contains("timeout(jakarta.ejb.Timer)"));
}
}
static ModelNode execute(final ManagementClient managementClient, final ModelNode op) throws IOException {
ModelNode response = managementClient.getControllerClient().execute(op);
assertTrue(response.isDefined());
if (!Operations.isSuccessfulOutcome(response)) {
fail(Operations.getFailureDescription(response).asString());
}
return response.get(ModelDescriptionConstants.RESULT);
}
static ModelNode executeOperation(final ManagementClient managementClient, final String name, final ModelNode address) throws IOException {
final ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set(name);
op.get(ModelDescriptionConstants.OP_ADDR).set(address);
op.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true);
op.get(ModelDescriptionConstants.OPERATIONS).set(true);
return execute(managementClient, op);
}
static PathAddress componentAddress(final PathAddress baseAddress, final String type, final String name) {
return baseAddress.append(PathElement.pathElement(SUBSYSTEM, "ejb3")).append(PathElement.pathElement(type, name));
}
private PathAddress getComponentAddress(String type, String name) {
return componentAddress(this.baseAddress, type, name);
}
}
| 22,709 | 49.579065 | 147 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/NoTimerSingletonBean.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.DependsOn;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Bean to use in tests of management resources for EJB Singletons.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Singleton
@Startup
@DependsOn({"ManagedSingletonBean"})
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@LocalBean
public class NoTimerSingletonBean implements BusinessInterface {
@Override
public void doIt() {
// no-op;
}
@Override
public void remove() {
// no-op;
}
}
| 1,980 | 31.47541 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/WaitTimeSingletonBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, 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.management.deployments;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerConfig;
import jakarta.ejb.TimerService;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.logging.Logger;
@Singleton
@TransactionManagement(TransactionManagementType.BEAN)
@AccessTimeout(value = 10, unit = TimeUnit.SECONDS)
@Remote(BusinessInterface.class)
public class WaitTimeSingletonBean implements BusinessInterface {
private static final Logger logger = Logger.getLogger(WaitTimeSingletonBean.class);
private final AtomicInteger timerNumbers = new AtomicInteger();
@Resource
private TimerService timerService;
@Override
public void doIt() {
logger.info("Entering doIt method");
startTimer();
}
@Override
public void remove() {
for (Timer t : timerService.getTimers()) {
try {
t.cancel();
} catch (Exception ignore) {
}
}
}
@PostConstruct
private void postConstruct() {
startTimer();
logger.info("Finishing postConstruct method");
}
private void startTimer() {
final TimerConfig timerConfig = new TimerConfig("WaitTimeSingletonBean timer " + timerNumbers.getAndIncrement(), false);
timerService.createSingleActionTimer(1, timerConfig);
}
@Timeout
private void timeout(Timer timer) {
final Serializable info = timer.getInfo();
logger.info("Entering timeout method for " + info);
try {
Thread.sleep(TimeoutUtil.adjust(50));
} catch (InterruptedException e) {
Thread.interrupted();
}
logger.info("Finishing timeout method for " + info);
}
}
| 3,168 | 32.357895 | 128 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/ManagedSingletonBean.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.management.deployments;
import static jakarta.ejb.LockType.WRITE;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Lock;
import jakarta.ejb.Schedule;
import jakarta.ejb.Singleton;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* TBean to use in tests of management resources for EJB Singletons.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Singleton
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@Lock(WRITE)
@LocalBean
public class ManagedSingletonBean extends AbstractManagedBean implements BusinessInterface {
@Timeout
@Schedule(second="15", persistent = false, info = "timer1")
public void timeout(final Timer timer) {
// no-op
}
}
| 1,941 | 33.678571 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/EjbInvocationStatisticsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.management.deployments;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.test.integration.ejb.management.deployments.EjbJarRuntimeResourceTestBase.MODULE_NAME;
import static org.jboss.as.test.integration.ejb.management.deployments.EjbJarRuntimeResourceTestBase.componentAddress;
import static org.jboss.as.test.integration.ejb.management.deployments.EjbJarRuntimeResourceTestBase.execute;
import static org.jboss.as.test.integration.ejb.management.deployments.EjbJarRuntimeResourceTestBase.executeOperation;
import static org.jboss.as.test.integration.ejb.management.deployments.EjbJarRuntimeResourceTestBase.getEJBJar;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.SINGLETON;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.STATEFUL;
import static org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil.STATELESS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests whether the invocation statistics actually make sense.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(EjbInvocationStatisticsTestCaseSetup.class)
public class EjbInvocationStatisticsTestCase {
private static final String SUBSYSTEM_NAME = "ejb3";
@ContainerResource
private ManagementClient managementClient;
private Boolean statisticsEnabled;
private static InitialContext context;
@After
public void after() throws IOException {
setEnableStatistics(managementClient, statisticsEnabled);
}
@Before
public void before() throws IOException {
statisticsEnabled = getEnableStatistics(managementClient);
setEnableStatistics(managementClient, true);
assertEquals(Boolean.TRUE, getEnableStatistics(managementClient));
}
@BeforeClass
public static void beforeClass() throws Exception {
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
context = new InitialContext(props);
}
@Deployment
public static Archive<?> deployment() {
return getEJBJar();
}
private static Boolean getEnableStatistics(final ManagementClient managementClient) throws IOException {
final ModelNode address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)).toModelNode();
address.protect();
final ModelNode value = readAttribute(managementClient, address, "statistics-enabled");
if (value.isDefined())
return value.asBoolean();
return null;
}
private static ModelNode readAttribute(final ManagementClient managementClient, final ModelNode address, final String attributeName) throws IOException {
final ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION);
op.get(ModelDescriptionConstants.OP_ADDR).set(address);
op.get(ModelDescriptionConstants.NAME).set(attributeName);
op.get(ModelDescriptionConstants.RESOLVE_EXPRESSIONS).set(true);
return execute(managementClient, op);
}
private static void setEnableStatistics(final ManagementClient managementClient, final Boolean enableStatistics) throws IOException {
final ModelNode address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)).toModelNode();
address.protect();
if (enableStatistics == null)
undefineAttribute(managementClient, address, "enable-statistics");
else
writeAttributeBoolean(managementClient, address, "enable-statistics", enableStatistics);
}
@Test
public void testSingleton() throws Exception {
validateBean(SINGLETON, ManagedSingletonBean.class);
}
@Test
//TODO Elytron - ejb-client4 integration
public void testSFSB() throws Exception {
validateBean(STATEFUL, ManagedStatefulBean.class);
}
@Test
public void testSLSB() throws Exception {
validateBean(STATELESS, ManagedStatelessBean.class);
}
@Test
@Ignore("WFLY-14107 intermittent failure")
public void testSingletonWaitTime() throws Exception {
validateWaitTimeStatistic(SINGLETON, WaitTimeSingletonBean.class);
}
/**
* Invoke the singleton bean business method multiple times.
* The target bean has multiple timers that are competing for the same
* singleton bean instance. The wait-time statistic should show
* a number greater than zero, because the singleton uses a write lock.
*
* @param type type of bean (EJBManagementUtil.STATEFUL, STATELESS, SINGLETON, MESSAGE_DRIVEN)
* @param beanClass the bean class
* @throws Exception on errors
*/
private void validateWaitTimeStatistic(final String type, final Class<?> beanClass) throws Exception {
final String name = beanClass.getSimpleName();
final BusinessInterface bean = (BusinessInterface) context.lookup("ejb:/" + MODULE_NAME + "//" + name + "!" + BusinessInterface.class.getName() + (STATEFUL.equals(type) ? "?stateful" : ""));
for (int i = 0; i < 3; i++) {
bean.doIt();
}
bean.remove();
// check the wait-time statistic
final ModelNode address = componentAddress(EjbJarRuntimeResourcesTestCase.BASE_ADDRESS, type, name).toModelNode();
address.protect();
{
final ModelNode result = executeOperation(managementClient,
ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertTrue("Expecting wait-time attribute value > 0, but got " + result.toString(), result.get("wait-time").asLong() > 0L);
}
}
private void validateBean(final String type, final Class<?> beanClass) throws Exception {
final String name = beanClass.getSimpleName();
final ModelNode address = componentAddress(EjbJarRuntimeResourcesTestCase.BASE_ADDRESS, type, name).toModelNode();
address.protect();
{
final ModelNode result = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertEquals(0L, result.get("execution-time").asLong());
assertEquals(0L, result.get("invocations").asLong());
assertEquals(0L, result.get("peak-concurrent-invocations").asLong());
assertEquals(0L, result.get("wait-time").asLong());
assertEquals(0L, result.get("methods").asInt());
if (type.equals(STATEFUL)) {
assertEquals(0L, result.get("cache-size").asLong());
assertEquals(0L, result.get("passivated-count").asLong());
assertEquals(0L, result.get("total-size").asLong());
}
}
final BusinessInterface bean = (BusinessInterface) context.lookup("ejb:/" + MODULE_NAME + "//" + name + "!" + BusinessInterface.class.getName() + (type == STATEFUL ? "?stateful" : ""));
bean.doIt();
{
ModelNode result = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertTrue(result.get("execution-time").asLong() >= 50L);
assertEquals(1L, result.get("invocations").asLong());
assertEquals(1L, result.get("peak-concurrent-invocations").asLong());
assertTrue(result.get("wait-time").asLong() >= 0L);
assertEquals(1L, result.get("methods").asInt());
final List<Property> methods = result.get("methods").asPropertyList();
assertEquals("doIt", methods.get(0).getName());
final ModelNode invocationValues = methods.get(0).getValue();
assertTrue(invocationValues.get("execution-time").asLong() >= 50L);
assertEquals(1L, invocationValues.get("invocations").asLong());
assertTrue(invocationValues.get("wait-time").asLong() >= 0L);
if (type.equals(STATEFUL)) {
assertEquals(1L, result.get("cache-size").asLong());
assertEquals(0L, result.get("passivated-count").asLong());
assertEquals(1L, result.get("total-size").asLong());
// Create a second bean forcing the first bean to passivate
BusinessInterface bean2 = (BusinessInterface) context.lookup("ejb:/" + MODULE_NAME + "//" + name + "!" + BusinessInterface.class.getName() + (type == STATEFUL ? "?stateful" : ""));
bean2.doIt();
// Eviction is asynchronous, so wait a bit for this to take effect
Thread.sleep(TimeoutUtil.adjust(500));
result = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertEquals(1L, result.get("cache-size").asLong());
assertEquals(1L, result.get("passivated-count").asLong());
assertEquals(2L, result.get("total-size").asLong());
// remove bean from container
bean.remove();
bean2.remove();
result = executeOperation(managementClient, ModelDescriptionConstants.READ_RESOURCE_OPERATION, address);
assertEquals(0L, result.get("cache-size").asLong());
assertEquals(0L, result.get("passivated-count").asLong());
assertEquals(0L, result.get("total-size").asLong());
}
}
}
private static ModelNode undefineAttribute(final ManagementClient managementClient, final ModelNode address, final String attributeName) throws IOException {
final ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION);
op.get(ModelDescriptionConstants.OP_ADDR).set(address);
op.get(ModelDescriptionConstants.NAME).set(attributeName);
return execute(managementClient, op);
}
private static ModelNode writeAttributeBoolean(final ManagementClient managementClient, final ModelNode address, final String attributeName, final boolean value) throws IOException {
final ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION);
op.get(ModelDescriptionConstants.OP_ADDR).set(address);
op.get(ModelDescriptionConstants.NAME).set(attributeName);
op.get(ModelDescriptionConstants.VALUE).set(value);
return execute(managementClient, op);
}
}
| 12,689 | 47.62069 | 198 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/AbstractManagedBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.management.deployments;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Remove;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public abstract class AbstractManagedBean implements BusinessInterface {
@Override
public void doIt() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
@Remove
public void remove() {
}
@Asynchronous
public void async(int a, int b) {
}
}
| 1,554 | 32.085106 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/ManagedStatelessBean.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Schedule;
import jakarta.ejb.Stateless;
import jakarta.ejb.Timeout;
import jakarta.ejb.Timer;
import org.jboss.ejb3.annotation.Pool;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Bean to use in tests of management resources for SLSBs.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Stateless
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@Pool("slsb-strict-max-pool")
@LocalBean
public class ManagedStatelessBean extends AbstractManagedBean implements BusinessInterface {
@Timeout
@Schedule(second="15", persistent = false, info = "timer1")
public void timeout(final Timer timer) {
// no-op
}
}
| 1,919 | 34.555556 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/ManagedStatefulBean.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateful;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Bean to use in tests of management resources for SFSBs.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Stateful
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@Cache("distributable")
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
public class ManagedStatefulBean extends AbstractManagedBean implements BusinessInterface {
}
| 1,826 | 36.285714 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/EjbJarInEarRuntimeResourcesTestCase.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.management.deployments;
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.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.junit.runner.RunWith;
/**
* Tests management resources exposed by EJBs in a jar deployment packaged inside an EAR.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EjbJarInEarRuntimeResourcesTestCase extends EjbJarRuntimeResourceTestBase {
public static final String EAR_NAME = "ejb-management.ear";
@Deployment
public static Archive<?> deploy() {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_NAME);
ear.addAsModule(getEJBJar());
return ear;
}
public EjbJarInEarRuntimeResourcesTestCase() {
super(PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, EAR_NAME),
PathElement.pathElement(ModelDescriptionConstants.SUBDEPLOYMENT, JAR_NAME)));
}
}
| 2,408 | 39.15 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/EjbInvocationStatisticsTestCaseSetup.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.management.deployments;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.junit.Assert;
/**
* Adjust the default passivating cache used to cache SFSB session states to hold at most one state entry
* in memory. Additional bean states are passivated.
*
* @author Stuart Douglas, Ondrej Chaloupka
* @author wangchao
* @author Richard Achmatowicz
*/
public class EjbInvocationStatisticsTestCaseSetup implements ServerSetupTask {
private static final Logger log = Logger.getLogger(EjbInvocationStatisticsTestCaseSetup.class);
/**
* This test setup originally depended upon manipulating the passivation-store for the default (passivating) cache.
* However, since WFLY-14953, passivation stores have been superceeded by bean-management-providers
* (i.e. use /subsystem=distributable-ejb/infinispan-bean-management=default instead of /subsystem=ejb3/passivation-store=infinispan)
*/
private static final PathAddress INFINISPAN_BEAN_MANAGEMENT_PATH = PathAddress.pathAddress(PathElement.pathElement("subsystem", "distributable-ejb"),
PathElement.pathElement("infinispan-bean-management", "default"));
/*
* Set the max-active-beans attribute of the bean-management provider to 1 to force passivation.
*/
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
ModelNode operation = Util.getWriteAttributeOperation(INFINISPAN_BEAN_MANAGEMENT_PATH, "max-active-beans", 1);
ModelNode result = managementClient.getControllerClient().execute(operation);
log.trace("modelnode operation write-attribute max-active-beans=1: " + result);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
ServerReload.reloadIfRequired(managementClient);
}
/*
* Return max-active-beans to its configured value (10,000).
* NOTE: the configured default is 10000 but may change over time.
*/
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
ModelNode operation = Util.getWriteAttributeOperation(INFINISPAN_BEAN_MANAGEMENT_PATH, "max-active-beans", 10000);
ModelNode result = managementClient.getControllerClient().execute(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
ServerReload.reloadIfRequired(managementClient);
}
}
| 3,997 | 48.358025 | 153 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/NoTimerStatelessBean.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.Pool;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Bean to use in tests of management resources for SLSBs.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Stateless
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@Pool("slsb-strict-max-pool")
@LocalBean
public class NoTimerStatelessBean implements BusinessInterface {
@Override
public void doIt() {
// no-op;
}
@Override
public void remove() {
// no-op;
}
}
| 1,793 | 31.035714 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/ManagedStatefulBean2.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.management.deployments;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.AfterBegin;
import jakarta.ejb.AfterCompletion;
import jakarta.ejb.BeforeCompletion;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
import jakarta.ejb.StatefulTimeout;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.ejb3.annotation.SecurityDomain;
@Stateful(passivationCapable = false)
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
@Cache("distributable")
@StatefulTimeout(value = 2, unit = TimeUnit.HOURS)
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
public class ManagedStatefulBean2 extends AbstractManagedBean implements BusinessInterface {
@AfterBegin
private void afterBegin() {
}
@BeforeCompletion
private void beforeCompletion() {
}
@AfterCompletion
private void afterCompletion() {
}
@Remove(retainIfException = true)
public void removeTrue() {
}
@Remove(retainIfException = false)
public void removeFalse() {
}
}
| 2,331 | 32.314286 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/NoTimerMDB.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.management.deployments;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RunAs;
import jakarta.jms.JMSDestinationDefinition;
import jakarta.jms.Message;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* MDB to use in tests of management resources for MDBs. Other bean metadata is declared in ejb-jar.xml
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@JMSDestinationDefinition(
name="java:/queue/NoTimerMDB-queue",
interfaceName = "jakarta.jms.Queue"
)
@SecurityDomain("other")
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@RunAs("Role3")
public class NoTimerMDB {
public void onMessage(Message message) {
// no-op
}
}
| 1,778 | 34.58 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/management/deployments/BusinessInterface.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.management.deployments;
import jakarta.ejb.Remote;
/**
* Dummy interface for session beans in this class.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
@Remote
public interface BusinessInterface {
void doIt();
void remove();
}
| 1,317 | 32.794872 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/AbstractReferencingBeanA.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import jakarta.ejb.EJB;
public abstract class AbstractReferencingBeanA {
@EJB
private ReferencedBeanInterface referencedBean;
public String relayHello() {
return referencedBean.sayHello();
}
}
| 285 | 19.428571 | 63 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencingComponentA.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import jakarta.ejb.Stateless;
@Stateless
public class ReferencingComponentA extends AbstractReferencingBeanA {
}
| 179 | 21.5 | 69 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ResourceAnnotationsProcessingTestCase.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import org.jboss.arquillian.container.spi.client.container.DeploymentException;
import org.jboss.arquillian.container.test.api.Deployer;
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.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class ResourceAnnotationsProcessingTestCase {
private static final String ABSTRACT_REFERENCING_INTERFACE_WITHOUT_IMPL = "abstract-referencing-interface-without-impl";
private static final String INTERFACE_REFERENCING_INTERFACE_WITHOUT_IMPL = "interface-referencing-interface-without-impl";
private static final String EJBS_REFERENCING_INTERFACE_WITH_IMPL = "ejbs-referencing-interface-with-impl";
private static final String EJBS_REFERENCING_INTERFACE_WITHOUT_IMPL = "ejbs-referencing-interface-without-impl";
private static final String CLASSES_REFERENCING_INTERFACE_WITH_IMPL = "classes-referencing-interface-with-impl";
private static final String CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL = "classes-referencing-interface-without-impl";
@ArquillianResource
private Deployer deployer;
@Deployment(name = ABSTRACT_REFERENCING_INTERFACE_WITHOUT_IMPL, managed = false)
public static WebArchive createDeployment1() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
ABSTRACT_REFERENCING_INTERFACE_WITHOUT_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(AbstractReferencingBeanA.class);
return war;
}
@Deployment(name = INTERFACE_REFERENCING_INTERFACE_WITHOUT_IMPL, managed = false)
public static WebArchive createDeployment2() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
INTERFACE_REFERENCING_INTERFACE_WITHOUT_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(ReferencingBeanBInterface.class);
return war;
}
@Deployment(name = EJBS_REFERENCING_INTERFACE_WITH_IMPL, managed = false)
public static WebArchive createDeployment3() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
EJBS_REFERENCING_INTERFACE_WITH_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(ReferencedBean.class);
war.addClass(AbstractReferencingBeanA.class);
war.addClass(ReferencingComponentA.class);
war.addClass(ReferencingBeanBInterface.class);
war.addClass(ReferencingComponentB.class);
return war;
}
@Deployment(name = EJBS_REFERENCING_INTERFACE_WITHOUT_IMPL, managed = false)
public static WebArchive createDeployment4() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
EJBS_REFERENCING_INTERFACE_WITHOUT_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(AbstractReferencingBeanA.class);
war.addClass(ReferencingComponentA.class);
war.addClass(ReferencingBeanBInterface.class);
war.addClass(ReferencingComponentB.class);
return war;
}
@Deployment(name = CLASSES_REFERENCING_INTERFACE_WITH_IMPL, managed = false)
public static WebArchive createDeployment5() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
CLASSES_REFERENCING_INTERFACE_WITH_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(ReferencedBean.class);
war.addClass(AbstractReferencingBeanA.class);
war.addClass(ReferencingClassA.class);
war.addClass(ReferencingBeanBInterface.class);
war.addClass(ReferencingClassB.class);
return war;
}
@Deployment(name = CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL, managed = false)
public static WebArchive createDeployment6() {
final WebArchive war = ShrinkWrap.create(WebArchive.class,
CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(AbstractReferencingBeanA.class);
war.addClass(ReferencingClassA.class);
war.addClass(ReferencingBeanBInterface.class);
war.addClass(ReferencingClassB.class);
return war;
}
@Test
public void testAbstractReferencingInterfaceWithoutImpl() {
tryDeployment(ABSTRACT_REFERENCING_INTERFACE_WITHOUT_IMPL);
}
@Test
public void testInterfaceReferencingInterfaceWithoutImpl() {
tryDeployment(INTERFACE_REFERENCING_INTERFACE_WITHOUT_IMPL);
}
@Test
public void testEjbsReferencingInterfaceWithImpl() {
tryDeployment(EJBS_REFERENCING_INTERFACE_WITH_IMPL);
}
@Test(expected = DeploymentException.class)
public void testEjbsReferencingInterfaceWithoutImpl() {
tryDeployment(EJBS_REFERENCING_INTERFACE_WITHOUT_IMPL);
}
@Test
public void testClassesReferencingInterfaceWithImpl() {
tryDeployment(CLASSES_REFERENCING_INTERFACE_WITH_IMPL);
}
@Test(expected = DeploymentException.class)
public void testClassesReferencingInterfaceWithoutImpl() {
tryDeployment(CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL);
}
private void tryDeployment(String name) {
deployer.deploy(name);
deployer.undeploy(name);
}
}
| 5,549 | 42.023256 | 126 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencingClassA.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
public class ReferencingClassA extends AbstractReferencingBeanA {
}
| 133 | 25.8 | 65 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ResourceAnnotationsProcessingIgnoreUnusedResourceBindingTestCase.java
|
/*
* Copyright 2020 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.annotationprocessing;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
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;
@RunWith(Arquillian.class)
@ServerSetup(ResourceAnnotationsProcessingIgnoreUnusedResourceBindingTestCase.ServerSetup.class)
public class ResourceAnnotationsProcessingIgnoreUnusedResourceBindingTestCase {
private static final String CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL = "classes-referencing-interface-without-impl";
private static final PathAddress PROP_ADDRESS = PathAddress.pathAddress("system-property", "jboss.ee.ignore-unused-resource-binding");
@ArquillianResource
private Deployer deployer;
public static class ServerSetup implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String s) throws Exception {
ModelNode op = Util.createAddOperation(PROP_ADDRESS);
op.get("value").set("true");
ModelNode response = managementClient.getControllerClient().execute(op);
Assert.assertEquals(response.toString(), "success", response.get("outcome").asString());
ServerReload.executeReloadAndWaitForCompletion(managementClient);
}
@Override
public void tearDown(ManagementClient managementClient, String s) throws Exception {
ModelNode op = Util.createRemoveOperation(PROP_ADDRESS);
ModelNode response = managementClient.getControllerClient().execute(op);
Assert.assertEquals(response.toString(), "success", response.get("outcome").asString());
ServerReload.executeReloadAndWaitForCompletion(managementClient);
}
}
@Deployment(name = CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL, managed = false)
public static WebArchive createDeployment6() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL + ".war");
war.addClass(ReferencedBeanInterface.class);
war.addClass(AbstractReferencingBeanA.class);
war.addClass(ReferencingClassA.class);
war.addClass(ReferencingBeanBInterface.class);
war.addClass(ReferencingClassB.class);
return war;
}
@Test
public void testClassesReferencingInterfaceWithoutImplIgnoreUnusedResourceBinding() {
// https://issues.redhat.com/browse/WFLY-13719 Test effect of system property "jboss.ee.ignore-unused-resource-binding"
// which allow to ignore unused resource binding.
tryDeployment(CLASSES_REFERENCING_INTERFACE_WITHOUT_IMPL);
}
private void tryDeployment(String name) {
deployer.deploy(name);
deployer.undeploy(name);
}
}
| 3,950 | 42.9 | 138 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencingComponentB.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import jakarta.ejb.Stateless;
@Stateless
public class ReferencingComponentB implements ReferencingBeanBInterface {
}
| 183 | 22 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencingClassB.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
public class ReferencingClassB implements ReferencingBeanBInterface {
}
| 137 | 26.6 | 69 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencingBeanBInterface.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import jakarta.ejb.EJB;
public interface ReferencingBeanBInterface {
@EJB
ReferencedBeanInterface refencedBean = null;
}
| 197 | 17 | 63 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencedBean.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
import jakarta.ejb.Stateless;
@Stateless
public class ReferencedBean implements ReferencedBeanInterface {
@Override
public String sayHello() {
return "Hello!";
}
}
| 250 | 19.916667 | 64 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/annotationprocessing/ReferencedBeanInterface.java
|
package org.jboss.as.test.integration.ejb.annotationprocessing;
public interface ReferencedBeanInterface {
String sayHello();
}
| 133 | 21.333333 | 63 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/EJBClientDescriptorTestCase.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.client.descriptor;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import jakarta.ejb.EJBException;
import javax.naming.Context;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
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.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.logging.Logger;
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.test.api.Authentication;
/**
* Tests that deployments containing a jboss-ejb-client.xml are processed correctly for EJB client context
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(EJBClientDescriptorTestCase.EJBClientDescriptorTestCaseSetup.class)
public class EJBClientDescriptorTestCase {
private static final Logger logger = Logger.getLogger(EJBClientDescriptorTestCase.class);
private static final String APP_NAME = "";
private static final String DISTINCT_NAME = "";
private static final String MODULE_NAME_ONE = "ejb-client-descriptor-test";
private static final String MODULE_NAME_TWO = "ejb-client-descriptor-with-no-receiver-test";
private static final String MODULE_NAME_THREE = "ejb-client-descriptor-with-local-and-remote-receivers-test";
private static final String JBOSS_EJB_CLIENT_1_2_MODULE_NAME = "ejb-client-descriptor-test-with-jboss-ejb-client_1_2_xml";
private static final String JBOSS_EJB_CLIENT_WITH_PROPERTIES_1_2_MODULE_NAME = "ejb-client-descriptor-test-with-jboss-ejb-client_with_properties_1_2_xml";
private static final String outboundSocketName = "ejb-client-descriptor-test-outbound-socket";
private static final String outboundConnectionName = "ejb-client-descriptor-test-remote-outbound-connection";
static class EJBClientDescriptorTestCaseSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
final String socketBindingRef = "http";
EJBManagementUtil.createLocalOutboundSocket(managementClient.getControllerClient(), "standard-sockets", outboundSocketName, socketBindingRef, Authentication.getCallbackHandler());
logger.trace("Created local outbound socket " + outboundSocketName);
final Map<String, String> connectionCreationOptions = new HashMap<String, String>();
logger.trace("Creatng remote outbound connection " + outboundConnectionName);
EJBManagementUtil.createRemoteOutboundConnection(managementClient.getControllerClient(), outboundConnectionName, outboundSocketName, connectionCreationOptions, Authentication.getCallbackHandler());
logger.trace("Created remote outbound connection " + outboundConnectionName);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.removeRemoteOutboundConnection(managementClient.getControllerClient(), outboundConnectionName, Authentication.getCallbackHandler());
logger.trace("Removed remote outbound connection " + outboundConnectionName);
ServerReload.reloadIfRequired(managementClient);
EJBManagementUtil.removeLocalOutboundSocket(managementClient.getControllerClient(), "standard-sockets", outboundSocketName, Authentication.getCallbackHandler());
logger.trace("Removed local outbound socket " + outboundSocketName);
}
}
@ArquillianResource
private Deployer deployer;
@ArquillianResource
private Context context;
@Deployment(name = "good-client-config", testable = false, managed = false)
public static JavaArchive createDeployment() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME_ONE + ".jar");
jar.addPackage(EchoBean.class.getPackage());
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "jboss-ejb-client.xml", "jboss-ejb-client.xml");
return jar;
}
@Deployment(name = "jboss-ejb-client_1_2_version", testable = false, managed = false)
public static JavaArchive createJBossEJBClient12VersionDeployment() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, JBOSS_EJB_CLIENT_1_2_MODULE_NAME + ".jar");
jar.addPackage(EchoBean.class.getPackage());
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "jboss-ejb-client_1_2.xml", "jboss-ejb-client.xml");
return jar;
}
@Deployment(name = "no-ejb-receiver-client-config", testable = false, managed = false)
public static JavaArchive createNoEJBReceiverConfigDeployment() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME_TWO + ".jar");
jar.addPackage(EchoBean.class.getPackage());
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "no-ejb-receiver-jboss-ejb-client.xml", "jboss-ejb-client.xml");
return jar;
}
@Deployment(name = "local-and-remote-receviers-config", testable = false, managed = false)
public static JavaArchive createLocalAndRemoteReceiverConfigDeployment() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME_THREE + ".jar");
jar.addPackage(EchoBean.class.getPackage());
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "local-and-remote-receiver-jboss-ejb-client.xml", "jboss-ejb-client.xml");
return jar;
}
@Deployment(name = "jboss-ejb-client_with_properties_1_2_version", testable = false, managed = false)
public static JavaArchive createJBossEJBClientWithProperties12VersionDeployment() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, JBOSS_EJB_CLIENT_WITH_PROPERTIES_1_2_MODULE_NAME + ".jar");
jar.addPackage(EchoBean.class.getPackage());
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "jboss-ejb-client_with_properties_1_2.xml", "jboss-ejb-client.xml");
jar.addAsManifestResource(EJBClientDescriptorTestCase.class.getPackage(), "jboss-ejb-client_with_properties_1_2.properties", "jboss.properties");
return jar;
}
/**
* Tests that a deployment containing jboss-ejb-client.xml with remoting EJB receivers configured, works as expected
*
* @throws Exception
*/
@Test
public void testEJBClientContextConfiguration() throws Exception {
deployer.deploy("good-client-config");
try {
final RemoteEcho remoteEcho = (RemoteEcho) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME_ONE + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from an EJB client descriptor test!!!";
final String echo = remoteEcho.echo(MODULE_NAME_ONE, msg);
logger.trace("Received echo " + echo);
Assert.assertEquals("Unexpected echo returned from remote bean", msg, echo);
} finally {
deployer.undeploy("good-client-config");
}
}
/**
* Tests that a deployment with a jboss-ejb-client.xml with no EJB receivers configured, fails due to
* non-availability of EJB receivers in the EJB client context
*
* @throws Exception
*/
@Test
public void testEJBClientContextWithNoReceiversConfiguration() throws Exception {
deployer.deploy("no-ejb-receiver-client-config");
try {
final RemoteEcho remoteEcho = (RemoteEcho) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME_TWO + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from an EJB client descriptor test!!!";
try {
remoteEcho.echo(MODULE_NAME_TWO, msg);
Assert.fail("Exepcted to fail due to no EJB receivers availability");
} catch (EJBException e) {
// no EJB receivers available, so expected to fail
logger.trace("Received the expected exception during testing with no EJB receivers", e);
// TODO: We could even narrow down into the exception to ensure we got the right exception.
// But that's a bit brittle too since there's no guarantee in terms of API on what underlying
// exception will be thrown for non-availability of EJB receivers.
}
} finally {
deployer.undeploy("no-ejb-receiver-client-config");
}
}
/**
* Tests that a deployment containing jboss-ejb-client.xml with both local and remoting EJB receivers configured,
* works as expected
*
* @throws Exception
*/
@Test
@OperateOnDeployment("local-and-remote-receviers-config")
public void testLocalAndRemoteReceiversClientConfig() throws Exception {
deployer.deploy("local-and-remote-receviers-config");
try {
final RemoteEcho remoteEcho = (RemoteEcho) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME_THREE + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from an EJB client descriptor test!!!";
final String echo = remoteEcho.echo(MODULE_NAME_THREE, msg);
logger.trace("Received echo " + echo);
Assert.assertEquals("Unexpected echo returned from remote bean", msg, echo);
} finally {
deployer.undeploy("local-and-remote-receviers-config");
}
}
/**
* Invokes a method which takes longer than the configured invocation timeout. The client is expected
* to a receive a timeout exception
*
* @throws Exception
*/
@Test
@OperateOnDeployment("jboss-ejb-client_1_2_version")
public void testClientInvocationTimeout() throws Exception {
deployer.deploy("jboss-ejb-client_1_2_version");
try {
final RemoteEcho remoteEcho = (RemoteEcho) context.lookup("ejb:" + APP_NAME + "/" + JBOSS_EJB_CLIENT_1_2_MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from an EJB client descriptor test!!!";
try {
remoteEcho.twoSecondEcho(JBOSS_EJB_CLIENT_1_2_MODULE_NAME, msg);
Assert.fail("Expected to receive a timeout for the invocation");
} catch (Exception e) {
if (e instanceof EJBException && e.getCause() instanceof TimeoutException) {
logger.trace("Got the expected timeout exception", e.getCause());
return;
}
throw e;
}
} finally {
deployer.undeploy("jboss-ejb-client_1_2_version");
}
}
/**
* Tests that a deployment containing jboss-ejb-client.xml with remoting EJB receivers configured and property placeholders,
* works as expected.
*
* @throws Exception
*/
@Test
@OperateOnDeployment("jboss-ejb-client_with_properties_1_2_version")
public void testClientPropertiesReplacementInConfig() throws Exception {
deployer.deploy("jboss-ejb-client_with_properties_1_2_version");
try {
final RemoteEcho remoteEcho = (RemoteEcho) context.lookup("ejb:" + APP_NAME + "/" + JBOSS_EJB_CLIENT_WITH_PROPERTIES_1_2_MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from an EJB client descriptor test!!!";
remoteEcho.echo(JBOSS_EJB_CLIENT_WITH_PROPERTIES_1_2_MODULE_NAME, msg);
} finally {
deployer.undeploy("jboss-ejb-client_with_properties_1_2_version");
}
}
}
| 14,194 | 49.336879 | 209 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/DelegateEchoBean.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.client.descriptor;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote(RemoteEcho.class)
public class DelegateEchoBean implements RemoteEcho {
@Override
public String echo(String moduleName, String msg) {
return msg;
}
@Override
public String twoSecondEcho(String moduleName, String msg) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return msg;
}
}
| 1,614 | 31.3 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/RemoteEcho.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.client.descriptor;
/**
* @author Jaikiran Pai
*/
public interface RemoteEcho {
String echo(String moduleName, String msg);
String twoSecondEcho(final String moduleName, final String msg);
}
| 1,269 | 36.352941 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/DummyDeploymentNodeSelector.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.client.descriptor;
import org.jboss.ejb.client.DeploymentNodeSelector;
/**
* @author Jaikiran Pai
*/
public class DummyDeploymentNodeSelector implements DeploymentNodeSelector {
@Override
public String selectNode(String[] eligibleNodes, String appName, String moduleName, String distinctName) {
return eligibleNodes[0];
}
}
| 1,414 | 38.305556 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/EchoBean.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.client.descriptor;
import java.util.Hashtable;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import javax.naming.Context;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote(RemoteEcho.class)
public class EchoBean implements RemoteEcho {
@Override
public String echo(final String moduleName, final String msg) {
try {
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new javax.naming.InitialContext(props);
RemoteEcho delegate = (RemoteEcho) context.lookup("ejb:" + "" + "/" + moduleName + "/" + "" + "/" + DelegateEchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
return delegate.echo(moduleName, msg);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public String twoSecondEcho(String moduleName, String msg) {
final RemoteEcho delegate;
try {
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new javax.naming.InitialContext(props);
delegate = (RemoteEcho) context.lookup("ejb:" + "" + "/" + moduleName + "/" + "" + "/" + DelegateEchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
return delegate.twoSecondEcho(moduleName, msg);
}
}
| 2,617 | 39.276923 | 187 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/passbyvalue/TestEJB.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.client.descriptor.passbyvalue;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Joshua Swett
*
*/
@Stateless
@Remote(TestEJBRemote.class)
public class TestEJB implements TestEJBRemote {
@Override
public String getObjectReference(DummySerializableObject obj) {
return obj.toString();
}
}
| 1,400 | 34.025 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/passbyvalue/TestEJBRemote.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.client.descriptor.passbyvalue;
/**
* @author Joshua Swett
*
*/
public interface TestEJBRemote {
String getObjectReference(DummySerializableObject obj);
}
| 1,229 | 36.272727 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/passbyvalue/PassValueTypeTestCase.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.client.descriptor.passbyvalue;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
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.common.HttpRequest;
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;
/**
* @author baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class PassValueTypeTestCase {
public static final String WAR_FULL_DEPLOYMENT = "TestWAR";
public static final String WAR_STRIPPED_DEPLOYMENT = "TestWAR-stripped";
@ArquillianResource
@OperateOnDeployment(WAR_FULL_DEPLOYMENT)
private URL warUrl;
@ArquillianResource
@OperateOnDeployment(WAR_STRIPPED_DEPLOYMENT)
private URL warStrippedUrl;
@Deployment(name = WAR_FULL_DEPLOYMENT)
public static Archive<?> deployWar() {
return createWAR(true, WAR_FULL_DEPLOYMENT);
}
@Deployment(name = WAR_STRIPPED_DEPLOYMENT)
public static Archive<?> deployStrippedWar() {
return createWAR(false, WAR_STRIPPED_DEPLOYMENT);
}
public static Archive<?> createWAR(final boolean includeJbossEJBClientXML, final String name) {
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war");
war.addClasses(ClientPassByValueTestServlet.class, TestEJB.class, TestEJBRemote.class, DummySerializableObject.class);
if (includeJbossEJBClientXML) {
war.addAsManifestResource(PassValueTypeTestCase.class.getPackage(), "jboss-ejb-client.xml", "jboss-ejb-client.xml");
}
war.addAsWebInfResource(PassValueTypeTestCase.class.getPackage(), "web.xml", "web.xml");
return war;
}
@Test
public void testFullWar() throws Exception {
test(warUrl);
}
@Test
public void testStrippedWar() throws Exception {
test(warStrippedUrl);
}
private void test(final URL url) throws IOException, ExecutionException, TimeoutException {
final String result2 = HttpRequest.get(url + "test?flip=false", 4, TimeUnit.SECONDS);
final String result = HttpRequest.get(url + "test?flip=true", 4, TimeUnit.SECONDS);
Assert.assertNotEquals(result, result2);
}
}
| 3,737 | 37.536082 | 128 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/passbyvalue/ClientPassByValueTestServlet.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.client.descriptor.passbyvalue;
import java.io.IOException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
*
* @author baranowb
*
*/
@WebServlet(urlPatterns = "/test")
public class ClientPassByValueTestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final DummySerializableObject DUMMY_SERIALIZABLE_OBJECT = new DummySerializableObject();
public static final String FLIP = "flip";
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
final String flip = request.getParameter(FLIP);
if (flip != null && Boolean.parseBoolean(flip)) {
InitialContext ctx = null;
try {
ctx = new InitialContext();
TestEJBRemote ejb = (TestEJBRemote) ctx.lookup("ejb:/TestWAR//TestEJB!org.jboss.as.test.integration.ejb.client.descriptor.passbyvalue.TestEJBRemote");
final String objectRefInside = ejb.getObjectReference(DUMMY_SERIALIZABLE_OBJECT);
write(response, objectRefInside);
} catch (NamingException ne) {
throw new RuntimeException(ne);
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
} else {
write(response, DUMMY_SERIALIZABLE_OBJECT.toString());
}
}
private static void write(HttpServletResponse writer, String message) {
try {
writer.getWriter().write(message);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
| 3,038 | 36.9875 | 166 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/client/descriptor/passbyvalue/DummySerializableObject.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.client.descriptor.passbyvalue;
import java.io.Serializable;
/**
* @author Joshua Swett
*
*/
public class DummySerializableObject implements Serializable {
private static final long serialVersionUID = 1L;
}
| 1,280 | 37.818182 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/exception/BeanieLocal.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.exception;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface BeanieLocal {
void callThrowException();
void callThrowExceptionNever();
void throwException() throws Exception;
void throwXmlAppException();
}
| 1,331 | 39.363636 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/exception/AppExceptionTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.exception;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBException;
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;
/**
* AS7-1317
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@RunWith(Arquillian.class)
public class AppExceptionTestCase {
@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class, "ejb3-app-exception.jar")
.addPackage(Beanie.class.getPackage())
.addAsManifestResource(AppExceptionTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
}
@EJB(mappedName = "java:global/ejb3-app-exception/Beanie")
private BeanieLocal bean;
@Test
public void testAppException() {
try {
bean.callThrowException();
} catch (EJBException e) {
// EJB 3.1 FR 14.3.1: a system exception is rethrown as an EJBException
final Exception cause1 = e.getCausedByException();
assertNotNull(cause1);
assertEquals(RuntimeException.class, cause1.getClass());
final Throwable cause2 = cause1.getCause();
assertNotNull(cause2);
assertEquals(Exception.class, cause2.getClass());
assertEquals("This is an app exception", cause2.getMessage());
}
}
/**
*AS7-5926
*/
@Test
public void testAppExceptionNever() {
try {
bean.callThrowExceptionNever();
} catch (EJBException e) {
// EJB 3.1 FR 14.3.1: a system exception is rethrown as an EJBException
final Exception cause1 = e.getCausedByException();
assertNotNull(cause1);
assertEquals(RuntimeException.class, cause1.getClass());
final Throwable cause2 = cause1.getCause();
assertNotNull(cause2);
assertEquals(Exception.class, cause2.getClass());
assertEquals("This is an app exception", cause2.getMessage());
}
}
@Test
public void testXmlAppException() {
try {
bean.throwXmlAppException();
Assert.fail("should have thrown exception");
} catch (XmlAppException e) {
}
}
}
| 3,620 | 35.21 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/exception/XmlAppException.java
|
package org.jboss.as.test.integration.ejb.exception;
/**
* @author Stuart Douglas
*/
public class XmlAppException extends RuntimeException {
}
| 146 | 17.375 | 55 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/exception/Beanie.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.exception;
import static jakarta.ejb.TransactionAttributeType.NEVER;
import static jakarta.ejb.TransactionAttributeType.NOT_SUPPORTED;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
public class Beanie implements BeanieLocal {
@Resource
private SessionContext ctx;
public void callThrowException() {
try {
ctx.getBusinessObject(BeanieLocal.class).throwException();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@TransactionAttribute(NEVER)
public void callThrowExceptionNever() {
try {
ctx.getBusinessObject(BeanieLocal.class).throwException();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@TransactionAttribute(NOT_SUPPORTED)
public void throwException() throws Exception {
throw new Exception("This is an app exception");
}
@Override
public void throwXmlAppException() {
throw new XmlAppException();
}
}
| 2,253 | 32.147059 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/OtherLocalInterface.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.localview;
import jakarta.ejb.Local;
/**
* @author Stuart Douglas
*/
@Local
public interface OtherLocalInterface {
void otherLocalOperation();
}
| 1,211 | 35.727273 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/LocalInterface.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.localview;
import jakarta.ejb.Local;
/**
* An ejb local interface
*
* @author Stuart Douglas
*/
@Local
public interface LocalInterface {
void localOperation();
}
| 1,232 | 32.324324 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/SimpleImplicitLocalInterfaceBean.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.localview;
import jakarta.ejb.Stateless;
/**
* EJB with a single implicit local interface
*
* @author Stuart Douglas
*/
@Stateless
public class SimpleImplicitLocalInterfaceBean implements ImplicitLocalInterface {
@Override
public void message() {
}
}
| 1,327 | 34.891892 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/ImplicitLocalInterfaceBean.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.localview;
import java.io.Serializable;
import jakarta.ejb.Stateless;
/**
* Bean that has a single implicit local interface, that also implements Serializable
*
* @author Stuart Douglas
*/
@Stateless
public class ImplicitLocalInterfaceBean implements Serializable, ImplicitLocalInterface {
@Override
public void message() {
}
}
| 1,407 | 34.2 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/OtherInterface.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.localview;
/**
* @author Stuart Douglas
*/
public interface OtherInterface {
void moreStuff();
}
| 1,164 | 35.40625 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/NotViewInterface.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.localview;
/**
* Interface that is not used as a local view
*
* @author Stuart Douglas
*/
public interface NotViewInterface {
void doOtherStuff();
}
| 1,218 | 34.852941 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/TwoLocalsDeclaredOnBean.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.localview;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
/**
* This bean class has a two local interfaces, declared on the bean class
* @author Stuart Douglas
*/
@Stateless
@Local({OtherInterface.class,LocalInterface.class})
public class TwoLocalsDeclaredOnBean implements OtherInterface, LocalInterface {
@Override
public void localOperation() {
}
@Override
public void moreStuff() {
}
}
| 1,487 | 34.428571 | 80 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/SingleLocalDeclaredOnBean.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.localview;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
/**
* This bean class has a single local interface, declared on the bean class
* @author Stuart Douglas
*/
@Stateless
@Local({OtherInterface.class})
public class SingleLocalDeclaredOnBean implements OtherInterface, LocalInterface {
@Override
public void localOperation() {
}
@Override
public void moreStuff() {
}
}
| 1,471 | 34.047619 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/TwoLocalsDeclaredOnInterface.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.localview;
import java.io.Serializable;
import jakarta.ejb.Stateless;
/**
* Bean with a two local interfaces, declared on the interface
* @author Stuart Douglas
*/
@Stateless
public class TwoLocalsDeclaredOnInterface implements NotViewInterface, LocalInterface, OtherLocalInterface, Serializable {
@Override
public void localOperation() {
}
@Override
public void doOtherStuff() {
}
@Override
public void otherLocalOperation() {
}
}
| 1,533 | 33.088889 | 122 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/SingleLocalDeclaredOnInterface.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.localview;
import java.io.Serializable;
import jakarta.ejb.Stateless;
/**
* Bean with a single local interface, declared on the interface
* @author Stuart Douglas
*/
@Stateless
public class SingleLocalDeclaredOnInterface implements NotViewInterface, LocalInterface, Serializable{
@Override
public void localOperation() {
}
@Override
public void doOtherStuff() {
}
}
| 1,454 | 34.487805 | 102 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/ImplicitNoInterfaceBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 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.localview;
import java.io.Serializable;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
public class ImplicitNoInterfaceBean implements Serializable {
public void message() {
}
}
| 1,325 | 35.833333 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/EjbLocalViewTestCase.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.localview;
import static org.junit.Assert.fail;
import java.io.Serializable;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
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.Test;
import org.junit.runner.RunWith;
/**
* Tests that local views of SLSF's are handled properly, as per EE 3.1 4.9.7
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbLocalViewTestCase {
@Deployment
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class,"testlocal.war");
war.addPackage(EjbLocalViewTestCase.class.getPackage());
return war;
}
@Test
public void testImplicitNoInterface() throws NamingException {
ensureExists(ImplicitNoInterfaceBean.class, ImplicitNoInterfaceBean.class, true);
ensureDoesNotExist(ImplicitNoInterfaceBean.class, Serializable.class);
}
@Test
public void testSingleImplicitInterface() throws NamingException {
ensureExists(SimpleImplicitLocalInterfaceBean.class,ImplicitLocalInterface.class,true);
ensureDoesNotExist(SimpleImplicitLocalInterfaceBean.class, Serializable.class);
}
@Test
public void testSingleImplicitInterfaceWithSerializable() throws NamingException {
ensureExists(ImplicitLocalInterfaceBean.class,ImplicitLocalInterface.class,true);
}
@Test
public void testSingleLocalDeclaredOnBean() throws NamingException {
ensureExists(SingleLocalDeclaredOnBean.class,OtherInterface.class,true);
ensureDoesNotExist(SingleLocalDeclaredOnBean.class,LocalInterface.class);
}
@Test
public void testSingleLocalDeclaredOnInterface() throws NamingException {
ensureExists(SingleLocalDeclaredOnInterface.class,LocalInterface.class,true);
ensureDoesNotExist(SingleLocalDeclaredOnInterface.class,NotViewInterface.class);
ensureDoesNotExist(SingleLocalDeclaredOnInterface.class,Serializable.class);
}
@Test
public void testTwoLocalsDeclaredOnBean() throws NamingException {
ensureExists(TwoLocalsDeclaredOnBean.class,OtherInterface.class,false);
ensureExists(TwoLocalsDeclaredOnBean.class,OtherInterface.class,false);
ensureDoesNotExist(TwoLocalsDeclaredOnBean.class);
}
@Test
public void testTwoLocalsDeclaredOnInterface() throws NamingException {
ensureExists(TwoLocalsDeclaredOnInterface.class,LocalInterface.class,false);
ensureExists(TwoLocalsDeclaredOnInterface.class,OtherLocalInterface.class,false);
ensureDoesNotExist(TwoLocalsDeclaredOnInterface.class);
ensureDoesNotExist(TwoLocalsDeclaredOnInterface.class,NotViewInterface.class);
ensureDoesNotExist(TwoLocalsDeclaredOnInterface.class,Serializable.class);
}
private void ensureExists(Class<?> bean, Class<?> iface, boolean single) throws NamingException {
try {
InitialContext ctx = new InitialContext();
ctx.lookup("java:global/testlocal/" + bean.getSimpleName() + "!" + iface.getName());
ctx.lookup("java:app/testlocal/" + bean.getSimpleName() + "!" + iface.getName());
ctx.lookup("java:module/" + bean.getSimpleName() + "!" + iface.getName());
if(single) {
ctx.lookup("java:global/testlocal/" + bean.getSimpleName());
ctx.lookup("java:app/testlocal/" + bean.getSimpleName());
ctx.lookup("java:module/" + bean.getSimpleName());
}
} catch (NameNotFoundException e) {
fail(e.getMessage());
}
}
private void ensureDoesNotExist(Class<?> bean, Class<?> iface) throws NamingException {
lookupAndFailIfExists("java:global/testlocal/" + bean.getSimpleName() + "!" + iface.getName());
lookupAndFailIfExists("java:app/testlocal/" + bean.getSimpleName() + "!" + iface.getName());
lookupAndFailIfExists("java:module/" + bean.getSimpleName() + "!" + iface.getName());
}
private void ensureDoesNotExist(Class<?> bean) throws NamingException {
lookupAndFailIfExists("java:global/testlocal/" + bean.getSimpleName());
lookupAndFailIfExists("java:app/testlocal/" + bean.getSimpleName());
lookupAndFailIfExists("java:module/" + bean.getSimpleName());
}
private void lookupAndFailIfExists(String name) throws NamingException {
try {
InitialContext ctx = new InitialContext();
ctx.lookup(name);
fail("Entry " + name + " was bound to JNDI when it should not be");
} catch (NameNotFoundException e) {
}
}
}
| 5,944 | 41.769784 | 107 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/localview/ImplicitLocalInterface.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.localview;
/**
* Implicit local interface
*
* @author Stuart Douglas
*/
public interface ImplicitLocalInterface {
void message();
}
| 1,200 | 35.393939 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/StatefulCalculatorRemote.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.remote.stateful;
import jakarta.ejb.Remote;
/**
* User: jpai
*/
@Remote
public interface StatefulCalculatorRemote {
int add(int number);
}
| 1,214 | 33.714286 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/ValueWrapper.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.remote.stateful;
import java.io.Serializable;
/**
* Java serialization will not invoke the class initializer during unmarshalling, resulting in
* shouldBeNilAfterUnmarshalling being left as null. This helps test if JBoss marshalling does the same.
*/
public class ValueWrapper implements Serializable {
public static String INITIALIZER_CONSTANT = "FIVE";
private transient String shouldBeNilAfterUnmarshalling = INITIALIZER_CONSTANT;
public String getShouldBeNilAfterUnmarshalling() {
return shouldBeNilAfterUnmarshalling;
}
}
| 1,625 | 39.65 | 105 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/RemoteInterface.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.remote.stateful;
import jakarta.ejb.Remote;
import jakarta.ejb.Remove;
/**
* @author Stuart Douglas
*/
@Remote
public interface RemoteInterface {
void add(int i);
int get();
ValueWrapper getValue();
@Remove
void remove();
}
| 1,309 | 30.95122 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/StatefulInVmRemoteInvocationTestCase.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.remote.stateful;
import jakarta.ejb.NoSuchEJBException;
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.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;
/**
* Tests cross deployment remote EJB invocation, when the deployments cannot see each others classes
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class StatefulInVmRemoteInvocationTestCase {
@Deployment
public static Archive<?> caller() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "stateful.jar");
jar.addPackage(StatefulInVmRemoteInvocationTestCase.class.getPackage());
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/stateful/" + beanName + "!" + interfaceType.getName()));
}
@Test
public void testCrossDeploymentInvocation() throws Exception {
RemoteInterface bean = lookup(StatefulAddingBean.class.getSimpleName(), RemoteInterface.class);
bean.add(10);
bean.add(10);
Assert.assertEquals(20, bean.get());
bean.remove();
try {
bean.add(10);
Assert.fail("Expected EJB to be removed");
} catch (NoSuchEJBException expected) {
}
}
/**
* Test bean returning a value object with a transient field. Will test that the transient field is set to null
* (just like java serialization would do)
* instead of a non-null value (non-null came ValueWrapper class initializer if this fails).
*
* @throws Exception
*/
@Test
public void testValueObjectWithTransientField() throws Exception {
RemoteInterface bean = lookup(StatefulAddingBean.class.getSimpleName(), RemoteInterface.class);
Assert.assertNull("transient field should be serialized as null but was '" + bean.getValue().getShouldBeNilAfterUnmarshalling() +"'",
bean.getValue().getShouldBeNilAfterUnmarshalling());
bean.remove();
}
}
| 3,509 | 36.340426 | 141 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/StatefulAddingBean.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.remote.stateful;
import jakarta.ejb.EJB;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
/**
*
*/
@Stateful
public class StatefulAddingBean implements RemoteInterface {
@EJB
private StatefulCalculatorRemote statefulCalculator;
private int value = 0;
@Override
public void add(final int i) {
this.value = this.statefulCalculator.add(i);
}
@Override
public int get() {
return value;
}
@Override
public ValueWrapper getValue() {
return new ValueWrapper();
}
@Override
@Remove
public void remove() {
}
}
| 1,674 | 26.016129 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/stateful/StatefulCalculator.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.remote.stateful;
import jakarta.ejb.Stateful;
/**
* User: jpai
*/
@Stateful
public class StatefulCalculator implements StatefulCalculatorRemote {
private int currentValue;
@Override
public int add(int number) {
currentValue += number;
return currentValue;
}
}
| 1,364 | 32.292683 | 70 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.