- @Test
- public void testCleanOld() throws Exception {
- map.setRecordTimeOut(240);
- map.setTimeUnit(TimeUnit.SECONDS);
-
- Object entry1Key = "entry1Key";
- String entry1recordKey = SubKeys.RECORD;
- String entry1recordValue = "record1";
- String entry1regdateKey = SubKeys.REGDATE;
- Date entry1regdateValue = new Date();
-
- Object entry2Key = "entry2Key";
- String entry2recordKey = SubKeys.RECORD;
- String entry2recordValue = "record2";
- String entry2regdateKey = SubKeys.REGDATE;
- Date entry2regdateValue = new Date(
- System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(map.getRecordTimeOut(), map.getTimeUnit()));
-
- map.put(entry1Key,
- new MappingEntry<>(entry1recordKey, entry1recordValue),
- new MappingEntry<>(entry1regdateKey, entry1regdateValue));
- map.put(entry2Key,
- new MappingEntry<>(entry2recordKey, entry2recordValue),
- new MappingEntry<>(entry2regdateKey, entry2regdateValue));
- map.cleanOld();
-
- Assert.assertEquals("Entry should be present in the DB due to its time didn't expired",
- entry1recordValue, map.getSpecific(entry1Key, entry1recordKey));
- Assert.assertNull("Entry should not be present in the DB due to its time expired",
- map.getSpecific(entry2Key, entry2recordKey));
-
- }
-
- @Test
- public void testSetGetTimeUnit() throws Exception {
- TimeUnit timeUnit = TimeUnit.DAYS;
- map.setTimeUnit(timeUnit);
- Assert.assertEquals(timeUnit, map.getTimeUnit());
- }
-
- @Test
- public void testSetGetRecordTimeOut() throws Exception {
- int recordTimeOut = 12345;
- map.setRecordTimeOut(recordTimeOut);
- Assert.assertEquals(recordTimeOut, map.getRecordTimeOut());
- }
-