JdbcExpiringCodeStore implements ExpiringCodeStore { public int cleanExpiredEntries() { long now = timeService.getCurrentTimeMillis(); long lastCheck = lastExpired.get(); if ((now - lastCheck) > expirationInterval && lastExpired.compareAndSet(lastCheck, now)) { int count = jdbcTemplate.update(deleteExpired, now); logger.debug("Expiring code sweeper complete, deleted " + count + " entries."); return count; } return 0; } protected  JdbcExpiringCodeStore();  JdbcExpiringCodeStore(DataSource dataSource, TimeService timeService); long getExpirationInterval(); void setExpirationInterval(long expirationInterval); @Override ExpiringCode generateCode(String data, Timestamp expiresAt, String intent, String zoneId); @Override ExpiringCode retrieveCode(String code, String zoneId); @Override void setGenerator(RandomValueStringGenerator generator); @Override void expireByIntent(String intent, String zoneId); int cleanExpiredEntries(); static final String tableName; static final String fields; }
@Test void expirationCleaner() { when(mockTimeService.getCurrentTimeMillis()).thenReturn(System.currentTimeMillis()); jdbcTemplate.update(JdbcExpiringCodeStore.insert, "test", System.currentTimeMillis() - 1000, "{}", null, IdentityZone.getUaaZoneId()); ((JdbcExpiringCodeStore) expiringCodeStore).cleanExpiredEntries(); assertThrows(EmptyResultDataAccessException.class, () -> jdbcTemplate.queryForObject( JdbcExpiringCodeStore.selectAllFields, new JdbcExpiringCodeStore.JdbcExpiringCodeMapper(), "test", IdentityZone.getUaaZoneId())); }