@Test public void testPutWithTTL() { final String mapName = randomString(); final int ttlSeconds = 1; final String key = "key"; final String value = "Value"; final IMap map = client.getMap(mapName); final TransactionContext context = client.newTransactionContext(); context.beginTransaction(); final TransactionalMap<Object, Object> txnMap = context.getMap(mapName); txnMap.put(key, value, ttlSeconds, TimeUnit.SECONDS); Object resultFromClientWhileTxnInProgress = map.get(key); context.commitTransaction(); assertNull(resultFromClientWhileTxnInProgress); assertEquals(value, map.get(key)); // waite for ttl to expire sleepSeconds(ttlSeconds + 1); assertNull(map.get(key)); }
public static void assertTrueDelayed(int delaySeconds, AssertTask task) { sleepSeconds(delaySeconds); try { task.run(); } catch (Exception e) { throw new RuntimeException(e); } }
public static void assertTrueAllTheTime(AssertTask task, long durationSeconds) { for (int k = 0; k < durationSeconds; k++) { try { task.run(); } catch (Exception e) { throw new RuntimeException(e); } sleepSeconds(1); } }