EJBTimerScheduler { public TimerJobInstance getTimerByName(String jobName) { if (USE_LOCAL_CACHE) { if (localCache.containsKey(jobName)) { logger.debug("Found job {} in cache returning", jobName); return localCache.get(jobName); } } TimerJobInstance found = null; for (Timer timer : timerService.getTimers()) { try { Serializable info = timer.getInfo(); if (info instanceof EjbTimerJob) { EjbTimerJob job = (EjbTimerJob) info; EjbGlobalJobHandle handle = (EjbGlobalJobHandle) job.getTimerJobInstance().getJobHandle(); if (handle.getUuid().equals(jobName)) { found = handle.getTimerJobInstance(); if (USE_LOCAL_CACHE) { localCache.putIfAbsent(jobName, found); } logger.debug("Job {} does match timer and is going to be returned {}", jobName, found); break; } } } catch (NoSuchObjectLocalException e) { logger.debug("Timer info for {} was not found ", timer); } } return found; }  @PostConstruct void setup(); @Timeout void executeTimerJob(Timer timer); void internalSchedule(TimerJobInstance timerJobInstance); boolean removeJob(JobHandle jobHandle); TimerJobInstance getTimerByName(String jobName);  }
@Test public void testEjbTimerSchedulerTestOnTimerLoop() { Collection<Timer> timers = new ArrayList<>(); TimerService timerService = mock(TimerService.class); when(timerService.getTimers()).thenReturn(timers); TimerJobInstance timerJobInstance1 = mock(TimerJobInstance.class); EjbGlobalJobHandle ejbGlobalJobHandle1 = new EjbGlobalJobHandle(1L, "test job", "test"); ejbGlobalJobHandle1.setTimerJobInstance(timerJobInstance1); when(timerJobInstance1.getJobHandle()).thenReturn(ejbGlobalJobHandle1); Timer timer1 = mock(Timer.class); when(timer1.getInfo()).thenReturn(new EjbTimerJob(timerJobInstance1)); timers.add(timer1); EJBTimerScheduler scheduler = new EJBTimerScheduler(); scheduler.timerService = timerService; TimerJobInstance jobInstance = scheduler.getTimerByName("not existing"); assertNull(jobInstance); jobInstance = scheduler.getTimerByName("not existing"); assertNull(jobInstance); jobInstance = scheduler.getTimerByName("test job"); assertNotNull(jobInstance); }