lukasz-antoniak commented on code in PR #1781:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1781#discussion_r1734228960
##########
batch_test.go:
##########
@@ -84,3 +84,68 @@ func TestBatch_WithTimestamp(t *testing.T) {
t.Errorf("got ts %d, expected %d", storedTs, micros)
}
}
+
+func TestQuery_WithNowInSeconds(t *testing.T) {
+ session := createSession(t)
+ defer session.Close()
+
+ if session.cfg.ProtoVersion < protoVersion5 {
+ t.Skip("Query now in seconds are only available on protocol >=
5")
+ }
+
+ if err := createTable(session, `CREATE TABLE query_now_in_seconds (id
int primary key, val text)`); err != nil {
+ t.Fatal(err)
+ }
+
+ // Using 30 minutes ago timestamp as a starting point for TTL
+ seconds := time.Now().Add(-time.Minute*30).UnixMicro() / 1e6
+
+ err := session.
+ Query("INSERT INTO query_now_in_seconds (id, val) VALUES (?, ?)
USING TTL 3600", 1, "val").
+ WithNowInSeconds(int(seconds)).
+ Exec()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var ttl int64
+ if err := session.Query(`SELECT TTL(val) FROM query_now_in_seconds
WHERE id = ?`, 1).Scan(&ttl); err != nil {
+ t.Fatal(err)
+ }
+
+ if ttl > 1800 {
Review Comment:
I think this test is slightly better:
[NowInSecondsIT.java](https://github.com/apache/cassandra-java-driver/blob/4.x/integration-tests/src/test/java/com/datastax/oss/driver/core/cql/NowInSecondsIT.java).
Use `NowInSeconds` also in SELECT query, so that you can indeed read expected
TTL difference.
##########
frame.go:
##########
@@ -1512,7 +1515,13 @@ func (f *framer) writeQueryParams(opts *queryParams) {
}
if f.proto > protoVersion4 {
- f.writeUint(uint32(flags))
+ flags := uint32(flags)
+
+ if opts.nowInSeconds {
Review Comment:
After we refactor flag to be an integer, we can move this to a place where
all flags are computed.
##########
frame.go:
##########
@@ -1512,7 +1515,13 @@ func (f *framer) writeQueryParams(opts *queryParams) {
}
if f.proto > protoVersion4 {
- f.writeUint(uint32(flags))
+ flags := uint32(flags)
Review Comment:
I think changing flags to `int` type and truncating it for protocols before
V5 would be cleaner.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]