Search in sources :

Example 1 with CalendarTimerData

use of org.apache.openejb.core.timer.CalendarTimerData in project tomee by apache.

the class EjbTimerImplSerializableTest method timerData.

public static CalendarTimerData timerData() throws Exception {
    final BeanContext context = SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext("EJBWithTimer");
    final EjbTimerService timer = context.getEjbTimerService();
    final MethodContext ctx = context.getMethodContext(EJBWithTimer.class.getMethod("doSthg"));
    final ScheduleData sd = ctx.getSchedules().iterator().next();
    return new CalendarTimerData(1, (EjbTimerServiceImpl) timer, context.getDeploymentID().toString(), null, ctx.getBeanMethod(), sd.getConfig(), sd.getExpression(), false);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) CalendarTimerData(org.apache.openejb.core.timer.CalendarTimerData) ScheduleData(org.apache.openejb.core.timer.ScheduleData) MethodContext(org.apache.openejb.MethodContext) EjbTimerService(org.apache.openejb.core.timer.EjbTimerService)

Example 2 with CalendarTimerData

use of org.apache.openejb.core.timer.CalendarTimerData in project tomee by apache.

the class EjbTimerImplSerializableTest method jobDataMapSerial.

@Test
public void jobDataMapSerial() throws Exception {
    final CalendarTimerData data = timerData();
    final EjbTimerServiceImpl timerService = (EjbTimerServiceImpl) timerService();
    data.setScheduler(timerService.getScheduler());
    // small hack for the test
    final Field preventSynch = TimerData.class.getDeclaredField("synchronizationRegistered");
    preventSynch.setAccessible(true);
    preventSynch.set(data, true);
    data.newTimer();
    final AbstractTrigger<?> trigger = (AbstractTrigger<?>) data.getTrigger();
    trigger.setJobName("my-job");
    trigger.setJobGroup("my-group");
    final JobDataMap triggerDataMap = trigger.getJobDataMap();
    triggerDataMap.put(EjbTimeoutJob.EJB_TIMERS_SERVICE, timerService);
    triggerDataMap.put(EjbTimeoutJob.TIMER_DATA, data);
    final byte[] serial = serialize(triggerDataMap);
    final JobDataMap map = (JobDataMap) deserialize(serial);
    assertTrue(map.containsKey(EjbTimeoutJob.EJB_TIMERS_SERVICE));
    assertTrue(map.containsKey(EjbTimeoutJob.TIMER_DATA));
}
Also used : CalendarTimerData(org.apache.openejb.core.timer.CalendarTimerData) Field(java.lang.reflect.Field) JobDataMap(org.apache.openejb.quartz.JobDataMap) AbstractTrigger(org.apache.openejb.quartz.impl.triggers.AbstractTrigger) EjbTimerServiceImpl(org.apache.openejb.core.timer.EjbTimerServiceImpl) Test(org.junit.Test)

Example 3 with CalendarTimerData

use of org.apache.openejb.core.timer.CalendarTimerData in project tomee by apache.

the class EjbTimerImplSerializableTest method serializationOfCalendarData.

@Test
public void serializationOfCalendarData() throws Exception {
    final CalendarTimerData data = timerData();
    final byte[] serial = serialize(data);
    final CalendarTimerData dataDeserialized = (CalendarTimerData) deserialize(serial);
    assertThat(dataDeserialized, instanceOf(CalendarTimerData.class));
    assertEqualsByReflection(data, dataDeserialized, "id");
    assertEqualsByReflection(data, dataDeserialized, "deploymentId");
    assertEqualsByReflection(data, dataDeserialized, "timeoutMethod");
    assertEqualsByReflection(data, dataDeserialized, "info");
}
Also used : CalendarTimerData(org.apache.openejb.core.timer.CalendarTimerData) Test(org.junit.Test)

Aggregations

CalendarTimerData (org.apache.openejb.core.timer.CalendarTimerData)3 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 BeanContext (org.apache.openejb.BeanContext)1 MethodContext (org.apache.openejb.MethodContext)1 EjbTimerService (org.apache.openejb.core.timer.EjbTimerService)1 EjbTimerServiceImpl (org.apache.openejb.core.timer.EjbTimerServiceImpl)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1 JobDataMap (org.apache.openejb.quartz.JobDataMap)1 AbstractTrigger (org.apache.openejb.quartz.impl.triggers.AbstractTrigger)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1