Subscriptions { @Scheduled(fixedDelay = 60000) public void purgeExpiredSubscriptions() { final Instant now = Instant.now(); subscriptions.forEach((subscriptionId, subscribeContext) -> { if (subscribeContext.getExpirationDate().isBefore(now)) { subscriptions.remove(subscriptionId); try { subscriptionsRepository.removeSubscription(subscriptionId); } catch (SubscriptionPersistenceException e) { logger.error("Failed to remove subscription from database", e); } } }); }  String addSubscription(SubscribeContext subscribeContext); boolean deleteSubscription(UnsubscribeContext unsubscribeContext); Iterator<Subscription> findSubscriptions(EntityId searchEntityId, Set<String> searchAttributes); @Scheduled(fixedDelay = 60000) void purgeExpiredSubscriptions(); Subscription getSubscription(String subscriptionId);  }
@Test public void purgeExpiredSubscriptionsTest() throws URISyntaxException, SubscriptionException, InterruptedException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); subscribeContext.setDuration("PT1S"); String subscriptionId = subscriptions.addSubscription(subscribeContext); Assert.isTrue(subscriptionsRepository.getAllSubscriptions().size()==1); Thread.sleep(1500); subscriptions.purgeExpiredSubscriptions(); assertNull(subscriptions.getSubscription(subscriptionId)); Assert.isTrue(subscriptionsRepository.getAllSubscriptions().size()==0); }