Description
David Prevost opened DATACOUCH-630 and commented
While trying to test if the expiry of my document was set correctly, I find out that it is not set at all.
Basically, I did a IT that create, and update my entity having @Document
(expiry = 60) and then I use the couchbase api to validate the expiry and it is never set.
The output of my test below show that the expiry date is alway 1970-01-01 unless I use the getAndTouch API of couchbase
Expiry on create using JPA save
Optional[1970-01-01T00:00:00Z]
Expiry on update using JPA save
Optional[1970-01-01T00:00:00Z]
Expiry on getAndTouch of couchbase API
Optional[2020-10-08T14:34:43Z]
Also, if we analyze occurences of CouchbaseDocument#getExpiration then it does not seems to be use anywhere with the couchbase api. And if we check CouchbaseDocument#export, the expiry is not in the content (not sure if it can actually be part of the content....)
@Test
public void givenSavedUserSession_whenUpdate_thenExpiryIsAlsoUpdated(
@Autowired final CouchbaseClientFactory couchbaseClient) {
final Collection operations = couchbaseClient.getBucket().defaultCollection();
final UUID userUuid = UUID.randomUUID();
final String id = userUuid.toString();
final UserSessionEntity userSessionEntity =
UserSessionEntityBuilder.builder().userUuid(userUuid).jtwTokenIds(Set.of(UUID.randomUUID())).build();
userSessionDao.save(userSessionEntity);
final GetResult resultWithExpiry =
operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));
System.out.println("Expiry on create using JPA save");
System.out.println(resultWithExpiry.expiryTime());
// Wait 5 sec to better compare create expiry and update expiry
userSessionDao.save(userSessionEntity);
final GetResult resultWithExpiry2 =
operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));
System.out.println("Expiry on update using JPA save");
System.out.println(resultWithExpiry2.expiryTime());
operations.getAndTouch(id, Duration.ofSeconds(60));
final GetResult resultWithExpiry3 =
operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));
System.out.println("Expiry on getAndTouch of couchbase API");
System.out.println(resultWithExpiry3.expiryTime());
}
@Document(expiry = 60)
public class UserSessionEntity {
@Id
private UUID userUuid;
@Version
private long version;
@Field
@NotNull
private Set<UUID> jtwTokenIds;
}
public interface UserSessionDao
extends CrudRepository<UserSessionEntity, UUID> {
}
Affects: 4.0.4 (Neumann SR4)
Referenced from: pull request #285
Backported to: 4.1.3 (2020.0.3), 4.0.7 (Neumann SR7)