-
Notifications
You must be signed in to change notification settings - Fork 192
Use expiry(duration) with duration. #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
73f2b46
to
909d8f7
Compare
pom.xml
Outdated
@@ -118,6 +118,18 @@ | |||
<optional>true</optional> | |||
</dependency> | |||
|
|||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those really needed runtime dependencies? or do you use them for tests only? in which case they need to have test scope
} | ||
|
||
private static Duration getExpiryDuration(Expiry annotation, Environment environment) { | ||
if (annotation == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing { }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in all three places.
@mikereiche does this supersede #1205 ? |
@dnault can you take a look at the instant and duration related bits please? |
6b44c7e
to
80e69c0
Compare
@@ -503,7 +503,7 @@ protected void writeInternal(final Object source, final CouchbaseDocument target | |||
final TreeMap<Integer, String> suffixes = new TreeMap<>(); | |||
final TreeMap<Integer, String> idAttributes = new TreeMap<>(); | |||
|
|||
target.setExpiration(entity.getExpiry()); | |||
target.setExpiration((int)(entity.getExpiryDuration().getSeconds())); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use explicit getExpiryDuration() as the other getExpiry() is sometimes duration and sometimes instant.
assertThrows(CouchbaseException.class, () -> couchbaseTemplate.findByQuery(UserSubmission.class).project(new String[] { "address.street" }) | ||
.withConsistency(QueryScanConsistency.REQUEST_PLUS).all()); | ||
assertThrows(CouchbaseException.class, () -> couchbaseTemplate.findByQuery(UserSubmission.class) | ||
.project(new String[] { "address.street" }).withConsistency(QueryScanConsistency.REQUEST_PLUS).all()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting only
ExecutableFindByQuery q = (ExecutableFindByQuery) couchbaseTemplate | ||
.findByQuery(Airline.class).matching(query); | ||
.findByQuery(Airline.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).matching(query); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this properly with QueryScanConsistency instead of sleep()
Also adds test for exceptions thrown during events - with validator. Closes #1204.
80e69c0
to
a5f643b
Compare
return Instant.ofEpochSecond(cal.getTimeInMillis() / 1000); // note: Unix UTC time representation in int is okay | ||
// until year 2038 | ||
} | ||
|
||
private static int getExpiryValue(Expiry annotation, Environment environment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the ambiguity with getExpiry() that returns a long that is sometimes a seconds_duration and sometimes an instant_seconds_since_epoch.
getExpiryDuration() returns a Duration
getExpiryInstant() returns an Instant
@@ -84,6 +85,7 @@ public void beforeEach() { | |||
couchbaseTemplate.removeByQuery(UserAnnotated.class).all(); | |||
couchbaseTemplate.removeByQuery(UserAnnotated2.class).all(); | |||
couchbaseTemplate.removeByQuery(UserAnnotated3.class).all(); | |||
couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixed intermittent failures when my vagrant vm got slow.
@@ -282,15 +284,23 @@ void withExpiryAndExpiryAnnotation() | |||
} | |||
// check that they are gone after a few seconds. | |||
sleepSecs(4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives all the failures instead of the just the first one.
Yes. #1205 had a merge from main on top of it. I closed it now. |
|
||
private static Duration getExpiryDuration(Expiry annotation, Environment environment) { | ||
if (annotation == null) { | ||
return Duration.ofSeconds(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Could avoid creating a new Duration by using Duration.ZERO
Mike: Fixed
...ain/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentEntity.java
Show resolved
Hide resolved
/** | ||
* Returns the expiration time of the entity. | ||
* <p/> | ||
* The Couchbase format for expiration time is: - for TTL < 31 days (<= 30 * 24 * 60 * 60): expressed as a TTL in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Is this relevant when getting the expiry as a duration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied from getExpiry()
@@ -40,6 +43,26 @@ | |||
*/ | |||
int getExpiry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can getExpiry (and the static version) be deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It also needs to be replaced in ReactiveFindByIdOperationSupport where it is used for getAndTouch()
return Instant.ofEpochSecond(0); | ||
} | ||
// we want it to be represented as a UNIX timestamp style, seconds since Epoch in UTC | ||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the expiry unit is not DAYS or SECONDS? (I think this is also a problem in getExpiry where this code originated.)
Since we're not worried about time zones, and UTC does not have Daylight Savings, using a calendar seems like overkill. Why not just:
long currentEpochSecond = System.curentTimeMillis() / 1000;
return Instant.ofEpochSecond(currentEpochSecond + secondsShift);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not days, then secondsShift is used which was produced from the expiryUnit() and expiryVlaue.
annotation.expiryUnit().toSeconds(expiryValue)
I don't understand the significance of adding in DAYS vs. seconds.
* | ||
* @return the expiration time Instant | ||
*/ | ||
Instant getExpiryInstant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method required? It seems like the value it returns is calculated from the duration specified by the user in the annotation.
If it's only used by integration tests, perhaps it could be moved into the test code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a new PR for your comments.
It's getting close to the release so I was hasty getting the previous one merged.
return Instant.ofEpochSecond(0); | ||
} | ||
// we want it to be represented as a UNIX timestamp style, seconds since Epoch in UTC | ||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this method.
@@ -40,6 +43,26 @@ | |||
*/ | |||
int getExpiry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It also needs to be replaced in ReactiveFindByIdOperationSupport where it is used for getAndTouch()
/** | ||
* Returns the expiration time of the entity. | ||
* <p/> | ||
* The Couchbase format for expiration time is: - for TTL < 31 days (<= 30 * 24 * 60 * 60): expressed as a TTL in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied from getExpiry()
* | ||
* @return the expiration time Instant | ||
*/ | ||
Instant getExpiryInstant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
return Instant.ofEpochSecond(0); | ||
} | ||
// we want it to be represented as a UNIX timestamp style, seconds since Epoch in UTC | ||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not days, then secondsShift is used which was produced from the expiryUnit() and expiryVlaue.
annotation.expiryUnit().toSeconds(expiryValue)
I don't understand the significance of adding in DAYS vs. seconds.
Also adds test for exceptions thrown during events - with validator.
Closes #1204.