From b3800c19527cade071a9d00f4e07576f858265b1 Mon Sep 17 00:00:00 2001 From: alwin-joseph Date: Wed, 11 May 2022 17:43:11 +0000 Subject: [PATCH 1/2] new faces client for ejb32 tests - part 1 Signed-off-by: alwin-joseph --- bin/xml/ts.vehicles.xml | 10 +- install/jakartaee/other/vehicle.properties | 45 +- .../ejb30/timer/common/JsfClientBase.java | 164 +++ .../tests/ejb30/timer/common/build-import.xml | 3 +- .../aroundtimeout/common/JsfClientBase.java | 191 +++ .../timer/basic/concurrency/JsfClient.java | 125 ++ .../lite/timer/basic/sharing/JsfClient.java | 170 +++ .../ejb32/lite/timer/basic/sharing/build.xml | 1 + .../ejb32/lite/timer/basic/xa/JsfClient.java | 73 + .../tests/ejb32/lite/timer/basic/xa/build.xml | 1 + .../singleton/annotated/JsfClient.java | 109 ++ .../singleton/annotated/build.xml | 1 + .../singleton/dual/JsfClient.java | 54 + .../business/common/JsfClientBase.java | 40 + .../business/singleton/JsfClient.java | 44 + .../interceptor/business/singleton/build.xml | 2 + .../business/stateless/JsfClient.java | 44 + .../interceptor/business/stateless/build.xml | 2 + .../lifecycle/singleton/JsfClient.java | 80 ++ .../interceptor/lifecycle/singleton/build.xml | 2 +- .../descriptor/stateless/JsfClient.java | 112 ++ .../lite/timer/schedule/expire/JsfClient.java | 1201 +++++++++++++++++ .../expression/annotated/JsfClient.java | 325 +++++ .../expression/descriptor/JsfClient.java | 81 ++ .../timer/schedule/lifecycle/JsfClient.java | 244 ++++ .../lite/timer/schedule/tx/JsfClient.java | 118 ++ .../lite/timer/schedule/tx/JsfClientBase.java | 246 ++++ .../schedule/txnonpersistent/JsfClient.java | 129 ++ .../timer/schedule/txnonpersistent/build.xml | 1 + .../lite/timer/schedule/tz/JsfClient.java | 101 ++ .../ejb32/lite/timer/schedule/tz/build.xml | 1 + .../timer/service/singleton/JsfClient.java | 43 + .../lite/timer/service/singleton/build.xml | 1 + .../timer/service/stateless/JsfClient.java | 42 + .../lite/timer/service/stateless/build.xml | 1 + .../lite/timer/timerconfig/JsfClient.java | 176 +++ .../ejb32/lite/timer/timerconfig/build.xml | 1 + .../timer/service/common/JsfClientBase.java | 103 ++ 38 files changed, 4073 insertions(+), 14 deletions(-) create mode 100644 src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java create mode 100644 src/com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/JsfClientBase.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClientBase.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/schedule/tz/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/service/singleton/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/service/stateless/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/lite/timer/timerconfig/JsfClient.java create mode 100644 src/com/sun/ts/tests/ejb32/timer/service/common/JsfClientBase.java diff --git a/bin/xml/ts.vehicles.xml b/bin/xml/ts.vehicles.xml index 2d23d3893d..c2fa51d081 100644 --- a/bin/xml/ts.vehicles.xml +++ b/bin/xml/ts.vehicles.xml @@ -436,7 +436,7 @@ com/sun/ts/tests/ejb30/common/lite/*.class, com/sun/ts/tests/ejb30/common/helper/Helper.class, ${harness.pkg.dir}/ServiceEETest*.class" - excludes="@{excludedfiles}, ${pkg.dir}/**/JsfClient.class"/> + excludes="@{excludedfiles}"/> @@ -472,7 +472,7 @@ com/sun/ts/tests/ejb30/common/lite/*.class, com/sun/ts/tests/ejb30/common/helper/Helper.class, ${harness.pkg.dir}/ServiceEETest*.class" - excludes="${runner.classes}, @{excludedfiles}, ${pkg.dir}/**/Client.class" + excludes="${runner.classes}, @{excludedfiles}" prefix="WEB-INF/classes"/> @@ -529,7 +529,7 @@ com/sun/ts/tests/ejb30/common/lite/*.class, com/sun/ts/tests/ejb30/common/helper/Helper.class, ${harness.pkg.dir}/ServiceEETest*.class" - excludes="${runner.classes}, @{excludedfiles}, ${pkg.dir}/**/JsfClient.class" + excludes="${runner.classes}, @{excludedfiles}" prefix="WEB-INF/classes"/> @@ -653,7 +653,7 @@ com/sun/ts/tests/ejb30/common/lite/*.class, com/sun/ts/tests/ejb30/common/helper/Helper.class, ${harness.pkg.dir}/ServiceEETest*.class" - excludes="${runner.classes}, @{excludedfiles}, ${pkg.dir}/**/JsfClient.class" + excludes="${runner.classes}, @{excludedfiles}" prefix="WEB-INF/classes"/> @@ -782,7 +782,7 @@ com/sun/ts/tests/ejb30/common/lite/*.class, com/sun/ts/tests/ejb30/common/helper/Helper.class, ${harness.pkg.dir}/ServiceEETest*.class" - excludes="${runner.classes}, @{excludedfiles}, ${pkg.dir}/**/JsfClient.class" + excludes="${runner.classes}, @{excludedfiles}" prefix="WEB-INF/classes"/> diff --git a/install/jakartaee/other/vehicle.properties b/install/jakartaee/other/vehicle.properties index 264e9664a5..6239e77f61 100644 --- a/install/jakartaee/other/vehicle.properties +++ b/install/jakartaee/other/vehicle.properties @@ -164,13 +164,44 @@ com/sun/ts/tests/ejb30/bb/session/stateful/timeout = ejblitejsp com/sun/ts/tests/ejb30/bb/session/stateful/concurrency = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp com/sun/ts/tests/ejb32/lite = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp ejbembed -com/sun/ts/tests/ejb32/lite/timer/basic/xa = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/service = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/schedule/tx = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp -com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent = ejbliteservlet ejbliteservlet2 ejblitejsf ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/basic/sharing/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/basic/xa/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/expire/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/service/singleton/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/service/singleton/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/service/stateless/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/service/stateless/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/tx/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/tz/Client.java = ejbembed ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/schedule/tz/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp +com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java = ejblitejsf +com/sun/ts/tests/ejb32/lite/timer/timerconfig/Client.java = ejbliteservlet ejbliteservlet2 ejblitejsp ejbembed +com/sun/ts/tests/ejb32/lite/timer/timerconfig/JsfClient.java = ejblitejsf com/sun/ts/tests/ejb32/timer = ejbliteservlet com/sun/ts/tests/jaxm = ejb servlet jsp appclient diff --git a/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java b/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java new file mode 100644 index 0000000000..ec8d1bed42 --- /dev/null +++ b/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.ejb30.timer.common; + +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.ejb30.common.helper.Helper; +import com.sun.ts.tests.ejb30.common.lite.EJBLiteJsfClientBase; + +import jakarta.ejb.EJB; + +public class JsfClientBase extends EJBLiteJsfClientBase { + protected static final long WAIT_FOR_TIMEOUT_STATUS = 60000; // millis + + protected static final long WAIT_FOR_NO_TIMEOUT_STATUS = 60000; // millis + + protected static final int NUM_OF_RECURRING_RECORDS = 3; + + protected static final long POLL_INTERVAL = 1000; // millis + + protected static final long DEFAULT_DURATION = 100L; // time out after these + // millisec + + protected static final long DEFAULT_INTERVAL = 100L; + + @EJB(beanName = "TimeoutStatusBean") + protected TimeoutStatusBean statusSingleton; + + @Override + public void setup(String[] args, Properties p) { + super.setup(args, p); + if (needToRemoveStatusAndRecords()) { + // NOTE: this method only clears records for the timer whose name is + // the same as the current test name. If the test method creates + // timers with different names, these timer records will not be cleared. + // In that case, individual test methods need to take care of it. + removeStatusAndRecords(); + } + } + + protected boolean needToRemoveStatusAndRecords() { + return true; + } + + protected void passIfNoTimeout(long... waitMillis) { + passIfNoTimeout(getTestName(), waitMillis); + } + + protected void passIfNoTimeout(String timerName, long... waitMillis) { + long waitFor = WAIT_FOR_NO_TIMEOUT_STATUS; + if (waitMillis.length != 0) { + waitFor = waitMillis[0]; + } + Boolean status = pollTimeoutStatus(timerName, waitFor, false); + assertEquals("Timeout status must not be set.", null, status); + assertEquals("Timeout result must not be set.", 0, + statusSingleton.getRecords(timerName).size()); + } + + protected void passIfTimeout(long... waitMillis) { + passIfTimeout(getTestName(), waitMillis); + } + + // Usually timerName is the same as getTestName(). This method is used + // when they are different. + protected void passIfTimeout(String timerName, long... waitMillis) { + long waitFor = WAIT_FOR_TIMEOUT_STATUS; + if (waitMillis.length != 0) { + waitFor = waitMillis[0]; + } + Boolean status = pollTimeoutStatus(timerName, waitFor, false); + appendReason(statusSingleton.getRecords(timerName)); + assertEquals("Check timeout status", Boolean.TRUE, status); + } + + protected void passIfTimeoutOnce(long... waitMillis) { + passIfTimeoutOnce(getTestName(), waitMillis); + } + + protected void passIfTimeoutOnce(String timerName, long... waitMillis) { + passIfTimeout(timerName, waitMillis); + // wait again to see if there is any subsequent expiration. + long waitFor = (waitMillis.length != 0) ? waitMillis[0] + : WAIT_FOR_TIMEOUT_STATUS; + TestUtil.sleepMsec((int) waitFor); + assertEquals("Check num of expirations", 1, + statusSingleton.getRecords(timerName).size()); + } + + // for recurring timers with interval + protected void passIfRecurringTimeout(long... waitMillis) { + passIfRecurringTimeout(getTestName(), waitMillis); + } + + // for recurring timers with interval + protected void passIfRecurringTimeout(String timerName, long... waitMillis) { + long waitFor = WAIT_FOR_TIMEOUT_STATUS * NUM_OF_RECURRING_RECORDS; + if (waitMillis.length != 0) { + waitFor = waitMillis[0]; + } + Boolean status = pollTimeoutStatus(timerName, waitFor, true); + List records = statusSingleton.getRecords(timerName); + appendReason(records); + assertEquals("Check timeout status", Boolean.TRUE, status); + assertGreaterThan("Check num of timeout records", records.size(), + NUM_OF_RECURRING_RECORDS - 1); + } + + private Boolean pollTimeoutStatus(String timerName, long waitMillis, + boolean recurringTimer) { + long end = System.currentTimeMillis() + waitMillis; + Boolean status = null; + List records = Collections.emptyList(); + if (recurringTimer) { + while (records.size() < NUM_OF_RECURRING_RECORDS + && System.currentTimeMillis() < end) { + TestUtil.sleepMsec((int) POLL_INTERVAL); + records = statusSingleton.getRecords(timerName); + } + status = statusSingleton.getStatus(timerName); + if (records.size() < NUM_OF_RECURRING_RECORDS) { + Helper.getLogger() + .fine("Polling recurring Timeout records timed out after " + + waitMillis + " millis for timerName " + timerName); + } + } else { + while (status == null && System.currentTimeMillis() < end) { + TestUtil.sleepMsec((int) POLL_INTERVAL); + status = statusSingleton.getStatus(timerName); + } + if (status == null) { + Helper.getLogger().fine("Polling Timeout status timed out after " + + waitMillis + " millis for timerName " + timerName); + } + } + return status; + } + + protected void removeStatusAndRecords(String... timerName) { + String tn = (timerName.length == 0) ? getTestName() : timerName[0]; + statusSingleton.removeStatus(tn); + statusSingleton.removeRecords(tn); + } +} diff --git a/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml b/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml index 1038321645..c76d5210e6 100644 --- a/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml +++ b/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml @@ -26,7 +26,8 @@ com/sun/ts/tests/ejb30/timer/common/ScheduleValues.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBase.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBaseWithoutTimeOutMethod.class, - com/sun/ts/tests/ejb30/timer/common/ClientBase.class"/> + com/sun/ts/tests/ejb30/timer/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/common/JsfClientBase.class"/> records = statusSingleton.getRecords(aroundTimeoutRecordKey); + statusSingleton.removeStatus(getTestName()); + statusSingleton.removeRecords(aroundTimeoutRecordKey); + appendReason(Helper.compareResultList(expected, records)); + } + +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java new file mode 100644 index 0000000000..a228e9a332 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.basic.concurrency; + +import java.util.Calendar; +import java.util.Date; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.ejb30.common.lite.EJBLiteJsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends EJBLiteJsfClientBase implements Serializable { + + private static final long serialVersionUID = -271884412676327L; + + private static final int THREAD_COUNT = 100; + + private static final int INCREMENT = 999; + + private static final int EXPECTED_SUM = THREAD_COUNT * INCREMENT; + + private static final int CREATE_TIMER_AFTER_MILLIS = 1000; + + private static final long DEFAULT_MAX_WAIT_MILLIS = 1000 * 60 * 5; + + private static final long POLL_INTERVAL_MILLIS = 1000 * 60; + + @EJB(beanName = "WriteSingletonTimerBean") + private TimerIF writeSingletonTimerBean; + + @EJB(beanName = "ReadSingletonTimerBean") + private TimerIF readSingletonTimerBean; + + /* + * @testName: lookupTimerService + * + * @test_Strategy: lookup TimerService in lifecycle methods and async methods; + * verify that TimerService and Timer methods can be invoked in these + * invocation contexts. + */ + public void lookupTimerService() + throws InterruptedException, ExecutionException { + Future f = readSingletonTimerBean.lookupTimerService(); + appendReason(f.get()); + } + + public void readLockTimeout() { + lockTimeout(readSingletonTimerBean); + assertNotEquals(null, EXPECTED_SUM, + getAndResetResult(readSingletonTimerBean, EXPECTED_SUM)); + } + + public void readLockBusyAdd() { + readSingletonTimerBean.cancelAllTimers(); + readSingletonTimerBean.resetResult(); + readSingletonTimerBean.setIncrement(INCREMENT); + for (int i = 0; i < THREAD_COUNT; i++) { + readSingletonTimerBean.readLockBusyAdd(); + } + assertNotEquals(null, EXPECTED_SUM, + getAndResetResult(readSingletonTimerBean, EXPECTED_SUM)); + } + + /* + * @testName: writeLockTimeout + * + * @test_Strategy: @Timeout method has LockType.WRITE + */ + public void writeLockTimeout() { + lockTimeout(writeSingletonTimerBean); + assertEquals(null, EXPECTED_SUM, + getAndResetResult(writeSingletonTimerBean, EXPECTED_SUM)); + } + + private void lockTimeout(TimerIF b) { + b.cancelAllTimers(); + b.resetResult(); + b.setIncrement(INCREMENT); + Date d = TimerUtil.getCurrentDatePlus(Calendar.MILLISECOND, + CREATE_TIMER_AFTER_MILLIS); + for (int i = 0; i < THREAD_COUNT; i++) { + String name = getTestName() + i; + b.createTimer(name, d); + } + } + + // keep polling the singleton bean till the expected result is reached, or the + // polling + // times out. The expected param is needed since singleton timeout method or + // business + // method keeps updating the sum result. + protected Integer getAndResetResult(TimerIF b, int expected, + long... maxWaitMillis) { + long waitFor = maxWaitMillis.length == 0 ? DEFAULT_MAX_WAIT_MILLIS + : maxWaitMillis[0]; + long stopTime = System.currentTimeMillis() + waitFor; + boolean avail = b.isResultComplete(expected); + while (!avail && System.currentTimeMillis() < stopTime) { + TestUtil.sleep((int) POLL_INTERVAL_MILLIS); + avail = b.isResultComplete(expected); + } + return b.getAndResetResult(); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java new file mode 100644 index 0000000000..88e8f2ceac --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.basic.sharing; + +import java.util.Calendar; +import java.util.Date; +import java.util.Properties; +import java.util.Vector; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.ejb30.common.helper.TestFailedException; +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import jakarta.ejb.Timer; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -271884412671127L; + + private static final int THREAD_COUNT = 100; + + private static final long TIMER_DURATION = 1000 * 60 * 5; + + @EJB(beanName = "StatelessTimerBean") + private TimerIF statelessTimerBean; + + @EJB(beanName = "SingletonTimerBean") + private TimerIF singletonTimerBean; + + @Override + public void setup(String[] args, Properties p) { + super.setup(args, p); + // warm up the timer service to avoid possible startup delay, and clean up + statelessTimerBean.cancelAllTimers(); + singletonTimerBean.cancelAllTimers(); + } + + /* + * @testName: createTimerRollbackStateless + * + * @assertion_ids: + * + * @test_Strategy: create a timer, and roll back the tx. + */ + public void createTimerRollbackStateless() { + statelessTimerBean.createTimerRollback(DEFAULT_DURATION, + new TimerInfo(getTestName())); + passIfNoTimeout(); + } + + /* + * @testName: createTimerRollbackSingleton + * + * @assertion_ids: + * + * @test_Strategy: create a timer, and roll back the tx. + */ + public void createTimerRollbackSingleton() { + singletonTimerBean.createTimerRollback(DEFAULT_DURATION, + new TimerInfo(getTestName())); + passIfNoTimeout(); + } + + /* + * @testName: createVerifyRecurringTimerStateless + * + * @assertion_ids: + * + * @test_Strategy: create a timer, find it, and verify its expiration + */ + public void createVerifyRecurringTimerStateless() { + Date expiration = TimerUtil.getCurrentDatePlus(Calendar.SECOND, 1); + Timer timer = statelessTimerBean.createTimer(expiration, DEFAULT_INTERVAL, + new TimerInfo(getTestName())); + passIfRecurringTimeout(); + statelessTimerBean.cancelTimer(timer); + } + + /* + * @testName: createVerifyRecurringTimerSingleton + * + * @assertion_ids: + * + * @test_Strategy: create a timer, find it, and verify its expiration + */ + public void createVerifyRecurringTimerSingleton() { + Date expiration = TimerUtil.getCurrentDatePlus(Calendar.SECOND, 1); + Timer timer = singletonTimerBean.createTimer(expiration, DEFAULT_INTERVAL, + new TimerInfo(getTestName())); + passIfRecurringTimeout(); + singletonTimerBean.cancelTimer(timer); + } + + /* + * @testName: accessTimersStateless + * + * @assertion_ids: + * + * @test_Strategy: verify all bean instances of the same EJB share the same + * set of timers, invoking stateless bean + */ + public void accessTimersStateless() { + accessTimers0(statelessTimerBean); + } + + /* + * @testName: accessTimersSingleton + * + * @assertion_ids: + * + * @test_Strategy: verify all bean instances of the same EJB share the same + * set of timers, invoking singleton bean + */ + public void accessTimersSingleton() { + accessTimers0(singletonTimerBean); + } + + private void accessTimers0(final TimerIF bean) { + final Vector results = new Vector(); + final Vector errors = new Vector(); + + bean.createTimer(TIMER_DURATION, null); + Runnable runnable = new Runnable() { + public void run() { + try { + String result = bean.accessTimers(); + results.add(result); + } catch (TestFailedException e) { + errors.add(TestUtil.printStackTraceToString(e)); + } + } + }; + Thread[] threads = new Thread[THREAD_COUNT]; + for (int i = 0; i < THREAD_COUNT; i++) { + threads[i] = new Thread(runnable); + threads[i].start(); + } + for (int i = 0; i < threads.length; i++) { + try { + threads[i].join(); + } catch (InterruptedException ex) { + // ignore + } + } + assertEquals(null, 0, errors.size()); + assertEquals(null, THREAD_COUNT, results.size()); + appendReason(results); + bean.cancelAllTimers(); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/build.xml index ed78d8a1fb..8f61dad9e0 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/build.xml @@ -28,6 +28,7 @@ com/sun/ts/tests/ejb30/timer/common/TimerInfo.class, com/sun/ts/tests/ejb30/timer/common/TimerUtil.class, com/sun/ts/tests/ejb30/timer/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/common/JsfClientBase.class, com/sun/ts/tests/ejb30/timer/common/TimeoutStatusBean.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBaseWithoutTimeOutMethod.class "> diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java new file mode 100644 index 0000000000..117da48667 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.basic.xa; + +import java.util.Calendar; +import java.util.Date; + +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -232184412671127L; + + @EJB(beanName = "StatelessXATimerBean") + private StatelessXATimerBean statelessXaTimerBean; + + @EJB(beanName = "SingletonXATimerBean") + private SingletonXATimerBean singletonXaTimerBean; + + /* + * @testName: persistCoffeeCreateTimerRollbackStateless + * + * @test_Strategy: persist a coffee in the first business method. In the + * second business method, create a timer and try to persist the same coffee. + * It will cause the tx and timer creation to rollback. + */ + public void persistCoffeeCreateTimerRollbackStateless() { + persistCoffeeCreateTimerRollback(statelessXaTimerBean, "RollbackStateless"); + } + + /* + * @testName: persistCoffeeCreateTimerRollbackSingleton + * + * @test_Strategy: see persistCoffeeCreateTimerRollbackStateless + */ + public void persistCoffeeCreateTimerRollbackSingleton() { + persistCoffeeCreateTimerRollback(singletonXaTimerBean, "RollbackSingleton"); + } + + private void persistCoffeeCreateTimerRollback(XATimerBeanBase b, + String brandName) { + int id = 1; + Date expireation = TimerUtil.getCurrentDatePlus(Calendar.HOUR, 5); + TimerInfo info = new TimerInfo(getTestName()); + b.persistCoffee(id, brandName); + boolean result = b.persistCoffeeCreateTimerRollback(id, brandName, + expireation, info); + assertEquals(null, true, result); + assertEquals(null, 0, b.getTimers().size()); + passIfNoTimeout(); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/build.xml index 9afe9a9044..8a7076c613 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/build.xml @@ -35,6 +35,7 @@ com/sun/ts/tests/ejb30/timer/common/TimerInfo.class, com/sun/ts/tests/ejb30/timer/common/TimerUtil.class, com/sun/ts/tests/ejb30/timer/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/common/JsfClientBase.class, com/sun/ts/tests/ejb30/timer/common/TimeoutStatusBean.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBaseWithoutTimeOutMethod.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBase.class diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/JsfClient.java new file mode 100644 index 0000000000..bfc9ca5538 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/JsfClient.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.aroundtimeout.singleton.annotated; + +import com.sun.ts.tests.ejb30.timer.interceptor.aroundtimeout.common.AroundTimeoutIF; +import com.sun.ts.tests.ejb30.timer.interceptor.aroundtimeout.common.JsfClientBase; + +import jakarta.ejb.EJB; +import jakarta.ejb.EJBException; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -256884412676327L; + + @EJB(beanName = "AroundTimeoutExceptionBean") + protected AroundTimeoutExceptionBean aroundTimeoutExceptionBean; + + @Override + protected AroundTimeoutIF getAroundTimeoutExceptionBean() { + return aroundTimeoutExceptionBean; + } + + /* + * @testName: aroundTimeoutExceptionAsBusinessMethod + * + * @test_Strategy: invoke the bean class' aroundTimeout method as a business + * method. + */ + public void aroundTimeoutExceptionAsBusinessMethod() throws Exception { + try { + aroundTimeoutExceptionBean.aroundTimeout(null); + } catch (EJBException e) { + RuntimeException cause = (RuntimeException) e.getCause(); + assertEquals(null, "AroundTimeoutExceptionBeanBase", cause.getMessage()); + } + } + + /* + * @testName: allInterceptors + * + * @test_Strategy: all interceptors at default and class-level should be + * invoked. //default interceptors 2, 1 //class-level interceptors 4, 3 + * //method-level interceptors 6, 5 + */ + + /* + * @testName: allInterceptorsOverride + * + * @test_Strategy: For AroundTimeoutOverrideBean, interceptor-order in + * ejb-jar.xml is used to override the ordering of class-level interceptors. + * exclude-default-interceptors is also applied for AroundTimeoutOverrideBean. + */ + + /* + * @testName: allInterceptorsComplement + * + * @test_Strategy: AroundTimeoutComplementBean's interceptors are also + * declared in ejb-jar.xml to complement the class-level interceptors. + * AroundTimeoutComplementBean excludes default interceptors. + */ + + /* + * @testName: aroundTimeoutMethod + * + * @test_Strategy: override @AroundTimeout method with @AroundTimeout method + * and verify that the superclass' @AroundTimeout is disabled, and subclass' + * + * @AroundTimeout method is invoked + */ + + /* + * @testName: aroundTimeoutMethod2 + * + * @test_Strategy:override @AroundTimeout method with non-AroundTimeout method + * and verify that the superclass' @AroundTimeout is disabled + */ + + /* + * @testName: aroundTimeoutException + * + * @test_Strategy: Interceptor1 catches and suppresses the RuntimeException + * from bean class' AroundTimeout method. + */ + + /* + * @testName: invocationContextMethods + * + * @test_Strategy: invokes various methods on InvocationContext inside + * + * @AroundTimeout method. + */ +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/build.xml index 54ceec2f36..ce671fe766 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/annotated/build.xml @@ -31,6 +31,7 @@ com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/MethodOverrideBeanBase.class, com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/AroundTimeoutIF.class, com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/JsfClientBase.class, com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/InterceptorBase.class, com/sun/ts/tests/ejb30/timer/interceptor/aroundtimeout/common/Interceptor*.class "> diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/JsfClient.java new file mode 100644 index 0000000000..fd6d1d6ba3 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/aroundtimeout/singleton/dual/JsfClient.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.aroundtimeout.singleton.dual; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends com.sun.ts.tests.ejb30.timer.common.JsfClientBase implements Serializable { + + private static final long serialVersionUID = -2564031884412627L; + + @EJB(beanName = "AroundTimeoutBean") + protected AroundTimeoutBean aroundTimeoutBean; + + /* + * @testName: asBusiness + * + * @test_Strategy: timeout method can also be exposed as business methods. + * When invoked as a business method, the around-invoke method in the + * method-level interceptor is to be invoked, not the around-timeout method. + */ + public void asBusiness() { + // There should be no exception + aroundTimeoutBean.asBusiness(); + appendReason("Invoked business method without errors."); + } + + /* + * @testName: asTimeout + * + * @test_Strategy: When invoked as a timeout method, the around-timeout method + * in the method-level interceptor is to be invoked, not the around-invoke + * method. + */ + public void asTimeout() { + passIfRecurringTimeout(); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.java new file mode 100644 index 0000000000..c2d7b38a07 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.business.common; + +public class JsfClientBase extends com.sun.ts.tests.ejb30.timer.common.JsfClientBase { + protected BusinessTimerBeanBase businessTimerBean; + + /* + * testName: aroundInvokeMethods + * + * @assertion_ids: + * + * @test_Strategy: create a timer in all interceptor methods. Verify they + * expire as expected. + */ + public void aroundInvokeMethods() { + businessTimerBean.createMillisecondLaterTimer(getTestName()); + passIfTimeout("BusinessTimerBeanBase.aroundInvoke"); // expire once + passIfTimeout("BusinessTimerBean.aroundInvoke"); // expire once + passIfTimeout("Interceptor1.aroundInvoke"); // expire once + passIfTimeout("Interceptor2.aroundInvoke"); // expire once + passIfTimeout("Interceptor3.aroundInvoke"); // expire once + passIfTimeout("InterceptorBase.aroundInvoke"); // expire 3 times + passIfTimeout(); // expire once + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/JsfClient.java new file mode 100644 index 0000000000..7fc635fba4 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/JsfClient.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.business.singleton; + +import com.sun.ts.tests.ejb32.lite.timer.interceptor.business.common.BusinessTimerBeanBase; +import com.sun.ts.tests.ejb32.lite.timer.interceptor.business.common.JsfClientBase; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -256884415436327L; + + @EJB(beanInterface = BusinessTimerBean.class, beanName = "BusinessTimerBean") + protected void setBusinessTimerBean(BusinessTimerBeanBase businessTimerBean) { + this.businessTimerBean = businessTimerBean; + } + + /* + * @testName: aroundInvokeMethods + * + * @assertion_ids: + * + * @test_Strategy: create a timer in all interceptor methods. Verify they + * expire as expected. + */ +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/build.xml index 03d41b5a26..18bcfd315c 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/singleton/build.xml @@ -28,11 +28,13 @@ com/sun/ts/tests/ejb30/timer/common/TimerInfo.class, com/sun/ts/tests/ejb30/timer/common/TimerUtil.class, com/sun/ts/tests/ejb30/timer/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/common/JsfClientBase.class, com/sun/ts/tests/ejb30/timer/common/TimeoutStatusBean.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBaseWithoutTimeOutMethod.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/BusinessTimerBeanBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/ClientBase.class, + com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/InterceptorBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/Interceptor1.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/Interceptor2.class, diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/JsfClient.java new file mode 100644 index 0000000000..6772323e9e --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/JsfClient.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.business.stateless; + +import com.sun.ts.tests.ejb32.lite.timer.interceptor.business.common.BusinessTimerBeanBase; +import com.sun.ts.tests.ejb32.lite.timer.interceptor.business.common.JsfClientBase; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -25688441589327L; + + @EJB(beanInterface = BusinessTimerBean.class, beanName = "BusinessTimerBean") + protected void setBusinessTimerBean(BusinessTimerBeanBase businessTimerBean) { + this.businessTimerBean = businessTimerBean; + } + + /* + * @testName: aroundInvokeMethods + * + * @assertion_ids: + * + * @test_Strategy: create a timer in all interceptor methods. Verify they + * expire as expected. + */ +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/build.xml index 90f38bb348..7eb3c43f97 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/business/stateless/build.xml @@ -28,11 +28,13 @@ com/sun/ts/tests/ejb30/timer/common/TimerInfo.class, com/sun/ts/tests/ejb30/timer/common/TimerUtil.class, com/sun/ts/tests/ejb30/timer/common/ClientBase.class, + com/sun/ts/tests/ejb30/timer/common/JsfClientBase.class, com/sun/ts/tests/ejb30/timer/common/TimeoutStatusBean.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBaseWithoutTimeOutMethod.class, com/sun/ts/tests/ejb30/timer/common/TimerBeanBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/BusinessTimerBeanBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/ClientBase.class, + com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/JsfClientBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/InterceptorBase.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/Interceptor1.class, com/sun/ts/tests/ejb32/lite/timer/interceptor/business/common/Interceptor2.class, diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/JsfClient.java new file mode 100644 index 0000000000..bcc46082ce --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/JsfClient.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.interceptor.lifecycle.singleton; + +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; + +import jakarta.ejb.EJB; +import java.io.Serializable; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase implements Serializable { + + private static final long serialVersionUID = -25218441589327L; + + @EJB(beanName = "LifecycleTimerBean") + private LifecycleTimerBean bean; + + @EJB(beanName = "LifecycleAroundConstructTimerBean") + private LifecycleAroundConstructTimerBean aroundConstructTimerBean; + + /* + * @testName: postConstructInBeanClass + * + * @assertion_ids: + * + * @test_Strategy: create a timer in singleton PostConstruct method in bean + * class and its superclass. Verify they expire as expected. + */ + public void postConstructInBeanClass() { + bean.getTimers(); // the first request to activate the singleton + passIfTimeout("LifecycleTimerBeanBase.postConstruct"); + passIfTimeout("LifecycleTimerBean.postConstruct"); + } + + /* + * @testName: postConstructInInterceptorClasses + * + * @assertion_ids: + * + * @test_Strategy: create a timer in PostConstruct methods of lifecycle + * interceptor classes. Verify they all expire as expected. + */ + public void postConstructInInterceptorClasses() { + bean.getTimers(); // the first request to activate the singleton + passIfTimeout("Interceptor1.postConstruct"); // expecting 2 timeout records + passIfTimeout("Interceptor2.postConstruct"); // expecting 1 timeout records + passIfRecurringTimeout("InterceptorBase.postConstruct"); // expecting 3 + // timeout records + } + + /* + * @testName: aroundConstructInBeanClass + * + * @assertion_ids: + * + * @test_Strategy: create a timer in singleton PostConstruct method in bean + * class and its superclass. Verify they expire as expected. + */ + public void aroundConstructInBeanClass() { + aroundConstructTimerBean.getTimers(); // the first request to activate the + // singleton + passIfTimeout("LifecycleTimerBeanBase.postConstruct"); + passIfTimeout("LifecycleAroundConstructTimerBean.postConstruct"); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/build.xml index adf0550a28..edbb6351a3 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/interceptor/lifecycle/singleton/build.xml @@ -44,7 +44,7 @@ diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/JsfClient.java new file mode 100644 index 0000000000..3aaf69ca06 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/descriptor/stateless/JsfClient.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.descriptor.stateless; + +import static com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF.AUTO_TIMER_SUFFIX; +import static com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF.EmptyParamTimeoutBean; +import static com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF.NoParamTimeoutBean; +import static com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF.PROGRAMMATIC_TIMER_SUFFIX; +import static com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF.WithParamTimeoutBean; + +import java.util.ArrayList; +import java.util.List; + +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; +import com.sun.ts.tests.ejb30.timer.schedule.descriptor.common.TimeoutParamIF; + +import jakarta.annotation.PostConstruct; +import jakarta.ejb.EJB; +import jakarta.ejb.Timer; +import jakarta.ejb.TimerConfig; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + + @EJB(beanName = NoParamTimeoutBean) + private TimeoutParamIF noParamTimeoutBean; + + @EJB(beanName = EmptyParamTimeoutBean) + private TimeoutParamIF emptyParamTimeoutBean; + + @EJB(beanName = WithParamTimeoutBean) + private TimeoutParamIF withParamTimeoutBean; + + private List beans = new ArrayList(); + + @SuppressWarnings("unused") + @PostConstruct + private void postConstruct() { + beans.add(noParamTimeoutBean); + beans.add(emptyParamTimeoutBean); + beans.add(withParamTimeoutBean); + } + + /* + * @testName: programmatic + * + * @test_Strategy: + */ + public void programmatic() { + for (TimeoutParamIF b : beans) { + String timerName = b.getBeanName() + PROGRAMMATIC_TIMER_SUFFIX; + // Timer t = b.createSecondLaterTimer(timerName); + Timer t = b.createSecondLaterTimer( + new TimerConfig(new TimerInfo(timerName), false), 2); + appendReason("Created a timer with name " + timerName + "; " + t); + passIfTimeout(timerName); + removeStatusAndRecords(timerName); + } + } + + /* + * @testName: autoNoParamTimeoutBean + * + * @test_Strategy: + */ + public void autoNoParamTimeoutBean() { + auto(noParamTimeoutBean); + } + + /* + * @testName: autoEmptyParamTimeoutBean + * + * @test_Strategy: + */ + public void autoEmptyParamTimeoutBean() { + auto(emptyParamTimeoutBean); + } + + /* + * @testName: autoWithParamTimeoutBean + * + * @test_Strategy: + */ + public void autoWithParamTimeoutBean() { + auto(withParamTimeoutBean); + } + + private void auto(TimeoutParamIF b) { + passIfRecurringTimeout(b.getBeanName() + AUTO_TIMER_SUFFIX); + + // If cancel timers, then the subsequent test run won't pass without a + // redeploy. + // b.cancelAllTimers(); + } + +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java new file mode 100644 index 0000000000..62e55c6a76 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java @@ -0,0 +1,1201 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.expire; + +import java.util.Calendar; +import java.util.Date; +import java.util.Properties; +import java.util.TimeZone; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.ejb30.common.helper.Helper; +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.ScheduleValues; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import jakarta.ejb.EJBException; +import jakarta.ejb.NoMoreTimeoutsException; +import jakarta.ejb.NoSuchObjectLocalException; +import jakarta.ejb.ScheduleExpression; +import jakarta.ejb.Timer; +import jakarta.ejb.TimerConfig; + +/** + * Some tests use 2100 as a test calendar: + January February + Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa + 1 2 1 2 3 4 5 6 + 3 4 5 6 7 8 9 7 8 9 10 11 12 13 + 10 11 12 13 14 15 16 14 15 16 17 18 19 20 + 17 18 19 20 21 22 23 21 22 23 24 25 26 27 + 24 25 26 27 28 29 30 28 + 31 + + * + */ +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + private static final int WAIT_YEARS = 6; + + @EJB(beanName = "ScheduleBean") + private ScheduleBean scheduleBean; + + @Override + public void setup(String[] args, Properties p) { + super.setup(args, p); + scheduleBean.cancelAllTimers(); + } + + private void incrementSecond0(String increment, + long timeRemainingTillNextTimeout) { + ScheduleExpression exp = new ScheduleExpression() + .hour(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .minute(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR).second(increment); + TimerInfo info = new TimerInfo(getTestName()); + info.setLongVar(timeRemainingTillNextTimeout); + Timer timer = createTimer(exp, info); + passIfRecurringTimeout(); + scheduleBean.cancelTimer(timer); + } + + private void incrementMinute0(String increment, Date expectedTimeout, + Date... starts) { + ScheduleExpression exp = new ScheduleExpression() + .hour(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR).minute(increment); + if (starts.length > 0) { + exp = exp.start(starts[0]); + } + Timer timer = createTimer(exp); + verifyNextTimeout(expectedTimeout, timer); + scheduleBean.cancelTimer(timer); + } + + private void incrementHour0(String increment, Date expectedTimeout, + Date... starts) { + ScheduleExpression exp = new ScheduleExpression().hour(increment); + if (starts.length > 0) { + exp = exp.start(starts[0]); + } + Timer timer = createTimer(exp); + verifyNextTimeout(expectedTimeout, timer); + scheduleBean.cancelTimer(timer); + } + + private void dayOfWeek0(ScheduleExpression exp, Date expectedNextTimeout, + String... dayOfWeeks) { + // all timers created with each dayOfWeek expire at the same + // expectedNextTimeout + if (exp == null) { + exp = new ScheduleExpression(); + } + // may fall to next month, or even next year. So set month and year to * + for (String day : dayOfWeeks) { + exp = exp.year(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .month(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .dayOfMonth(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .dayOfWeek(day); + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + } + + private void month0(ScheduleExpression exp, Date expectedNextTimeout, + String... months) { + // all timers created with each month expire at the same expectedNextTimeout + if (exp == null) { + exp = new ScheduleExpression(); + } + // may fall to next year. So set year to * + for (String month : months) { + exp = exp.year(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR).month(month); + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + } + + private void year0(ScheduleExpression exp, Date expectedNextTimeout, + String... years) { + if (exp == null) { + exp = new ScheduleExpression(); + } + for (String year : years) { + exp = exp.year(year); + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + } + + private void dayOfMonth0(String[] dayOfMonths, int[] expectedDayOfMonths, + Calendar cal) { + for (int i = 0; i < dayOfMonths.length; i++) { + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal) + .dayOfMonth(dayOfMonths[i]); + Date expectedNextTimeout = cal.getTime(); + expectedNextTimeout = DateUtils.setDays(expectedNextTimeout, + expectedDayOfMonths[i]); + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + } + + protected void verifyNextTimeout(Date expected, Timer timer) + throws RuntimeException { + final long ignoreableMillis = DateUtils.MILLIS_PER_MINUTE; + Date actual = scheduleBean.getNextTimeout(timer); + long actualTimeRemaining = scheduleBean.getTimeRemaining(timer); + Helper.getLogger().fine( + "About to compare expected and actual nextTimeout and actualTimeRemaining:" + + expected + "; " + actual + "; " + actualTimeRemaining); + + appendReason("Compare expected nextTimeout " + expected + + ", and actual nextTimeout " + actual); + try { + assertEquals(null, true, + DateUtils.isSameInstant(DateUtils.round(expected, Calendar.MINUTE), + DateUtils.round(actual, Calendar.MINUTE))); + } catch (RuntimeException e) { + appendReason( + "Rounded dates are not equal; next check if they are close."); + long dif = Math.abs(expected.getTime() - actual.getTime()); + if (dif <= ignoreableMillis) { + appendReason("The time diff " + dif + " <= ignoreableMillis " + + ignoreableMillis); + } else { + throw new RuntimeException( + "The time diff " + dif + " > " + ignoreableMillis); + } + } + Helper.assertCloseEnough("Check timeRemaining", + expected.getTime() - System.currentTimeMillis(), actualTimeRemaining, + ignoreableMillis, getReasonBuffer()); + } + + protected Timer createTimer(ScheduleExpression exp, TimerInfo... infos) { + Timer timer = null; + if (infos.length == 0) { + // timer = scheduleBean.createTimer(exp, getTestName()); + timer = scheduleBean.createTimer(exp, + new TimerConfig(new TimerInfo(getTestName()), false)); + } else { + // timer = scheduleBean.createTimer(exp, infos[0]); + timer = scheduleBean.createTimer(exp, new TimerConfig(infos[0], false)); + } + appendReason(TestUtil.NEW_LINE + "Created a timer with expression " + + TimerUtil.toString(exp)); + return timer; + } + + /* + * @testName: startNeverExpires + * + * @test_Strategy: create a timer with year="currentYear - currentYear+1", and + * start="currentYear+WAIT_YEARS". The start value is beyond the year values, + * and this timer will never expire. Creating this timer will succeed, but any + * timer method access in a subsequent business method will result in + * NoSuchObjectLocalException. + */ + public void startNeverExpires() { + Calendar cal = Calendar.getInstance(); + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.SECOND, 10); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date start = TimerUtil.getCurrentDatePlus(Calendar.YEAR, WAIT_YEARS); + exp.start(start); + exp.year((currentYear) + " - " + (currentYear + 1)); + + Timer timer = createTimer(exp); + appendReason(scheduleBean.passIfNoMoreTimeouts(timer)); + passIfNoTimeout(); + } + + /* + * @testName: endNeverExpires + * + * @test_Strategy: create a timer with year="currentYear - currentYear+1", and + * end="currentYear-1". The end value is prior to the year values, and this + * timer will never expire. Creating this timer will succeed, but any timer + * method access in a subsequent business method will result in + * NoSuchObjectLocalException. + */ + + public void endNeverExpires() { + Calendar cal = Calendar.getInstance(); + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.SECOND, 10); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date end = DateUtils.setYears(cal.getTime(), cal.get(Calendar.YEAR) - 1); + exp.end(end); + exp.year((currentYear) + " - " + (currentYear + 1)); + + Timer timer = createTimer(exp); + appendReason(scheduleBean.passIfNoMoreTimeouts(timer)); + passIfNoTimeout(); + } + + /* + * @testName: endBeforeActualValues + * + * @test_Strategy: the end date is before the actual values. So the timer + * should be dead. + */ + public void endBeforeActualValues() { + int plusMinutes = 5; + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR); + Date end = TimerUtil.getCurrentDatePlus(Calendar.YEAR, plusMinutes); + end = DateUtils.setYears(end, currentYear + WAIT_YEARS); + + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.SECOND, + plusMinutes * 2); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + exp.year((currentYear + WAIT_YEARS) + "-" + (currentYear + WAIT_YEARS * 2)); + exp.end(end); + + Timer timer = createTimer(exp); + appendReason(scheduleBean.passIfNoMoreTimeouts(timer)); + } + + /* + * @testName: startBeforeActualValues + * + * @test_Strategy: the start attr of the expression represents a time before + * the first expiration. Verify that the timer does not expire at the start + * date. If the current date is 1/13/2009 17:46:47, then the schedule is + * year=2015 - 2021 month=1 dayOfMonth=13 dayOfWeek=* hour=17 minute=46 + * second=47 start Tue Jan 13 17:46:52 EST 2009 end null + */ + public void startBeforeActualValues() { + Date start = TimerUtil.getCurrentDatePlus(Calendar.SECOND, 5); + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR); + Calendar cal = Calendar.getInstance(); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + exp.year( + (currentYear + WAIT_YEARS) + " - " + (currentYear + WAIT_YEARS * 2)); + exp.start(start); + + Timer timer = createTimer(exp); + Date expectedNextTimeout = DateUtils.setYears(cal.getTime(), + currentYear + WAIT_YEARS); + verifyNextTimeout(expectedNextTimeout, timer); + passIfNoTimeout(); + } + + /* + * @testName: startInTheFuture + * + * @test_Strategy: the start attr of the expression represents a time in the + * future. Other attrs take defaults. If the current year is 2009, then the + * schedule is: year=* month=* dayOfMonth=* dayOfWeek=* hour=0 minute=0 + * second=0 start Thu Jan 01 00:00:00 EST 2015 end null + * + * ScheduleExpression is mutable but any modification should not affect timers + * that were created previously with this schedule. + */ + + public void startInTheFuture() { + Calendar cal = Calendar.getInstance(); + Date currentDate = cal.getTime(); + Date start = DateUtils.truncate(currentDate, Calendar.YEAR); + start = DateUtils.setYears(start, cal.get(Calendar.YEAR) + WAIT_YEARS); + + ScheduleExpression exp = new ScheduleExpression().start(start); + Timer timer = createTimer(exp); + verifyNextTimeout(start, timer); + + exp.start(currentDate); + verifyNextTimeout(start, timer); + passIfNoTimeout(); + } + + /* + * @testName: startAfterActualValues + * + * @test_Strategy: the start attr of the expression represents a time after + * the first expiration. Verify that the timer does not start at the current + * year; it does not start at the start date; it should start at start + 1 + * year. For example, + * + * year=2009 - 2021 month=1 dayOfMonth=14 dayOfWeek=* hour=13 minute=51 + * second=50 start Wed Jan 14 13:51:51 EST 2015 + */ + public void startAfterActualValues() { + Calendar cal = Calendar.getInstance(); + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.SECOND, 10); + Date currentDatePlus10Sec = cal.getTime(); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date start = DateUtils.addYears(currentDatePlus10Sec, WAIT_YEARS); + start = DateUtils.addSeconds(start, 1); + exp.start(start); + exp.year((currentYear) + " - " + (currentYear + WAIT_YEARS * 2)); + + Timer timer = createTimer(exp); + int startYear = TimerUtil.getDateField(Calendar.YEAR, start); + Date expectedNextTimeout = DateUtils.setYears(currentDatePlus10Sec, + startYear + 1); + verifyNextTimeout(expectedNextTimeout, timer); + passIfNoTimeout(); + } + + /* + * @testName: startAfterActualValues2 + * + * @test_Strategy: the start attr of the expression represents a time after + * the first expiration. Verify that the timer does not start at the current + * year; it should start a little later after the start date. For example, + * + * year=2009 - 2021 month=1 dayOfMonth=20 dayOfWeek=* hour=10 minute=33 + * second=19 start Tue Jan 20 10:23:19 EST 2015 end null + */ + + public void startAfterActualValues2() { + int plusMinutes = 10; + Calendar cal = Calendar.getInstance(); + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + Date currentDate = cal.getTime(); + cal.add(Calendar.MINUTE, plusMinutes); + Date currentDatePlus = cal.getTime(); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + + // the start time (excluding year) is before the scheduled time + Date start = DateUtils.addYears(currentDate, WAIT_YEARS); + exp.start(start); + exp.year((currentYear) + " - " + (currentYear + WAIT_YEARS * 2)); + + Timer timer = createTimer(exp); + int startYear = TimerUtil.getDateField(Calendar.YEAR, start); + Date expectedNextTimeout = DateUtils.setYears(currentDatePlus, startYear); + verifyNextTimeout(expectedNextTimeout, timer); + passIfNoTimeout(); + } + + /* + * @testName: allDefaults + * + * @test_Strategy: create a no-arg ScheduleExpression, which should expire + * every year, every month, everyday, at 0:0:0 (midnight) + */ + public void allDefaults() { + ScheduleExpression exp = new ScheduleExpression(); + Timer timer = createTimer(exp); + + // the next timeout is tomorrow at 0:0:0 + Date expectedNextTimeout = Calendar.getInstance().getTime(); + expectedNextTimeout = DateUtils.addDays(expectedNextTimeout, 1); + expectedNextTimeout = DateUtils.truncate(expectedNextTimeout, + Calendar.DAY_OF_MONTH); + + verifyNextTimeout(expectedNextTimeout, timer); + scheduleBean.cancelTimer(timer); + } + + /* + * @testName: timerAccessInTimeoutMethod + * + * @test_Strategy: create a single-event scheduled timer, access timer methods + * in timeout method. + */ + public void timerAccessInTimeoutMethod() { + scheduleBean.cancelAllTimers(); + + @SuppressWarnings("unused") + // Timer timer = scheduleBean.createSecondLaterTimer(getTestName()); + Timer timer = scheduleBean.createSecondLaterTimer( + new TimerConfig(new TimerInfo(getTestName()), false), 2); + // ScheduleBean's superclass' timeout method may add a positive timeout + // record. But ScheduleBean's timeout method does additional verification, + // which may turn out to be negative. + TestUtil.sleepMsec((int) (WAIT_FOR_TIMEOUT_STATUS / 2)); + passIfTimeout(); + } + + /* + * @testName: cancelInTimeoutMethod + * + * @test_Strategy: create a recurring timer, cancel it in timeout method. + * There should be no more timeout event for this timer. There is only one + * timeout record. + */ + public void cancelInTimeoutMethod() { + Date end = TimerUtil.getCurrentDatePlus(Calendar.MINUTE, 5); + ScheduleExpression exp = new ScheduleExpression() + .second(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .minute(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .hour(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR).end(end); + // Timer timer = scheduleBean.createTimer(exp, getTestName()); + Timer timer = scheduleBean.createTimer(exp, + new TimerConfig(new TimerInfo(getTestName()), false)); + passIfTimeout(); + removeStatusAndRecords(); + appendReason(scheduleBean.passIfNoSuchObjectLocalException(timer)); + } + + /* + * @testName: leapYears + * + * @test_Strategy: Test 2/29 in 3 leap years (next next leapYear, 2104/2/29, + * 2104/2/last. For example, year=2013-2016 month=2 dayOfMonth=29 dayOfWeek=* + * hour=21 minute=15 second=31 start null end null expected nextTimeout Mon + * Feb 29 21:15:15 EST 2016 + * + * UTC timezone is used to create the test timers to avoid the hour difference + * between next timeout time and expected next time that may be caused by + * daylight time switch. For example, such difference could occur when running + * this test in mid March when US switched to daylight saving time, while the + * configured timer is set to expire on Feb 29 (in standard time) a few years + * later. + * See https://github.com/eclipse-ee4j/jakartaee-tck/issues/163 + */ + public void leapYears() { + scheduleBean.cancelAllTimers(); + int nextNextLeapYear = TimerUtil + .getNextLeapYear(TimerUtil.getNextLeapYear()); + int[] leapYears = { nextNextLeapYear, 2104, 2104 }; + String[] yearRange = { (leapYears[0] - 3) + "-" + leapYears[0], + (leapYears[1] - 6) + "-" + leapYears[1], String.valueOf(leapYears[2]) }; + String[] dayOfMonths = { "29, 29", "29, 29", "last, last" }; + + final TimeZone utc = TimeZone.getTimeZone("UTC"); + final Calendar cal = Calendar.getInstance(utc); + cal.set(Calendar.DAY_OF_MONTH, 1); + + for (int i = 0; i < leapYears.length; i++) { + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal) + .dayOfMonth(dayOfMonths[i]).month(2).year(yearRange[i]) + .timezone(utc.getID()); + + final Calendar cal2 = Calendar.getInstance(utc); + cal2.set(leapYears[i], Calendar.FEBRUARY, 29); + final Date expectedNextTimeout = cal2.getTime(); + + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + assertEquals("Check # of timers", 3, scheduleBean.getTimers().size()); + } + + /* + * @testName: dayOfMonth + * + * @test_Strategy: test dayOfMonth (1, , and "last") for the next month + */ + public void dayOfMonth() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MONTH, 1); + int lastDayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); + String[] dayOfMonths = { String.valueOf(1), String.valueOf(lastDayOfMonth), + "last, last" }; + int[] expectedDayOfMonths = { 1, lastDayOfMonth, lastDayOfMonth }; + dayOfMonth0(dayOfMonths, expectedDayOfMonths, cal); + } + + /* + * @testName: dayOfMonthNegative + * + * @test_Strategy: test dayOfMonth [-7, -1] + */ + public void dayOfMonthNegative() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MONTH, 1); + int lastDayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); + int[] dayOfMonthsInt = ScheduleValues.getSequenceIntArray(-7, -1); + String[] dayOfMonths = ScheduleValues.intArrayToStringArray(dayOfMonthsInt); + int[] expectedDayOfMonths = new int[dayOfMonths.length]; + for (int i = 0; i < expectedDayOfMonths.length; i++) { + expectedDayOfMonths[i] = lastDayOfMonth + dayOfMonthsInt[i]; + } + dayOfMonth0(dayOfMonths, expectedDayOfMonths, cal); + } + + /* + * @testName: dayOfMonthNthDayFeb + * + * @test_Strategy: test 1st Sun, 3rd Sat, etc, using Feb 2100 as a sample. + */ + public void dayOfMonthNthDayFeb() { + + // Calendar.getInstance() returns a lenient calendar based on the current + // date. + // When we modify it (setting month and year), also need to reset the + // day-of-month to a February-safe value. For example, when running this + // test + // on 2010-07-31, the modified calendar will be 2100-02-31 before resetting + // day-of-month, and Calendar.get(MONTH) will wrap the month value to March. + // Although the test sets the dayOfMonth field on schedule, the schedule + // month + // value is already set to an unexpected value. + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, 2100); + cal.set(Calendar.DAY_OF_MONTH, 1); + cal.set(Calendar.MONTH, Calendar.FEBRUARY); + + String[] dayOfMonths = { "1st Mon", "1st Tue", "1st Wed", "1st Thu", + "1st Fri", "1st Sat", "1st Sun", "2nd Mon", "2nd Tue", "2nd Wed", + "2nd Thu", "2nd Fri", "2nd Sat", "2nd Sun", "3rd Mon", "3rd Tue", + "3rd Wed", "3rd Thu", "3rd Fri", "3rd Sat", "3rd Sun", "4th Mon", + "4th Tue", "4th Wed", "4th Thu", "4th Fri", "4th Sat", "4th Sun" }; + int[] expectedDayOfMonths = ScheduleValues.getSequenceIntArray(1, 28); + dayOfMonth0(dayOfMonths, expectedDayOfMonths, cal); + dayOfMonths = null; + expectedDayOfMonths = null; + + String[] dayOfMonths2 = { "Last Mon", "Last Tue", "Last Wed", "Last Thu", + "Last Fri", "Last Sat", "Last Sun" }; + int[] expectedDayOfMonths2 = ScheduleValues.getSequenceIntArray(22, 28); + dayOfMonth0(dayOfMonths2, expectedDayOfMonths2, cal); + } + + /* + * @testName: dayOfMonthNthDayJan + * + * @test_Strategy: test 1st Sun, 3rd Sat, etc, using Jan 2100 as a sample. + */ + public void dayOfMonthNthDayJan() { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, 2100); + cal.set(Calendar.MONTH, Calendar.JANUARY); + String[] dayOfMonths = { "1st Fri-1st Mon", "1st Sat", "1st Sun", "1st Mon", + "1st Tue", "1st Wed", "1st Thu", "2nd Fri", "2nd Sat", "2nd Sun", + "2nd Mon", "2nd Tue", "2nd Wed", "2nd Thu", "3rd Fri", "3rd Sat", + "3rd Sun", "3rd Mon", "3rd Tue", "3rd Wed", "3rd Thu", "4th Fri", + "4th Sat", "4th Sun", "4th Mon", "4th Tue", "4th Wed", "4th Thu", + "5th Fri", "5th Sat-5th Sat", "5th Sun-Last Sun" }; + int[] expectedDayOfMonths = ScheduleValues.getSequenceIntArray(1, 31); + dayOfMonth0(dayOfMonths, expectedDayOfMonths, cal); + dayOfMonths = null; + expectedDayOfMonths = null; + + String[] dayOfMonths2 = { "Last Mon", "Last Tue", "Last Wed", "Last Thu", + "Last Fri", "Last Sat", "Last Sun, 5th Sun" }; + int[] expectedDayOfMonths2 = ScheduleValues.getSequenceIntArray(25, 31); + dayOfMonth0(dayOfMonths2, expectedDayOfMonths2, cal); + } + + /* + * @testName: dayOfWeekAll + * + * @test_Strategy: test dayOfWeek [0, 7], and ["Sun", "Sat"] The timer may + * expire once, twice, 3, or 4times. Check the first expiration + */ + public void dayOfWeekAll() { + Calendar cal = Calendar.getInstance(); + for (int i = 0; i < 7; i++) { + cal.add(Calendar.DAY_OF_WEEK, 1); + int targetDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + String[] targetDayOfWeeks = { String.valueOf(targetDayOfWeek), + ScheduleValues.dayOfWeekIntToString(targetDayOfWeek) }; + Date expectedNextTimeout = cal.getTime(); + dayOfWeek0(TimerUtil.getPreciseScheduleExpression(cal), + expectedNextTimeout, targetDayOfWeeks); + } + } + + /* + * @testName: dayOfWeekSunday + * + * @test_Strategy: test dayOfWeek 0, 7, and Sun are refers to Sunday + */ + public void dayOfWeekSunday() { + Calendar cal = Calendar.getInstance(); + int currentDayOfWeek = 0; + do { + cal.add(Calendar.DAY_OF_WEEK, 1); + currentDayOfWeek = cal.get(Calendar.DAY_OF_WEEK); + } while (currentDayOfWeek != Calendar.SUNDAY); + + Date nextSun = cal.getTime(); + dayOfWeek0(TimerUtil.getPreciseScheduleExpression(cal), nextSun, "0", "7", + "SUn"); + } + + /* + * @testName: dayOfWeekSunday0To7 + * + * @test_Strategy: create a schedule timer using dayOfWeek="0-7" to denote all + * dayOfWeeks. + */ + public void dayOfWeekSunday0To7() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.SECOND, 5); + Date expectedNextTimeout = cal.getTime(); + dayOfWeek0(TimerUtil.getPreciseScheduleExpression(cal), expectedNextTimeout, + "0-7"); + } + + /* + * @testName: dayOfWeekSunday2 + * + * @test_Strategy: test dayOfWeek Sun and start. start is set to the date + * after the next Sun. So the first expiration should be the next next Sun. + */ + public void dayOfWeekSunday2() { + Calendar cal = Calendar.getInstance(); + int currentDayOfWeek = 0; + do { + cal.add(Calendar.DAY_OF_WEEK, 1); + currentDayOfWeek = cal.get(Calendar.DAY_OF_WEEK); + } while (currentDayOfWeek != Calendar.SUNDAY); + + Date nextSun = cal.getTime(); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + cal.add(Calendar.DAY_OF_WEEK, 1); + exp = exp.start(cal.getTime()); + dayOfWeek0(exp, DateUtils.addDays(nextSun, 7), "7"); + } + + /* + * @testName: dayOfWeekNow + * + * @test_Strategy: test today's dayOfWeek, create a recurring timer that + * expires on this year, this month, and this dayOfWeek. + */ + public void dayOfWeekNow() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.SECOND, 10); + int targetDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + exp = exp.dayOfMonth(ScheduleValues.DEFAULT_ATTRIBUTE_VALUE_STAR) + .dayOfWeek(targetDayOfWeek); + + Timer timer = createTimer(exp); + int currentMonth = cal.get(Calendar.MONTH); + cal.add(Calendar.DAY_OF_WEEK, 7); + int nextWeekMonth = cal.get(Calendar.MONTH); + appendReason( + "currentMonth=" + currentMonth + ", nextWeekMonth=" + nextWeekMonth); + passIfTimeout(); + if (currentMonth == nextWeekMonth) { + // still in the same month 7 days later. So a 2nd expiration + Date expectedNextTimeout = cal.getTime(); + verifyNextTimeout(expectedNextTimeout, timer); + } else { + try { + Date nextTimeout = scheduleBean.getNextTimeout(timer); + throw new RuntimeException( + "Expecting EJBException, but got " + nextTimeout); + } catch (NoSuchObjectLocalException e) { + appendReason("Got the expected " + e); + } catch (NoMoreTimeoutsException e) { + appendReason("Got the expected " + e); + } catch (EJBException e) { + // after the first expiration, this timer may or may not have been + // removed + Throwable c = e.getCause(); + if (c instanceof NoSuchObjectLocalException + || c instanceof NoMoreTimeoutsException) { + appendReason("Got the (wrapped) expected " + c); + } else { + throw new RuntimeException( + "Expecting (wrapped) NoSuchObjectLocalException or NoMoreTimeoutsException, but actual " + + c); + } + } + } + } + + /* + * @testName: dayOfWeekList + * + * @test_Strategy: create a schedule timer using dayOfWeek= + * "dayAfter, dayBefore, today". It should expire in a few minutes. The order + * of the list elements is insignificant (the implementation needs to sort out + * the earliest possible element, rather than the first element). + */ + public void dayOfWeekList() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int currentDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + cal.add(Calendar.DAY_OF_WEEK, 1); + int nextDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + cal.add(Calendar.DAY_OF_WEEK, -2); + int previosDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + int[] dayOfWeeks = { nextDayOfWeek, previosDayOfWeek, currentDayOfWeek }; + String[] dayOfWeeksAsNumber = ScheduleValues + .intArrayToStringArray(dayOfWeeks); + String[] dayOfWeeksAsText = ScheduleValues.dayOfWeekIntToString(dayOfWeeks); + + dayOfWeek0(exp, expectedTimeout, StringUtils.join(dayOfWeeksAsNumber, ','), + StringUtils.join(dayOfWeeksAsText, ',')); + } + + /* + * @testName: dayOfWeekListComplex + * + * @test_Strategy: create a schedule timer using dayOfWeek= + * "nextDay-2DaysLater, 2DaysBack-1DayBack, today". It should expire in a few + * minutes. + */ + public void dayOfWeekListComplex() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.DAY_OF_WEEK, -3); // rewind to 3 days back + int[] dayOfWeeks = new int[5]; + for (int i = 0; i < dayOfWeeks.length; i++) { + cal.add(Calendar.DAY_OF_WEEK, 1); + dayOfWeeks[i] = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + } + String[] dayOfWeeksAsNumber = ScheduleValues + .intArrayToStringArray(dayOfWeeks); + String[] dayOfWeeksAsText = ScheduleValues.dayOfWeekIntToString(dayOfWeeks); + String[][] combinedDayOfWeeks = { dayOfWeeksAsNumber, dayOfWeeksAsText }; + + for (String[] days : combinedDayOfWeeks) { + // array index 0 1 2 3 4 + // dayOfWeek today-2 today-1 today today+1 today+2 + + String dayOfWeekVal = days[3] + "-" + days[4] + ", " + days[0] + "-" + + days[1] + ", " + days[2]; + dayOfWeek0(exp, expectedTimeout, dayOfWeekVal); + } + } + + /* + * @testName: dayOfWeekListOverlap + * + * @test_Strategy: create a schedule timer using dayOfWeek= + * "2DayBack-1DaysLater, 1DaysBack-2DaysLater". It should expire in a few + * minutes. This test is similar to dayOfWeekListComplex + */ + public void dayOfWeekListOverlap() { + // The following code is the same as in dayOfWeekListComplex + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.DAY_OF_WEEK, -3); // rewind to 3 days back + int[] dayOfWeeks = new int[5]; + for (int i = 0; i < dayOfWeeks.length; i++) { + cal.add(Calendar.DAY_OF_WEEK, 1); + dayOfWeeks[i] = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + } + String[] dayOfWeeksAsNumber = ScheduleValues + .intArrayToStringArray(dayOfWeeks); + String[] dayOfWeeksAsText = ScheduleValues.dayOfWeekIntToString(dayOfWeeks); + String[][] combinedDayOfWeeks = { dayOfWeeksAsNumber, dayOfWeeksAsText }; + + // The following code is different than dayOfWeekListComplex + for (String[] days : combinedDayOfWeeks) { + // array index 0 1 2 3 4 + // dayOfWeek today-2 today-1 today today+1 today+2 + + String dayOfWeekVal = days[0] + "-" + days[3] + ", " + days[1] + "-" + + days[4]; + dayOfWeek0(exp, expectedTimeout, dayOfWeekVal); + } + } + + /* + * @testName: dayOfWeekRange + * + * @test_Strategy: create a schedule timer using dayOfWeek= + * "prevPrevDay-today". It should expire in a few minutes. The range may wrap + * around (e.g., Sat-Mon) + */ + public void dayOfWeekRange() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int thisDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + cal.add(Calendar.DAY_OF_WEEK, -2); + int prevPrevDayOfWeek = TimerUtil.getForSchedule(Calendar.DAY_OF_WEEK, cal); + + String dayOfWeeksAsNumber = prevPrevDayOfWeek + "-" + thisDayOfWeek; + String dayOfWeeksAsText = ScheduleValues + .dayOfWeekIntToString(prevPrevDayOfWeek) + "-" + + ScheduleValues.dayOfWeekIntToString(thisDayOfWeek); + + dayOfWeek0(exp, expectedTimeout, dayOfWeeksAsNumber, dayOfWeeksAsText); + } + + /* + * @testName: monthList + * + * @test_Strategy: create a schedule timer using month= + * "monthAfter, monthBefore, thisMonth". It should expire in a few minutes. + * The order of the list elements is insignificant (the implementation needs + * to sort out the earliest possible element, rather than the first element). + */ + public void monthList() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int currentMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + cal.add(Calendar.MONTH, 1); + int nextMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + cal.add(Calendar.MONTH, -2); + int previosMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + int[] months = { nextMonth, previosMonth, currentMonth }; + String[] monthsAsNumber = ScheduleValues.intArrayToStringArray(months); + String[] monthsAsText = ScheduleValues.monthIntToString(months); + + month0(exp, expectedTimeout, StringUtils.join(monthsAsNumber, ','), + StringUtils.join(monthsAsText, ',')); + } + + /* + * @testName: monthRange + * + * @test_Strategy: create a schedule timer using month= + * "prevPrevMonth-thisMonth". It should expire in a few minutes. The range may + * wrap around (e.g., Dec-Feb) + */ + public void monthRange() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int thisMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + cal.add(Calendar.MONTH, -2); + int prevPrevMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + + String monthsAsNumber = prevPrevMonth + "-" + thisMonth; + String monthsAsText = ScheduleValues.monthIntToString(prevPrevMonth) + "-" + + ScheduleValues.monthIntToString(thisMonth); + month0(exp, expectedTimeout, monthsAsNumber, monthsAsText); + + monthsAsNumber = thisMonth + "-" + thisMonth; + monthsAsText = ScheduleValues.monthIntToString(thisMonth) + "-" + + ScheduleValues.monthIntToString(thisMonth); + month0(exp, expectedTimeout, monthsAsNumber, monthsAsText); + } + + /* + * @testName: monthListComplex + * + * @test_Strategy: create a schedule timer using month= + * "nextMonth-2MonthsLater, 2MonthsBack-1MonthBack, thisMonth". It should + * expire in a few minutes. + */ + public void monthListComplex() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.MONTH, -3); // rewind to 3 months back + int[] months = new int[5]; + for (int i = 0; i < months.length; i++) { + cal.add(Calendar.MONTH, 1); + months[i] = TimerUtil.getForSchedule(Calendar.MONTH, cal); + } + String[] monthsAsNumber = ScheduleValues.intArrayToStringArray(months); + String[] monthsAsText = ScheduleValues.monthIntToString(months); + + String[][] combinedMonths = { monthsAsNumber, monthsAsText }; + for (String[] m : combinedMonths) { + // array index 0 1 2 3 4 + // month -2 -1 current +1 +2 + + String monthVal = m[3] + "-" + m[4] + ", " + m[0] + "-" + m[1] + ", " + + m[2]; + month0(exp, expectedTimeout, monthVal); + } + } + + /* + * @testName: monthListOverlap + * + * @test_Strategy: create a schedule timer using month= + * "2MonthsBack-1MonthsLater, 1MonthsBack-2MonthsLater". It should expire in a + * few minutes. This test is similar to monthListComplex + */ + public void monthListOverlap() { + // The following code is the same as in dayOfWeekListComplex + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.MONTH, -3); // rewind to 3 months back + int[] months = new int[5]; + for (int i = 0; i < months.length; i++) { + cal.add(Calendar.MONTH, 1); + months[i] = TimerUtil.getForSchedule(Calendar.MONTH, cal); + } + String[] monthsAsNumber = ScheduleValues.intArrayToStringArray(months); + String[] monthsAsText = ScheduleValues.monthIntToString(months); + String[][] combinedMonths = { monthsAsNumber, monthsAsText }; + + // The following code is different than dayOfWeekListComplex + for (String[] m : combinedMonths) { + // array index 0 1 2 3 4 + // month -2 -1 current +1 +2 + + String monthVal = m[0] + "-" + m[3] + ", " + m[1] + "-" + m[4]; + month0(exp, expectedTimeout, monthVal); + } + } + + /* + * @testName: monthAll + * + * @test_Strategy: test the last day of each month [1,12; Jan-Dec] + */ + public void monthAll() { + Calendar cal = Calendar.getInstance(); + for (int i = 0; i < 24; i++) { + cal.add(Calendar.MONTH, 1); + int targetMonth = TimerUtil.getForSchedule(Calendar.MONTH, cal); + String[] targetMonths = { String.valueOf(targetMonth), + ScheduleValues.monthIntToString(targetMonth) }; + cal.set(Calendar.DAY_OF_MONTH, + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); + Date expectedNextTimeout = cal.getTime(); + for (String month : targetMonths) { + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal) + .month(month).dayOfMonth("last"); + Timer timer = createTimer(exp); + verifyNextTimeout(expectedNextTimeout, timer); + } + } + } + + /* + * @testName: yearList + * + * @test_Strategy: create a schedule timer using year= + * "yearAfter, yearBefore, thisYear". It should expire in a few minutes. The + * order of the list elements is insignificant (the implementation needs to + * sort out the earliest possible element, rather than the first element). + */ + public void yearList() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int currentYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.YEAR, 1); + int nextYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.YEAR, -2); + int previosYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + int[] years = { nextYear, previosYear, currentYear }; + String[] yearsAsNumber = ScheduleValues.intArrayToStringArray(years); + year0(exp, expectedTimeout, StringUtils.join(yearsAsNumber, ',')); + } + + /* + * @testName: yearRange + * + * @test_Strategy: create a schedule timer using year= + * "prevPrevYear-thisYear". It should expire in a few minutes. The range may + * wrap around (e.g., Dec-Feb) + */ + public void yearRange() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + int thisYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + cal.add(Calendar.YEAR, -2); + int prevPrevYear = TimerUtil.getForSchedule(Calendar.YEAR, cal); + + String yearsAsNumber = prevPrevYear + "-" + thisYear; + year0(exp, expectedTimeout, yearsAsNumber); + + yearsAsNumber = thisYear + "-" + thisYear; + year0(exp, expectedTimeout, yearsAsNumber); + } + + /* + * @testName: yearListComplex + * + * @test_Strategy: create a schedule timer using year= + * "nextYear-2YearsLater, 2YearsBack-1YearBack, thisYear". It should expire in + * a few minutes. + */ + public void yearListComplex() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.YEAR, -3); // rewind to 3 years back + int[] years = new int[5]; + for (int i = 0; i < years.length; i++) { + cal.add(Calendar.YEAR, 1); + years[i] = TimerUtil.getForSchedule(Calendar.YEAR, cal); + } + String[] yearsAsNumber = ScheduleValues.intArrayToStringArray(years); + // array index 0 1 2 3 4 + // year -2 -1 current +1 +2 + + String yearVal = yearsAsNumber[3] + "-" + yearsAsNumber[4] + ", " + + yearsAsNumber[0] + "-" + yearsAsNumber[1] + ", " + yearsAsNumber[2]; + year0(exp, expectedTimeout, yearVal); + } + + /* + * @testName: yearListOverlap + * + * @test_Strategy: create a schedule timer using year= + * "2YearsBack-1YearsLater, 1YearsBack-2YearsLater". It should expire in a few + * minutes. This test is similar to yearListComplex + */ + public void yearListOverlap() { + Calendar cal = TimerUtil.getCurrentCalendarPlus(Calendar.MINUTE, 5); + ScheduleExpression exp = TimerUtil.getPreciseScheduleExpression(cal); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.YEAR, -3); // rewind to 3 years back + int[] years = new int[5]; + for (int i = 0; i < years.length; i++) { + cal.add(Calendar.YEAR, 1); + years[i] = TimerUtil.getForSchedule(Calendar.YEAR, cal); + } + String[] yearsAsNumber = ScheduleValues.intArrayToStringArray(years); + + // array index 0 1 2 3 4 + // year -2 -1 current +1 +2 + + String yearVal = yearsAsNumber[0] + "-" + yearsAsNumber[3] + ", " + + yearsAsNumber[1] + "-" + yearsAsNumber[4]; + year0(exp, expectedTimeout, yearVal); + } + + /* + * @testName: incrementSecond1 + * + * @test_Strategy: + */ + public void incrementSecond1() { + incrementSecond0("*/10", 10 * 1000); + } + + /* + * @testName: incrementSecond2 + * + * @test_Strategy: + */ + public void incrementSecond2() { + incrementSecond0("0/10", 10 * 1000); + } + + /* + * @testName: incrementSecond3 + * + * @test_Strategy: + */ + public void incrementSecond3() { + incrementSecond0("25/35", 60 * 1000); + } + + /* + * @testName: incrementMinute1 + * + * @test_Strategy: start the incremental timer with start set to 1 minute + * before {10, 20, 30, etc}. + */ + public void incrementMinute1() { + String[] increments = { "*/10", "0/10" }; + for (String increment : increments) { + Calendar cal = Calendar.getInstance(); + int currentMinute = cal.get(Calendar.MINUTE); + do { + cal.add(Calendar.MINUTE, 1); + currentMinute = cal.get(Calendar.MINUTE); + } while (currentMinute % 10 != 0); + + cal.set(Calendar.SECOND, 0); + Date expectedTimeout = cal.getTime(); + cal.add(Calendar.MINUTE, -1); + cal.set(Calendar.SECOND, 1); + Date start = cal.getTime(); + incrementMinute0(increment, expectedTimeout, start); + } + } + + /* + * @testName: incrementMinute2 + * + * @test_Strategy: start the incremental timer with start set to 1 minute + * after 25 minute. Verify the first timeout is about 1 hour later, and minute + * 60 is not included (there is no minute 60). + */ + public void incrementMinute2() { + String increment = "25/35"; + Calendar cal = Calendar.getInstance(); + int currentMinute = cal.get(Calendar.MINUTE); + do { + cal.add(Calendar.MINUTE, 1); + currentMinute = cal.get(Calendar.MINUTE); + } while (currentMinute != 25); + + cal.add(Calendar.HOUR, 1); + cal.set(Calendar.SECOND, 0); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.HOUR, -1); + cal.add(Calendar.MINUTE, 1); + cal.set(Calendar.SECOND, 1); + Date start = cal.getTime(); + incrementMinute0(increment, expectedTimeout, start); + } + + /* + * @testName: incrementHour1 + * + * @test_Strategy: + */ + public void incrementHour1() { + String[] increments = { "*/3", "0/3" }; + for (String increment : increments) { + Calendar cal = Calendar.getInstance(); + int currentHour = cal.get(Calendar.HOUR); + do { + cal.add(Calendar.HOUR, 1); + currentHour = cal.get(Calendar.HOUR); + } while (currentHour % 3 != 0); + + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MINUTE, 0); + Date expectedTimeout = cal.getTime(); + cal.add(Calendar.MINUTE, -1); + cal.set(Calendar.SECOND, 1); + Date start = cal.getTime(); + incrementHour0(increment, expectedTimeout, start); + } + } + + /* + * @testName: incrementHour2 + * + * @test_Strategy: + */ + public void incrementHour2() { + String increment = "22/2"; + Calendar cal = Calendar.getInstance(); + int currentHour = cal.get(Calendar.HOUR_OF_DAY); + do { + cal.add(Calendar.HOUR_OF_DAY, 1); + currentHour = cal.get(Calendar.HOUR_OF_DAY); + } while (currentHour != 22); + + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + Date expectedTimeout = cal.getTime(); + + cal.add(Calendar.MINUTE, -1); + cal.set(Calendar.SECOND, 1); + Date start = cal.getTime(); + incrementHour0(increment, expectedTimeout, start); + } + +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/JsfClient.java new file mode 100644 index 0000000000..c3e9632936 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/annotated/JsfClient.java @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.expression.annotated; + +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; + +import jakarta.ejb.EJB; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + @EJB(beanName = "ScheduleBean") + private ScheduleBean scheduleBean; + + /* + * @testName: validSecondValuesInt + * + * @test_Strategy: verify valid int values are correctly processed. + */ + public void validSecondValuesInt() { + appendReason(scheduleBean.validSecondValuesInt()); + } + + /* + * @testName: validSecondValuesString + * + * @test_Strategy: verify valid String values are correctly processed. + */ + public void validSecondValuesString() { + appendReason(scheduleBean.validSecondValuesString()); + } + + /* + * @testName: validMinuteValuesInt + */ + public void validMinuteValuesInt() { + appendReason(scheduleBean.validMinuteValuesInt()); + } + + /* + * @testName: validMinuteValuesString + */ + public void validMinuteValuesString() { + appendReason(scheduleBean.validMinuteValuesString()); + } + + /* + * @testName: validHourValuesInt + */ + public void validHourValuesInt() { + appendReason(scheduleBean.validHourValuesInt()); + } + + /* + * @testName: validHourValuesString + */ + public void validHourValuesString() { + appendReason(scheduleBean.validHourValuesString()); + } + + /* + * @testName: validMonthValuesInt + */ + public void validMonthValuesInt() { + appendReason(scheduleBean.validMonthValuesInt()); + } + + /* + * @testName: validMonthValuesString + */ + public void validMonthValuesString() { + appendReason(scheduleBean.validMonthValuesString()); + } + + /* + * @testName: validYearValuesInt + */ + public void validYearValuesInt() { + appendReason(scheduleBean.validYearValuesInt()); + } + + /* + * @testName: validYearValuesString + */ + public void validYearValuesString() { + appendReason(scheduleBean.validYearValuesString()); + } + + /* + * @testName: validDayOfMonthValuesInt + */ + public void validDayOfMonthValuesInt() { + appendReason(scheduleBean.validDayOfMonthValuesInt()); + } + + /* + * @testName: validDayOfMonthValuesString + */ + public void validDayOfMonthValuesString() { + appendReason(scheduleBean.validDayOfMonthValuesString()); + } + + /* + * @testName: validDayOfWeekValuesInt + */ + public void validDayOfWeekValuesInt() { + appendReason(scheduleBean.validDayOfWeekValuesInt()); + } + + /* + * @testName: validDayOfWeekValuesString + */ + public void validDayOfWeekValuesString() { + appendReason(scheduleBean.validDayOfWeekValuesString()); + } + + /* + * @testName: invalidSecondValuesInt + */ + public void invalidSecondValuesInt() { + appendReason(scheduleBean.invalidSecondValuesInt()); + } + + /* + * @testName: invalidSecondValuesString + */ + public void invalidSecondValuesString() { + appendReason(scheduleBean.invalidSecondValuesString()); + } + + /* + * @testName: invalidMinuteValuesInt + */ + public void invalidMinuteValuesInt() { + appendReason(scheduleBean.invalidMinuteValuesInt()); + } + + /* + * @testName: invalidMinuteValuesString + */ + public void invalidMinuteValuesString() { + appendReason(scheduleBean.invalidMinuteValuesString()); + } + + /* + * @testName: invalidHourValuesInt + */ + public void invalidHourValuesInt() { + appendReason(scheduleBean.invalidHourValuesInt()); + } + + /* + * @testName: invalidHourValuesString + */ + public void invalidHourValuesString() { + appendReason(scheduleBean.invalidHourValuesString()); + } + + /* + * @testName: invalidMonthValuesInt + */ + public void invalidMonthValuesInt() { + appendReason(scheduleBean.invalidMonthValuesInt()); + } + + /* + * @testName: invalidMonthValuesString + */ + public void invalidMonthValuesString() { + appendReason(scheduleBean.invalidMonthValuesString()); + } + + /* + * @testName: invalidYearValuesInt + */ + public void invalidYearValuesInt() { + appendReason(scheduleBean.invalidYearValuesInt()); + } + + /* + * @testName: invalidYearValuesString + */ + public void invalidYearValuesString() { + appendReason(scheduleBean.invalidYearValuesString()); + } + + /* + * @testName: invalidDayOfMonthValuesInt + */ + public void invalidDayOfMonthValuesInt() { + appendReason(scheduleBean.invalidDayOfMonthValuesInt()); + } + + /* + * @testName: invalidDayOfMonthValuesString + */ + public void invalidDayOfMonthValuesString() { + appendReason(scheduleBean.invalidDayOfMonthValuesString()); + } + + /* + * @testName: invalidDayOfWeekValuesInt + */ + public void invalidDayOfWeekValuesInt() { + appendReason(scheduleBean.invalidDayOfWeekValuesInt()); + } + + /* + * @testName: invalidDayOfWeekValuesString + */ + public void invalidDayOfWeekValuesString() { + appendReason(scheduleBean.invalidDayOfWeekValuesString()); + } + + /* + * @testName: leapYear + * + * @test_Strategy: Create a timer with a valid leap year date, and cancel it. + */ + public void leapYear() { + appendReason(scheduleBean.leapYear()); + } + + /* + * @testName: attributeDefaults + * + * @test_Strategy: verify the default values 0 for second, minute, hour, and + * '*' for dayOfMonth, month, year, and dayOfWeek + */ + public void attributeDefaults() { + appendReason(scheduleBean.attributeDefaults()); + } + + /* + * @testName: dayOfMonthOverDayOfWeek + * + * @test_Strategy: If dayOfWeek has a wildcard value and dayOfMonth does not, + * the dayOfMonth attribute takes precedence and the dayOfWeek attribute is + * ignored. If dayOfMonth has a non-wildcard value and dayOfWeek has a + * non-wildcard value, both attributes apply. Typically, at most one of these + * two attributes will be specified to contain a non-wildcard value. + */ + public void dayOfMonthOverDayOfWeek() { + appendReason(scheduleBean.dayOfMonthOverDayOfWeek()); + passIfNoTimeout(); + } + + /* + * @testName: dayOfWeekOverDayOfMonth + * + * @test_Strategy: If dayOfMonth has a wildcard value and dayOfWeek does not, + * the dayOfWeek attribute takes precedence and the dayOfMonth attribute is + * ignored. + */ + public void dayOfWeekOverDayOfMonth() { + appendReason(scheduleBean.dayOfWeekOverDayOfMonth()); + passIfNoTimeout(); + } + + /* + * @testName: dayOfMonthAndDayOfWeek + * + * @test_Strategy: If dayOfMonth has a non-wildcard value and dayOfWeek has a + * non-wildcard value, both attributes apply. Typically, at most one of these + * two attributes will be specified to contain a non-wildcard value. + */ + public void dayOfMonthAndDayOfWeek() { + scheduleBean.cancelAllTimers(); + appendReason(scheduleBean.dayOfMonthAndDayOfWeek()); + passIfTimeout(); + } + + /* + * @testName: validStart + * + * @test_Strategy: verify various valid ScheduleExpression start value. + */ + public void validStart() { + scheduleBean.validStart(getReasonBuffer()); + } + + /* + * @testName: validEnd + * + * @test_Strategy:verify various valid ScheduleExpression end value. + */ + public void validEnd() { + scheduleBean.validEnd(getReasonBuffer()); + } + + /* + * @testName: validStartEnd + * + * @test_Strategy:verify ScheduleExpression with a stard and end value, + * supplied as java.util.Date + */ + public void validStartEnd() { + scheduleBean.validStartEnd(getReasonBuffer()); + scheduleBean.cancelAllTimers(); + } + + /* + * @testName: validTimeZone + * + * @test_Strategy:verify creating ScheduleExpression with timezone + */ + public void validTimeZone() { + scheduleBean.validTimeZone(getReasonBuffer()); + scheduleBean.cancelAllTimers(); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/JsfClient.java new file mode 100644 index 0000000000..9e87c414b7 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/expression/descriptor/JsfClient.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.expression.descriptor; + +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import jakarta.ejb.ScheduleExpression; +import jakarta.ejb.Timer; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + @EJB(beanName = "ScheduleBean") + private ScheduleBean scheduleBean; + + private void schedule0() { + ScheduleExpression exp = scheduleBean + .getSchedule(scheduleBean.findTimer(getTestName())); + appendReason("Found auto timer with schedule " + exp); + } + + /* + * @testName: defaultSchedule + * + * @test_Strategy: verify a auto timer declared in ejb-jar.xml with default + * values in schedule + */ + public void defaultSchedule() { + Timer t = scheduleBean.findTimer(getTestName()); + ScheduleExpression exp = scheduleBean.getSchedule(t); + TimerUtil.checkScheduleDefaults(exp, getReasonBuffer()); + } + + /* + * @testName: schedule1 + * + * @test_Strategy: verify a auto timer declared in ejb-jar.xml with various + * values in schedule + */ + public void schedule1() { + schedule0(); + } + + /* + * @testName: schedule2 + */ + public void schedule2() { + schedule0(); + } + + /* + * @testName: schedule3 + */ + public void schedule3() { + schedule0(); + } + + /* + * @testName: schedule4 + */ + public void schedule4() { + schedule0(); + } + +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java new file mode 100644 index 0000000000..b4b1e8f577 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.lifecycle; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import com.sun.ts.tests.ejb30.common.helper.Helper; +import com.sun.ts.tests.ejb30.timer.common.JsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; + +import jakarta.ejb.EJB; +import jakarta.ejb.NoSuchObjectLocalException; +import jakarta.ejb.ScheduleExpression; +import jakarta.ejb.Timer; +import jakarta.ejb.TimerConfig; +import jakarta.ejb.TimerHandle; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + + public static final String TIMER_STORE_DIR = System + .getProperty("java.io.tmpdir"); + + public static final String TIMER_STORE_NAME = "ts-ejb30-timer.ser"; + + public static final File TIMER_STORE = new File(TIMER_STORE_DIR, + TIMER_STORE_NAME); + + @EJB(beanName = "ScheduleBean") + private ScheduleBean scheduleBean; + + private void deleteTimerStore() { + if (TIMER_STORE.exists()) { + boolean deleted = TIMER_STORE.delete(); + if (deleted) { + Helper.getLogger().info("Deleted existing TIMER_STORE file: " + + TIMER_STORE.getAbsolutePath()); + } else { + Helper.getLogger().info( + "Failed to delete TIMER_STORE: " + TIMER_STORE.getAbsolutePath()); + } + } + } + + private void writeTimerHandle(TimerHandle handle) throws IOException { + ObjectOutputStream out = null; + try { + out = new ObjectOutputStream(new FileOutputStream(TIMER_STORE)); + out.writeObject(handle); + } finally { + if (out != null) { + out.close(); + } + } + } + + private TimerHandle readTimerHandle() + throws IOException, ClassNotFoundException { + ObjectInputStream in = null; + Object obj; + try { + in = new ObjectInputStream(new FileInputStream(TIMER_STORE)); + obj = in.readObject(); + } finally { + if (in != null) { + in.close(); + } + } + return (TimerHandle) obj; + } + + /* + * @testName: timerHandle + * + * @test_Strategy: verify Timer.getHandler(), pass it locally to web + * component, write it to disk, read it back, and compare it to the original + * one with Timer.equals(Object). Also verifies that calling Handle.getTimer() + * after the associated timer is cancelled will result in + * NoSuchObjectLocalException. + */ + public void timerHandle() throws IOException, ClassNotFoundException { + deleteTimerStore(); + Timer t = scheduleBean.findTimer(ScheduleBean.YEAR_5000); + TimerHandle handle = scheduleBean.getTimerHandle(t); + appendReason(" Got TimerHandle: " + handle); + writeTimerHandle(handle); + appendReason(" Serialized it to " + TIMER_STORE.getAbsolutePath()); + handle = readTimerHandle(); + appendReason(" Read it from TIMER_STORE "); + appendReason(scheduleBean.compareTimer(handle)); + + // TimerHandle.getTimer() in web tier is currently not allowed + // appendReason(scheduleBean.compareTimer(handle.getTimer())); + + scheduleBean.cancelTimer(handle); + appendReason(" Auto timer cancelled."); + assertEquals("Confirm the timer no long exists", null, + scheduleBean.findTimer(ScheduleBean.YEAR_5000)); + + // call handle.getTimer() after the associated timer has been cancelled, + // expecting NoSuchObjectLocalException + appendReason(scheduleBean.getTimerExpired(handle)); + } + + /* + * @testName: timerHandleIllegalStateException + * + * @test_Strategy: verify Timer.getHandler() throws IllegalStateException for + * non-persistent timers. + */ + public void timerHandleIllegalStateException() { + appendReason(scheduleBean.timerHandleIllegalStateException()); + } + + /* + * @testName: isCalendarTimerAndGetSchedule + * + * @test_Strategy: test isCalendarTimer for auto and programmatic timer, and + * getSchedule returns the schedule expression for calendar timer and throws + * IllegalStateException for non-calendar timer. + */ + public void isCalendarTimerAndGetSchedule() { + appendReason(scheduleBean.isCalendarTimerAndGetSchedule()); + } + + /* + * @testName: timerEquals + * + * @test_Strategy: test Timer.equals(Object) + */ + public void timerEquals() { + ScheduleExpression exp = new ScheduleExpression(); + // Timer t1 = scheduleBean.createSecondLaterTimer(t1Name); + // Timer t2 = scheduleBean.createFarFutureTimer(getTestName()); + Timer t2 = scheduleBean.createFarFutureTimer( + new TimerConfig(new TimerInfo(getTestName()), false)); + // Timer t3 = scheduleBean.createTimer(exp, getTestName()); + Timer t3 = scheduleBean.createTimer(exp, + new TimerConfig(new TimerInfo(getTestName()), false)); + // Timer t4 = scheduleBean.createTimer(exp, getTestName()); + Timer t4 = scheduleBean.createTimer(exp, + new TimerConfig(new TimerInfo(getTestName()), false)); + String t1Name = getTestName() + "t1"; + Timer t1 = scheduleBean + .createSecondLaterTimer(new TimerConfig(new TimerInfo(t1Name), false)); + Timer t1Found = scheduleBean.findTimer(t1Name); + assertEquals("Compare timer to itself.", t1, t1); + assertEquals("Compare timer to t1Found.", t1, t1Found); + assertNotEquals("Compare timer to null.", t1, null); + assertNotEquals("Compare timer to 1.", t1, 1); + assertNotEquals("Compare timer to true.", t1, true); + try{ + TimerHandle timerHandle = scheduleBean.getTimerHandle(t1); + assertNotEquals("Compare timer to TimerHandle.", t1, timerHandle); + assertNotEquals("Compare TimerHandle to timer.", timerHandle, t1); + } + catch (NoSuchObjectLocalException ex){ + ex.printStackTrace(); + } + assertNotEquals("Compare 2 timers.", t1, t2); + assertNotEquals("Compare timer 3 to timer 4.", t3, t4); + try { + scheduleBean.cancelTimer(t1, t2, t3, t4); + } + catch (NoSuchObjectLocalException ex){ + ex.printStackTrace(); + } + } + + /* + * @testName: createAndComplete + * + * @test_Strategy: create a timer and wait for its completion + */ + public void createAndComplete() { + // scheduleBean.createSecondLaterTimer(getTestName()); + scheduleBean.createSecondLaterTimer( + new TimerConfig(new TimerInfo(getTestName()), false)); + appendReason("Created a timer and wait for its completion."); + passIfTimeoutOnce(); + } + + /* + * @testName: completeAndNoSuchObjectLocalException + * + * @test_Strategy: after a timer completes, further access will result in + * jakarta.ejb.NoSuchObjectLocalException + */ + public void completeAndNoSuchObjectLocalException() { + // Timer t = scheduleBean.createSecondLaterTimer(getTestName()); + Timer t = scheduleBean.createSecondLaterTimer( + new TimerConfig(new TimerInfo(getTestName()), false)); + passIfTimeoutOnce(); + appendReason(scheduleBean.passIfNoSuchObjectLocalException(t)); + } + + /* + * @testName: cancelAndNoSuchObjectLocalException + * + * @test_Strategy: after a timer cancellation, further access will result in + * jakarta.ejb.NoSuchObjectLocalException + */ + public void cancelAndNoSuchObjectLocalException() { + // Timer t = scheduleBean.createFarFutureTimer(getTestName()); + Timer t = scheduleBean.createFarFutureTimer( + new TimerConfig(new TimerInfo(getTestName()), false)); + scheduleBean.cancelTimerWithNoTransaction(t); + appendReason(scheduleBean.passIfNoSuchObjectLocalException(t)); + } + + /* + * @testName: cancelWithTxAndNoSuchObjectLocalException + * + * @test_Strategy: after a timer cancellation within a tx context, further + * access will result in jakarta.ejb.NoSuchObjectLocalException + */ + public void cancelWithTxAndNoSuchObjectLocalException() { + // Timer t = scheduleBean.createFarFutureTimer(getTestName()); + Timer t = scheduleBean.createFarFutureTimer( + new TimerConfig(new TimerInfo(getTestName()), false)); + scheduleBean.cancelTimer(t); // cancel with default tx context in EJB + appendReason(scheduleBean.passIfNoSuchObjectLocalException(t)); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java new file mode 100644 index 0000000000..b329b46489 --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.tx; + +import jakarta.ejb.EJB; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + + @EJB(beanInterface = ScheduleBean.class, beanName = "ScheduleBean") + protected void setScheduleBean(ScheduleTxBeanBase b) { + scheduleBean = b; + } + + @EJB(beanInterface = ScheduleBMTBean.class, beanName = "ScheduleBMTBean") + protected void setScheduleBMTBean(ScheduleTxBeanBase b) { + scheduleBMTBean = b; + } + + /* + * @testName: createRollback + * + * @test_Strategy: create a timer that is to expire in 1 second, and 1.5 + * seconds later, set the transaction to rollback only. The timer must not be + * present, and no timeout event for this timer. + */ + /* + * @testName: createRollbackBMT + * + * @test_Strategy: same as above, but using BMT + */ + /* + * @testName: createRollbackTxPropagation + * + * @test_Strategy: Inside propagated transaction, create a timer that is to + * expire in 2 seconds. The client transaction is rolled back. The timer must + * not be present, and no timeout event for this timer. + */ + /* + * @testName: createRollbackTxPropagationBMT + * + * @test_Strategy: See above. But for BMT, no tx propagation. + */ + /* + * @testName: cancelRollback + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer, and then set the tx to + * rollback. This timer must still be present, and has not yet expired. These + * business methods have default transaction attribute type (REQUIRED) + */ + /* + * @testName: cancelRollbackBMT + * + * @test_Strategy: See above. Using BMT + */ + /* + * @testName: cancelRollbackPropagation + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer within a client-initiated tx. + * The client tx is rolled back. This timer must still be present, and has not + * yet expired. These business methods have default transaction attribute type + * (REQUIRED) + */ + /* + * @testName: cancelRollbackPropagationBMT + * + * @test_Strategy: See above. No propagation for BMT + */ + /* + * @testName: timeoutRollback + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * method sets rollback for this timeout event. This event must be retried at + * least once. The timeout method has default transaction attribute type + * (REQUIRED) + */ + /* + * @testName: timeoutSystemException + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. The + * timeout method has default transaction attribute type (REQUIRED) + */ + /* + * @testName: timeoutSystemExceptionBMT + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. + */ + /* + * @testName: createTimerWithoutTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. + */ + /* + * @testName: createTimerWithoutTxHavingClientTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. The + * client does have a UserTransaction but it is not propagated. + */ +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClientBase.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClientBase.java new file mode 100644 index 0000000000..0ce8694dfb --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClientBase.java @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.tx; + +import java.util.List; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; + +import jakarta.annotation.Resource; +import jakarta.ejb.Timer; +import jakarta.ejb.TimerConfig; +import jakarta.transaction.UserTransaction; + +/** + * These tests make use of UserTransaction, and therefore all the hosting + * vehicles must support UserTransaction. OK with jsf bean, jsp, and servlet, + * but servlet filter and webapp listeners do not. + */ +abstract public class JsfClientBase + extends com.sun.ts.tests.ejb30.timer.common.JsfClientBase { + + protected ScheduleTxBeanBase scheduleBean; // OK to use supertype + + protected ScheduleTxBeanBase scheduleBMTBean; + + @Resource + private UserTransaction ut; + + protected TimerConfig getTimerConfig() { + // TimerConfig timerConfig = new TimerConfig(new TimerInfo(getTestName()), + // true); + TimerConfig timerConfig = new TimerConfig(new TimerInfo(getTestName()), + false); + return timerConfig; + } + + /* + * testName: createRollback + * + * @test_Strategy: create a timer that is to expire in 1 second, and 1.5 + * seconds later, set the transaction to rollback only. The timer must not be + * present, and no timeout event for this timer. + */ + public void createRollback() { + createRollback(scheduleBean); + } + + /* + * testName: createRollbackBMT + * + * @test_Strategy: same as above, but using BMT + */ + public void createRollbackBMT() { + createRollback(scheduleBMTBean); + } + + /* + * testName: createRollbackTxPropagation + * + * @test_Strategy: Inside propagated transaction, create a timer that is to + * expire in 2 seconds. The client transaction is rolled back. The timer must + * not be present, and no timeout event for this timer. + */ + + public void createRollbackTxPropagation() throws Exception { + ut.begin(); + Timer timer = scheduleBean.createSecondLaterTimer(getTimerConfig(), 2); + TestUtil.sleep(3000); // 3 seconds + ut.rollback(); + assertEquals("contains the timer? " + timer, false, + scheduleBean.getTimers().contains(timer)); + passIfNoTimeout(); + } + + /* + * testName: createRollbackTxPropagationBMT + * + * @test_Strategy: See above. But for BMT, no tx propagation. + */ + + public void createRollbackTxPropagationBMT() throws Exception { + ut.begin(); + scheduleBMTBean.createSecondLaterTimer(getTimerConfig(), 2); + TestUtil.sleep(3000); // 3 seconds + ut.rollback(); + passIfTimeout(); + } + + /* + * testName: cancelRollback + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer, and then set the tx to + * rollback. This timer must still be present, and has not yet expired. These + * business methods have default transaction attribute type (REQUIRED) + */ + public void cancelRollback() { + cancelRollback(scheduleBean); + } + + /* + * testName: cancelRollbackBMT + * + * @test_Strategy: See above. Using BMT + */ + public void cancelRollbackBMT() { + cancelRollback(scheduleBMTBean); + } + + /* + * testName: cancelRollbackPropagation + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer within a client-initiated tx. + * The client tx is rolled back. This timer must still be present, and has not + * yet expired. These business methods have default transaction attribute type + * (REQUIRED) + */ + public void cancelRollbackPropagation() throws Exception { + Timer timer = scheduleBean.createFarFutureTimer(getTimerConfig()); + String result = "This timer must still be present, since the tx " + + "within which cancellation occurs is rolled back: " + timer; + ut.begin(); + scheduleBean.cancelTimer(timer); + ut.rollback(); + assertEquals(result, true, scheduleBean.getTimers().contains(timer)); + scheduleBean.cancelTimer(timer); + assertEquals("contains the timer? " + timer, false, + scheduleBean.getTimers().contains(timer)); + } + + /* + * testName: cancelRollbackPropagationBMT + * + * @test_Strategy: See above. No propagation for BMT + */ + public void cancelRollbackPropagationBMT() throws Exception { + Timer timer = scheduleBMTBean.createSecondLaterTimer(getTimerConfig()); + String result = "This timer must not be present, since the tx is not " + + "propagated to BMT bean: " + timer; + ut.begin(); + scheduleBMTBean.cancelTimer(timer); // really cancel it + ut.rollback(); + assertEquals(result, false, scheduleBMTBean.getTimers().contains(timer)); + } + + /* + * testName: timeoutRollback + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * method sets rollback for this timeout event. This event must be retried at + * least once. This only applies to CMT, not BMT. The timeout method has + * default transaction attribute type (REQUIRED) + */ + public void timeoutRollback() { + timeoutRollback(scheduleBean); + } + + /* + * testName: timeoutSystemException + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. The + * timeout method has default transaction attribute type (REQUIRED) + */ + public void timeoutSystemException() { + timeoutRollback(); + } + + /* + * testName: timeoutSystemExceptionBMT + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. + */ + public void timeoutSystemExceptionBMT() { + timeoutRollback(scheduleBMTBean); + } + + /* + * testName: createTimerWithoutTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. + */ + public void createTimerWithoutTx() { + scheduleBMTBean.createSecondLaterTimer(getTimerConfig(), 2); + passIfTimeout(); + } + + /* + * testName: createTimerWithoutTxHavingClientTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. The + * client does have a UserTransaction but it is not propagated. + */ + public void createTimerWithoutTxHavingClientTx() throws Exception { + ut.begin(); + scheduleBMTBean.createSecondLaterTimer(getTimerConfig(), 2); + ut.commit(); + passIfTimeout(); + } + + private void createRollback(ScheduleTxBeanBase b) { + String result = b.createRollback(getTimerConfig()); + appendReason(result); + passIfNoTimeout(); + } + + private void cancelRollback(ScheduleTxBeanBase b) { + Timer timer = b.createFarFutureTimer(getTimerConfig()); + String result = b.cancelRollback(getTestName()); + assertEquals(result, true, b.getTimers().contains(timer)); + b.cancelTimer(timer); // really cancel it + passIfNoTimeout(); + } + + private void timeoutRollback(ScheduleTxBeanBase b) { + appendReason( + "If the transaction rolls back in timeout method, must retry at least once."); + Timer timer = b.createSecondLaterTimer(getTimerConfig(), 2); + TestUtil.sleep((int) WAIT_FOR_TIMEOUT_STATUS); + List a = statusSingleton.getRecords(getTestName()); + appendReason("timeout callback result: ", a); + assertGreaterThan(null, a.size(), 1); + + // Containers may retry failed timeout method once or multiple times. + // The original timer may or may not exist at this point. So do not + // check for its existence. + // assertEquals(null, false, b.getTimers().contains(timer)); + } +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java new file mode 100644 index 0000000000..a5d8d4045f --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.lite.timer.schedule.txnonpersistent; + +import com.sun.ts.tests.ejb32.lite.timer.schedule.tx.JsfClientBase; +import com.sun.ts.tests.ejb32.lite.timer.schedule.tx.ScheduleTxBeanBase; + +import jakarta.ejb.EJB; +import jakarta.ejb.TimerConfig; + +@jakarta.inject.Named("client") +@jakarta.enterprise.context.RequestScoped +public class JsfClient extends JsfClientBase { + + @EJB(beanInterface = ScheduleBean.class, beanName = "txnonpersistent-ScheduleBean") + protected void setScheduleBean(ScheduleTxBeanBase b) { + scheduleBean = b; + } + + @EJB(beanInterface = ScheduleBMTBean.class, beanName = "txnonpersistent-ScheduleBMTBean") + protected void setScheduleBMTBean(ScheduleTxBeanBase b) { + scheduleBMTBean = b; + } + + @Override + protected TimerConfig getTimerConfig() { + TimerConfig timerConfig = super.getTimerConfig(); + timerConfig.setPersistent(false); + return timerConfig; + } + + /* + * @testName: createRollback + * + * @test_Strategy: create a timer that is to expire in 1 second, and 1.5 + * seconds later, set the transaction to rollback only. The timer must not be + * present, and no timeout event for this timer. + */ + /* + * @testName: createRollbackBMT + * + * @test_Strategy: same as above, but using BMT + */ + /* + * @testName: createRollbackTxPropagation + * + * @test_Strategy: Inside propagated transaction, create a timer that is to + * expire in 2 seconds. The client transaction is rolled back. The timer must + * not be present, and no timeout event for this timer. + */ + /* + * @testName: createRollbackTxPropagationBMT + * + * @test_Strategy: See above. But for BMT, no tx propagation. + */ + /* + * @testName: cancelRollback + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer, and then set the tx to + * rollback. This timer must still be present, and has not yet expired. These + * business methods have default transaction attribute type (REQUIRED) + */ + /* + * @testName: cancelRollbackBMT + * + * @test_Strategy: See above. Using BMT + */ + /* + * @testName: cancelRollbackPropagation + * + * @test_Strategy: create a timer that is to expire in the far future. The + * subsequent business method cancels the timer within a client-initiated tx. + * The client tx is rolled back. This timer must still be present, and has not + * yet expired. These business methods have default transaction attribute type + * (REQUIRED) + */ + /* + * @testName: cancelRollbackPropagationBMT + * + * @test_Strategy: See above. No propagation for BMT + */ + /* + * @testName: timeoutRollback + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * method sets rollback for this timeout event. This event must be retried at + * least once. The timeout method has default transaction attribute type + * (REQUIRED) + */ + /* + * @testName: timeoutSystemException + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. The + * timeout method has default transaction attribute type (REQUIRED) + */ + /* + * @testName: timeoutSystemExceptionBMT + * + * @test_Strategy: create a timer that is to expire in 2 seconds. The timeout + * throws system exception. This event must be retried at least once. + */ + /* + * @testName: createTimerWithoutTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. + */ + /* + * @testName: createTimerWithoutTxHavingClientTx + * + * @test_Strategy: invoke the BMT bean to create a timer without tx. The + * client does have a UserTransaction but it is not propagated. + */ +} diff --git a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/build.xml b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/build.xml index df41662d48..f6f8e1a016 100644 --- a/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/build.xml +++ b/src/com/sun/ts/tests/ejb32/lite/timer/schedule/txnonpersistent/build.xml @@ -25,6 +25,7 @@ diff --git a/src/com/sun/ts/tests/ejb32/timer/service/common/JsfClientBase.java b/src/com/sun/ts/tests/ejb32/timer/service/common/JsfClientBase.java new file mode 100644 index 0000000000..ea25a02fec --- /dev/null +++ b/src/com/sun/ts/tests/ejb32/timer/service/common/JsfClientBase.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.ejb32.timer.service.common; + +import java.util.Calendar; +import java.util.Collection; + +import com.sun.ts.tests.ejb30.common.lite.EJBLiteJsfClientBase; +import com.sun.ts.tests.ejb30.timer.common.TimerInfo; +import com.sun.ts.tests.ejb30.timer.common.TimerUtil; + +import jakarta.ejb.EJB; +import jakarta.ejb.ScheduleExpression; +import jakarta.ejb.Timer; +import jakarta.ejb.TimerConfig; + +abstract public class JsfClientBase extends EJBLiteJsfClientBase { + private static final long ONE_HOUR_MILLIS = 60 * 60 * 1000; + + @EJB(beanName = "TimersSingletonBean") + protected TimerIF singletonBean; + + @EJB(beanName = "TimersStatelessBean") + protected TimerIF statelessBean; + + @EJB(beanName = "NoTimersStatefulBean") + protected TimerIF statefulBean; + + protected TimerIF clientBean; + + protected int autoTimerCount = 0; + + protected boolean ejbLite = false; + + private int programmaticTimerCount = 0; + + protected void createTimersProgrammatically(boolean persistent) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.HOUR, 1); // next hour + ScheduleExpression se = TimerUtil.getPreciseScheduleExpression(cal); + + singletonBean.createTimer(TimerUtil.getCurrentDatePlus(Calendar.HOUR, 1), + newTimerConfig(persistent)); + singletonBean.createTimer(TimerUtil.getCurrentDatePlus(Calendar.HOUR, 1), + ONE_HOUR_MILLIS, newTimerConfig(persistent)); + singletonBean.createTimer(ONE_HOUR_MILLIS, newTimerConfig(persistent)); + singletonBean.createTimer(ONE_HOUR_MILLIS, ONE_HOUR_MILLIS, + newTimerConfig(persistent)); + singletonBean.createTimer(se, newTimerConfig(persistent)); + + statelessBean.createTimer(TimerUtil.getCurrentDatePlus(Calendar.HOUR, 1), + newTimerConfig(persistent)); + statelessBean.createTimer(TimerUtil.getCurrentDatePlus(Calendar.HOUR, 1), + ONE_HOUR_MILLIS, newTimerConfig(persistent)); + statelessBean.createTimer(ONE_HOUR_MILLIS, newTimerConfig(persistent)); + statelessBean.createTimer(ONE_HOUR_MILLIS, ONE_HOUR_MILLIS, + newTimerConfig(persistent)); + statelessBean.createTimer(se, newTimerConfig(persistent)); + } + + private TimerConfig newTimerConfig(boolean persistent) { + TimerInfo ti = new TimerInfo(Integer.toString(programmaticTimerCount++)); + return new TimerConfig(ti, persistent); + } + + protected void passIfAllTimersRetrieved(Collection allTimers) { + assertEquals("Check the count of Timer objects retrieved is correct", + programmaticTimerCount + autoTimerCount, allTimers.size()); + checkTimersIndexedByInfo(allTimers, programmaticTimerCount, false); + checkTimersIndexedByInfo(allTimers, autoTimerCount, true); + } + + private void checkTimersIndexedByInfo(Collection allTimers, int count, + boolean auto) { + for (int i = 0; i < count; i++) { + Timer t = TimerUtil.findTimer(allTimers, + new TimerInfo((auto ? "a" : "") + i)); + assertNotEquals("Check Timer object retrieved not null", null, t); + } + } + + public void testGetAllTimers() { + if (!ejbLite) { + createTimersProgrammatically(true); + } + createTimersProgrammatically(false); + passIfAllTimersRetrieved(clientBean.getAllTimers()); + } +} From 5583db58216a6188b4f4397b1925646645478cd2 Mon Sep 17 00:00:00 2001 From: Alwin Joseph <44426046+alwin-joseph@users.noreply.github.com> Date: Wed, 11 May 2022 23:27:03 +0530 Subject: [PATCH 2/2] update copyright years --- src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java | 2 +- src/com/sun/ts/tests/ejb30/timer/common/build-import.xml | 2 +- .../timer/interceptor/aroundtimeout/common/JsfClientBase.java | 2 +- .../ts/tests/ejb32/lite/timer/basic/concurrency/JsfClient.java | 2 +- .../sun/ts/tests/ejb32/lite/timer/basic/sharing/JsfClient.java | 2 +- src/com/sun/ts/tests/ejb32/lite/timer/basic/sharing/build.xml | 2 +- src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/JsfClient.java | 2 +- src/com/sun/ts/tests/ejb32/lite/timer/basic/xa/build.xml | 2 +- .../aroundtimeout/singleton/annotated/JsfClient.java | 2 +- .../interceptor/aroundtimeout/singleton/annotated/build.xml | 2 +- .../interceptor/aroundtimeout/singleton/dual/JsfClient.java | 2 +- .../lite/timer/interceptor/business/common/JsfClientBase.java | 2 +- .../lite/timer/interceptor/business/singleton/JsfClient.java | 2 +- .../ejb32/lite/timer/interceptor/business/singleton/build.xml | 2 +- .../lite/timer/interceptor/business/stateless/JsfClient.java | 2 +- .../ejb32/lite/timer/interceptor/business/stateless/build.xml | 2 +- .../lite/timer/interceptor/lifecycle/singleton/JsfClient.java | 2 +- .../lite/timer/schedule/descriptor/stateless/JsfClient.java | 2 +- .../ts/tests/ejb32/lite/timer/schedule/expire/JsfClient.java | 2 +- .../lite/timer/schedule/expression/annotated/JsfClient.java | 2 +- .../lite/timer/schedule/expression/descriptor/JsfClient.java | 2 +- .../ts/tests/ejb32/lite/timer/schedule/lifecycle/JsfClient.java | 2 +- .../sun/ts/tests/ejb32/lite/timer/schedule/tx/JsfClient.java | 2 +- .../ts/tests/ejb32/lite/timer/schedule/tx/JsfClientBase.java | 2 +- .../ejb32/lite/timer/schedule/txnonpersistent/JsfClient.java | 2 +- .../tests/ejb32/lite/timer/schedule/txnonpersistent/build.xml | 2 +- .../sun/ts/tests/ejb32/lite/timer/schedule/tz/JsfClient.java | 2 +- src/com/sun/ts/tests/ejb32/lite/timer/schedule/tz/build.xml | 2 +- .../ts/tests/ejb32/lite/timer/service/singleton/JsfClient.java | 2 +- .../sun/ts/tests/ejb32/lite/timer/service/singleton/build.xml | 2 +- .../ts/tests/ejb32/lite/timer/service/stateless/JsfClient.java | 2 +- .../sun/ts/tests/ejb32/lite/timer/service/stateless/build.xml | 2 +- .../sun/ts/tests/ejb32/lite/timer/timerconfig/JsfClient.java | 2 +- src/com/sun/ts/tests/ejb32/lite/timer/timerconfig/build.xml | 2 +- .../sun/ts/tests/ejb32/timer/service/common/JsfClientBase.java | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java b/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java index ec8d1bed42..39d4dab8d8 100644 --- a/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java +++ b/src/com/sun/ts/tests/ejb30/timer/common/JsfClientBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml b/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml index c76d5210e6..86d98ca610 100644 --- a/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml +++ b/src/com/sun/ts/tests/ejb30/timer/common/build-import.xml @@ -1,7 +1,7 @@