DATACOUCH-59 - Allow expiry touch on read
Configuration is based on Document annotation. When read of document takes place then touch action is executed on document. It is an asynchronous action so it does not block read. It is executed only on single reads (not view-based or N1QL-based ones).
This commit is contained in:
committed by
Simon Baslé
parent
90839ef604
commit
40e4212ad7
@@ -17,6 +17,8 @@
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -103,6 +105,42 @@ public class BasicCouchbasePersistentEntityTests {
|
||||
assertEquals(expected.get(Calendar.SECOND), calendar.get(Calendar.SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotUseGetExpiry() throws Exception {
|
||||
assertEquals(0, getBasicCouchbasePersistentEntity(SimpleDocument.class).getExpiry());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesGetExpiry() throws Exception {
|
||||
assertEquals(10, getBasicCouchbasePersistentEntity(SimpleDocumentWithExpiry.class).getExpiry());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotUseIsUpdateExpiryForRead() throws Exception {
|
||||
assertFalse(getBasicCouchbasePersistentEntity(SimpleDocument.class).isTouchOnRead());
|
||||
assertFalse(getBasicCouchbasePersistentEntity(SimpleDocumentWithExpiry.class).isTouchOnRead());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesTouchOnRead() throws Exception {
|
||||
assertTrue(getBasicCouchbasePersistentEntity(SimpleDocumentWithTouchOnRead.class).isTouchOnRead());
|
||||
}
|
||||
|
||||
private BasicCouchbasePersistentEntity getBasicCouchbasePersistentEntity(Class<?> clazz) {
|
||||
return new BasicCouchbasePersistentEntity(ClassTypeInformation.from(clazz));
|
||||
}
|
||||
|
||||
public static class SimpleDocument {
|
||||
}
|
||||
|
||||
@Document(expiry = 10)
|
||||
public static class SimpleDocumentWithExpiry {
|
||||
}
|
||||
|
||||
@Document(expiry = 10, touchOnRead = true)
|
||||
public static class SimpleDocumentWithTouchOnRead {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple POJO to test default expiry.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user