forked from ydb-platform/ydb-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy of changes made in ydb-platform#353
- Loading branch information
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
table/src/test/java/tech/ydb/table/types/PrimitiveTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package tech.ydb.table.types; | ||
|
||
import java.time.Instant; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import tech.ydb.proto.ValueProtos.Value; | ||
import tech.ydb.table.values.PrimitiveValue; | ||
|
||
/** | ||
* | ||
* @author Aleksandr Gorshenin | ||
*/ | ||
public class PrimitiveTypeTest { | ||
|
||
@Test | ||
public void timestampTest() { | ||
PrimitiveValue min = PrimitiveValue.newTimestamp(Instant.EPOCH); | ||
Assert.assertEquals(min, PrimitiveValue.newTimestamp(0)); | ||
Value minValue = min.toPb(); | ||
|
||
Assert.assertEquals(0, minValue.getUint32Value()); | ||
Assert.assertEquals(0, minValue.getUint64Value()); | ||
Assert.assertEquals(0, minValue.getInt32Value()); | ||
Assert.assertEquals(0, minValue.getInt64Value()); | ||
Assert.assertEquals(0, minValue.getLow128()); | ||
Assert.assertEquals(0, minValue.getHigh128()); | ||
|
||
PrimitiveValue max = PrimitiveValue.newTimestamp(Instant.parse("2105-12-31T23:59:59.999999Z")); | ||
Assert.assertEquals(max, PrimitiveValue.newTimestamp(4291747199999999l)); | ||
Value maxValue = max.toPb(); | ||
|
||
Assert.assertEquals(0, maxValue.getUint32Value()); | ||
Assert.assertEquals(4291747199999999l, maxValue.getUint64Value()); | ||
Assert.assertEquals(0, maxValue.getInt32Value()); | ||
Assert.assertEquals(0, maxValue.getInt64Value()); | ||
Assert.assertEquals(0, maxValue.getLow128()); | ||
Assert.assertEquals(0, maxValue.getHigh128()); | ||
|
||
IllegalArgumentException err1 = Assert.assertThrows( | ||
IllegalArgumentException.class, () -> PrimitiveValue.newTimestamp(-1) | ||
); | ||
Assert.assertEquals("Negative microsSinceEpoch: -1", err1.getMessage()); | ||
|
||
IllegalArgumentException err2 = Assert.assertThrows( | ||
IllegalArgumentException.class, () -> PrimitiveValue.newTimestamp(Instant.EPOCH.minusNanos(1)) | ||
); | ||
Assert.assertEquals("Instant before epoch: 1969-12-31T23:59:59.999999999Z", err2.getMessage()); | ||
} | ||
} |