Skip to content

Commit

Permalink
Added tests for Timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Dec 21, 2024
1 parent 7087c18 commit c50dde5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions table/src/test/java/tech/ydb/table/integration/ValuesReadTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ydb.table.integration;

import java.time.Instant;
import java.util.UUID;

import org.junit.Assert;
Expand Down Expand Up @@ -101,4 +102,41 @@ public void uuidReadTest() {
Assert.assertEquals(0x9cfbb7462d9e498bL, v2.getUuidLow());
Assert.assertEquals(0x6e73b41c4ede4d08L, v2.getUuidHigh());
}

private void assertTimestamp(ValueReader vr, boolean optional, Instant expected) {
Assert.assertNotNull(vr);
if (optional) {
Assert.assertSame(Type.Kind.OPTIONAL, vr.getType().getKind());
Assert.assertSame(PrimitiveType.Timestamp, vr.getType().unwrapOptional());
} else {
Assert.assertSame(PrimitiveType.Timestamp, vr.getType());
}

Assert.assertEquals(expected, vr.getTimestamp());
}

@Test
public void timestampReadTest() {
DataQueryResult result = CTX.supplyResult(
s -> s.executeDataQuery("SELECT "
+ "DateTime::MakeTimestamp(DateTime::FromMilliseconds(0ul)) as t1,"
+ "DateTime::MakeTimestamp(DateTime::FromMicroseconds(1000ul)) as t2,"
+ "DateTime::MakeTimestamp(DateTime::FromMicroseconds(4291747199999999ul)) as t3,"
+ "Timestamp('1970-01-01T00:00:00.000000Z') as t4,"
+ "Timestamp('2105-12-31T23:59:59.999999Z') as t5;",
TxControl.serializableRw()
)
).join().getValue();

Assert.assertEquals(1, result.getResultSetCount());

ResultSetReader rs = result.getResultSet(0);
Assert.assertTrue(rs.next());

assertTimestamp(rs.getColumn("t1"), true, Instant.EPOCH);
assertTimestamp(rs.getColumn("t2"), true, Instant.EPOCH.plusMillis(1));
assertTimestamp(rs.getColumn("t3"), true, Instant.parse("2105-12-31T23:59:59.999999Z"));
assertTimestamp(rs.getColumn("t4"), false, Instant.ofEpochSecond(0, 0));
assertTimestamp(rs.getColumn("t5"), false, Instant.ofEpochSecond(4291747199l, 999999000l));
}
}
39 changes: 39 additions & 0 deletions table/src/test/java/tech/ydb/table/types/PrimitiveTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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);
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"));
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());
}
}

0 comments on commit c50dde5

Please sign in to comment.