SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override public List<ExtendedEventDto> getKnownRecordings() throws SchedulerServiceDatabaseException { final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.knownRecordings") .setParameter("org", securityService.getOrganization().getId()); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } }  void setEntityManagerFactory(EntityManagerFactory emf); void setSecurityService(SecurityService securityService); void activate(ComponentContext cc); @Override synchronized void touchLastEntry(String agentId); @Override Date getLastModified(String agentId); @Override @SuppressWarnings("unchecked") Map<String, Date> getLastModifiedDates(); @Override void storeEvent(String mediapackageId, String organizationId, Opt<String> captureAgentId, Opt<Date> start,
          Opt<Date> end, Opt<String> source, Opt<String> recordingState, Opt<Long> recordingLastHeard,
          Opt<String> presenters, Opt<Date> lastModifiedDate, Opt<String> checksum, Opt<Map<String,
          String>> workflowProperties, Opt<Map<String, String>> caProperties
  ); @Override @SuppressWarnings("unchecked") List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis); @Override @SuppressWarnings("unchecked") List<ExtendedEventDto> search(
      Opt<String> captureAgentId,
      Opt<Date> optStartsFrom,
      Opt<Date> optStartsTo,
      Opt<Date> optEndFrom,
      Opt<Date> optEndTo,
      Opt<Integer> limit); @Override List<ExtendedEventDto> getKnownRecordings(); @Override void deleteEvent(String mediapackageId); @Override List<ExtendedEventDto> getEvents(); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId, String orgId); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId); @Override void resetRecordingState(String mediapackageId); @Override int countEvents(); static final String PERSISTENCE_UNIT; }
@Test public void testGetKnownRecordings() throws Exception { final long oneHourMillis = 3600_000; final long nowMillis = new Date().getTime(); final String mpId = "mpId"; final String agentId = "agent1"; final String orgId = new DefaultOrganization().getId(); final Date intervalEnd = new Date(nowMillis + 5 * oneHourMillis); final Date[] eventStartDates = { new Date(nowMillis - 4 * oneHourMillis), new Date(nowMillis - oneHourMillis), new Date(nowMillis + oneHourMillis), new Date(intervalEnd.getTime()), }; final String recordingState = "recordingState"; final Long lastHeard = new Date().getTime(); for (int i = 0; i < 4; i++) { final Date start = eventStartDates[i]; final Date end = new Date(start.getTime() + 2 * oneHourMillis); schedulerDatabase.storeEvent( mpId + i, orgId, Opt.some(agentId), Opt.some(start), Opt.some(end), Opt.none(), i % 2 == 0 ? Opt.some(recordingState) : Opt.none(), i % 2 == 0 ? Opt.some(lastHeard) : Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none() ); } final List<ExtendedEventDto> knownEvents = schedulerDatabase.getKnownRecordings(); Assert.assertEquals(2, knownEvents.size()); Assert.assertTrue(knownEvents.get(0).getMediaPackageId().equals(mpId + 0) || knownEvents.get(1).getMediaPackageId().equals(mpId + 0)); Assert.assertTrue(knownEvents.get(0).getMediaPackageId().equals(mpId + 2) || knownEvents.get(1).getMediaPackageId().equals(mpId + 2)); }