use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class ManualSqlEntryManagerTest method testBatchJob.
@Test(dependsOnMethods = "deleteSessionId", enabled = false)
public void testBatchJob() {
String outsideSid = UUID.randomUUID().toString();
for (int i = 0; i < 200; i++) {
SessionId sessionId = buildSessionId();
sessionId.setOutsideSid(outsideSid);
Pair<Date, Integer> expirarion = expirationDate(new Date());
sessionId.setExpirationDate(expirarion.getFirst());
sessionId.setTtl(expirarion.getSecond());
manager.persist(sessionId);
}
totalProcessedCount = 0;
ProcessBatchOperation<SessionId> sessionBatchOperation = new ProcessBatchOperation<SessionId>() {
int processedCount = 0;
@Override
public void performAction(List<SessionId> objects) {
for (SessionId simpleSession : objects) {
try {
Calendar calendar = Calendar.getInstance();
Date jansLastAccessTimeDate = simpleSession.getExpirationDate();
calendar.setTime(jansLastAccessTimeDate);
calendar.add(Calendar.SECOND, -1);
simpleSession.setExpirationDate(calendar.getTime());
manager.merge(simpleSession);
processedCount++;
} catch (EntryPersistenceException ex) {
System.err.println("Failed to update entry: " + ex.getMessage());
}
}
System.out.println("Total processed: " + processedCount);
assertEquals(processedCount, 100);
totalProcessedCount += processedCount;
}
};
Filter filter1 = Filter.createANDFilter(Filter.createPresenceFilter("exp"), Filter.createEqualityFilter("sid", outsideSid));
manager.findEntries("o=jans", SessionId.class, filter1, SearchScope.SUB, new String[] { "exp" }, sessionBatchOperation, 0, 500, 100);
assertEquals(totalProcessedCount, 200);
}
Aggregations