sashapolo commented on code in PR #2402:
URL: https://github.com/apache/ignite-3/pull/2402#discussion_r1283333807
##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -236,12 +236,23 @@ public String toString() {
/**
* Returns a new hybrid timestamp with incremented physical component.
*/
- public HybridTimestamp addPhysicalTime(long mills) {
- if (mills >= (1L << PHYSICAL_TIME_BITS_SIZE)) {
- throw new IllegalArgumentException("Physical time is out of
bounds: " + mills);
+ public HybridTimestamp addPhysicalTime(long millis) {
+ if (millis >= (1L << PHYSICAL_TIME_BITS_SIZE)) {
+ throw new IllegalArgumentException("Physical time is out of
bounds: " + millis);
}
- return new HybridTimestamp(time + (mills << LOGICAL_TIME_BITS_SIZE));
+ return new HybridTimestamp(time + (millis << LOGICAL_TIME_BITS_SIZE));
+ }
+
+ /**
+ * Returns a new hybrid timestamp with decremented physical component.
+ */
+ public HybridTimestamp subtractPhysicalTime(long millis) {
+ if (millis >= (1L << PHYSICAL_TIME_BITS_SIZE)) {
+ throw new IllegalArgumentException("Physical time is out of
bounds: " + millis);
+ }
+
+ return new HybridTimestamp(time - (millis << LOGICAL_TIME_BITS_SIZE));
Review Comment:
Can we have an overflow here?
##########
modules/core/src/test/java/org/apache/ignite/internal/hlc/HybridTimestampTest.java:
##########
@@ -64,4 +67,62 @@ void notEqualWhenLogicalIsDifferent() {
void hashCodeSameWhenComponentsAreSame() {
assertEquals(new HybridTimestamp(1, 2).hashCode(), new
HybridTimestamp(1, 2).hashCode());
}
+
+ @Test
+ void addPhysicalTimeIncrementsPhysicalComponent() {
+ HybridTimestamp before = new HybridTimestamp(1, 2);
+
+ HybridTimestamp after = before.addPhysicalTime(1000);
+
+ assertThat(after.getPhysical(), is(1001L));
+ }
+
+ @Test
+ void addPhysicalTimeLeavesLogicalComponentIntact() {
Review Comment:
What's the point of having two tests here? I think we can simply check two
conditions in the test above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]