ribaraka commented on code in PR #1822: URL: https://github.com/apache/cassandra-gocql-driver/pull/1822#discussion_r1965222902
########## cassandra_test.go: ########## @@ -3362,3 +3366,460 @@ func TestQuery_NamedValues(t *testing.T) { t.Fatal(err) } } + +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 IF NOT EXISTS query_now_in_seconds (id int primary key, val text)`); err != nil { + t.Fatal(err) + } + + err := session.Query("INSERT INTO query_now_in_seconds (id, val) VALUES (?, ?) USING TTL 20", 1, "val"). + WithNowInSeconds(int(0)). + Exec() + if err != nil { + t.Fatal(err) + } + + var remainingTTL int + err = session.Query(`SELECT TTL(val) FROM query_now_in_seconds WHERE id = ?`, 1). + WithNowInSeconds(10). + Scan(&remainingTTL) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, remainingTTL, 10) +} + +func TestQuery_SetKeyspace(t *testing.T) { + session := createSession(t) + defer session.Close() + + if session.cfg.ProtoVersion < protoVersion5 { + t.Skip("keyspace for QUERY message is not supported in protocol < 5") + } + + const keyspaceStmt = ` + CREATE KEYSPACE IF NOT EXISTS gocql_query_keyspace_override_test + WITH replication = { + 'class': 'SimpleStrategy', + 'replication_factor': '1' + }; +` + + err := session.Query(keyspaceStmt).Exec() + if err != nil { + t.Fatal(err) + } + + err = createTable(session, "CREATE TABLE IF NOT EXISTS gocql_query_keyspace_override_test.query_keyspace(id int, value text, PRIMARY KEY (id))") + if err != nil { + t.Fatal(err) + } + + expectedID := 1 + expectedText := "text" + + // Testing PREPARE message + err = session.Query("INSERT INTO gocql_query_keyspace_override_test.query_keyspace (id, value) VALUES (?, ?)", expectedID, expectedText).Exec() + if err != nil { + t.Fatal(err) + } + + var ( + id int + text string + ) + + q := session.Query("SELECT * FROM gocql_query_keyspace_override_test.query_keyspace"). + SetKeyspace("gocql_query_keyspace_override_test") + err = q.Scan(&id, &text) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, expectedID, id) + require.Equal(t, expectedText, text) + + // Testing QUERY message + id = 0 + text = "" + + q = session.Query("SELECT * FROM gocql_query_keyspace_override_test.query_keyspace"). + SetKeyspace("gocql_query_keyspace_override_test") + q.skipPrepare = true + err = q.Scan(&id, &text) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, expectedID, id) + require.Equal(t, expectedText, text) +} + +func TestLargeSizeQuery(t *testing.T) { + // TestLargeSizeQuery runs a query bigger than the max allowed size of the payload of a frame, + // so it should be sent as 2 different frames where each contains a self-contained bit set to zero. + + session := createSession(t) + defer session.Close() + + if err := createTable(session, "CREATE TABLE IF NOT EXISTS gocql_test.large_size_query(id int, text_col text, PRIMARY KEY (id))"); err != nil { + t.Fatal(err) + } + + longString := strings.Repeat("a", 500_000) + + err := session.Query("INSERT INTO gocql_test.large_size_query (id, text_col) VALUES (?, ?)", "1", longString).Exec() + if err != nil { + t.Fatal(err) + } + + var result string + err = session.Query("SELECT text_col FROM gocql_test.large_size_query").Scan(&result) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, longString, result) +} + +func TestQueryCompressionNotWorthIt(t *testing.T) { + // TestQueryCompressionNotWorthIt runs a query that is not likely to be compressed efficiently + // (uncompressed payload size > compressed payload size). + // So, it should send a Compressed Frame where: + // 1. Compressed length is set to the length of the uncompressed payload; + // 2. Uncompressed length is set to zero; + // 3. Payload is the uncompressed payload. + + session := createSession(t) + defer session.Close() + + if err := createTable(session, "CREATE TABLE IF NOT EXISTS gocql_test.compression_now_worth_it(id int, text_col text, PRIMARY KEY (id))"); err != nil { + t.Fatal(err) + } + + str := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+" + err := session.Query("INSERT INTO gocql_test.large_size_query (id, text_col) VALUES (?, ?)", "1", str).Exec() + if err != nil { + t.Fatal(err) + } + + var result string + err = session.Query("SELECT text_col FROM gocql_test.large_size_query").Scan(&result) + if err != nil { + t.Fatal(err) + } + + require.Equal(t, str, result) +} + +func TestPrepareExecuteMetadataChangedFlag(t *testing.T) { + // This test ensures that the whole Metadata_changed flow + // is handled properly. + // + // To trigger C* to return Metadata_changed we should do: + // 1. Create a table + // 2. Prepare stmt which uses the created table + // 3. Change the table schema in order to affect prepared stmt (e.g. add a column) + // 4. Execute prepared stmt. As a result C* should return RESULT/ROWS response with + // Metadata_changed flag, new metadata id and updated metadata resultset. + // + // The driver should handle this by updating its prepared statement inside the cache + // when it receives RESULT/ROWS with Metadata_changed flag Review Comment: Could you move descriptions above the function declaration? ########## cassandra_test.go: ########## @@ -3256,6 +3256,10 @@ func TestCreateSession_DontSwallowError(t *testing.T) { func TestControl_DiscoverProtocol(t *testing.T) { cluster := createCluster() cluster.ProtoVersion = 0 + // Forcing to run this test without any compression. + // If compressor is presented, then CI will fail when snappy compression is enabled, since + // protocol v5 doesn't support it. + cluster.Compressor = nil Review Comment: You've exluded the snappy from proto v5 in the CI, then everyting should work fine - remove this block of code (?) -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org