Skip to content

Commit

Permalink
tests: use session protocol version not the flag (apache#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zariel authored Jul 8, 2017
1 parent c9b7799 commit 566b74b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 80 deletions.
146 changes: 78 additions & 68 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ func TestTracing(t *testing.T) {
}

func TestPaging(t *testing.T) {
if *flagProto == 1 {
t.Skip("Paging not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("Paging not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, "CREATE TABLE gocql_test.paging (id int primary key)"); err != nil {
t.Fatal("create table:", err)
}
Expand All @@ -216,15 +216,15 @@ func TestPaging(t *testing.T) {
}

func TestCAS(t *testing.T) {
if *flagProto == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

cluster := createCluster()
cluster.SerialConsistency = LocalSerial
session := createSessionFromCluster(cluster, t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.cas_table (
title varchar,
revid timeuuid,
Expand Down Expand Up @@ -338,13 +338,13 @@ func TestCAS(t *testing.T) {
}

func TestMapScanCAS(t *testing.T) {
if *flagProto == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.cas_table2 (
title varchar,
revid timeuuid,
Expand Down Expand Up @@ -380,13 +380,13 @@ func TestMapScanCAS(t *testing.T) {
}

func TestBatch(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.batch_table (id int primary key)`); err != nil {
t.Fatal("create table:", err)
}
Expand All @@ -410,19 +410,19 @@ func TestBatch(t *testing.T) {

func TestUnpreparedBatch(t *testing.T) {
t.Skip("FLAKE skipping")
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.batch_unprepared (id int primary key, c counter)`); err != nil {
t.Fatal("create table:", err)
}

var batch *Batch
if *flagProto == 2 {
if session.cfg.ProtoVersion == 2 {
batch = NewBatch(CounterBatch)
} else {
batch = NewBatch(UnloggedBatch)
Expand Down Expand Up @@ -453,12 +453,13 @@ func TestUnpreparedBatch(t *testing.T) {
// TestBatchLimit tests gocql to make sure batch operations larger than the maximum
// statement limit are not submitted to a cassandra node.
func TestBatchLimit(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.batch_table2 (id int primary key)`); err != nil {
t.Fatal("create table:", err)
}
Expand Down Expand Up @@ -500,12 +501,13 @@ func TestWhereIn(t *testing.T) {
// TestTooManyQueryArgs tests to make sure the library correctly handles the application level bug
// whereby too many query arguments are passed to a query
func TestTooManyQueryArgs(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.too_many_query_args (id int primary key, value int)`); err != nil {
t.Fatal("create table:", err)
}
Expand All @@ -531,12 +533,13 @@ func TestTooManyQueryArgs(t *testing.T) {
// TestNotEnoughQueryArgs tests to make sure the library correctly handles the application level bug
// whereby not enough query arguments are passed to a query
func TestNotEnoughQueryArgs(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.not_enough_query_args (id int, cluster int, value int, primary key (id, cluster))`); err != nil {
t.Fatal("create table:", err)
}
Expand Down Expand Up @@ -829,11 +832,13 @@ func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[
}

func TestSmallInt(t *testing.T) {
if *flagProto < protoVersion4 {
t.Skip("smallint is only supported in cassandra 2.2+")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < protoVersion4 {
t.Skip("smallint is only supported in cassandra 2.2+")
}

if err := createTable(session, `CREATE TABLE gocql_test.smallint_table (
testsmallint smallint PRIMARY KEY,
)`); err != nil {
Expand Down Expand Up @@ -888,13 +893,13 @@ func TestScanWithNilArguments(t *testing.T) {
}

func TestScanCASWithNilArguments(t *testing.T) {
if *flagProto == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, `CREATE TABLE gocql_test.scan_cas_with_nil_arguments (
foo varchar,
bar varchar,
Expand Down Expand Up @@ -1083,14 +1088,13 @@ func TestBoundQueryInfo(t *testing.T) {

//TestBatchQueryInfo makes sure that the application can manually bind query parameters when executing in a batch
func TestBatchQueryInfo(t *testing.T) {
session := createSession(t)
defer session.Close()

if *flagProto == 1 {
if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

session := createSession(t)
defer session.Close()

if err := createTable(session, "CREATE TABLE gocql_test.batch_query_info (id int, cluster int, value text, PRIMARY KEY (id, cluster))"); err != nil {
t.Fatalf("failed to create table with error '%v'", err)
}
Expand Down Expand Up @@ -1216,11 +1220,13 @@ func TestPrepare_ReprepareStatement(t *testing.T) {
}

func TestPrepare_ReprepareBatch(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

stmt, conn := injectInvalidPreparedStatement(t, session, "test_reprepare_statement_batch")
batch := session.NewBatch(UnloggedBatch)
batch.Query(stmt, "bar")
Expand All @@ -1244,7 +1250,7 @@ func TestQueryInfo(t *testing.T) {
t.Fatalf("Was not expecting meta data for %d query arguments, but got %d\n", 1, x)
}

if *flagProto > 1 {
if session.cfg.ProtoVersion > 1 {
if x := len(info.response.columns); x != 2 {
t.Fatalf("Was not expecting meta data for %d result columns, but got %d\n", 2, x)
}
Expand Down Expand Up @@ -1594,12 +1600,13 @@ func TestIterHost(t *testing.T) {

//TestBatchStats confirms that the stats are returning valid data. Accuracy may be questionable.
func TestBatchStats(t *testing.T) {
if *flagProto == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion == 1 {
t.Skip("atomic batches not supported. Please use Cassandra >= 2.0")
}

if err := createTable(session, "CREATE TABLE gocql_test.batchStats (id int, PRIMARY KEY (id))"); err != nil {
t.Fatalf("failed to create table with error '%v'", err)
}
Expand Down Expand Up @@ -1741,7 +1748,7 @@ func TestGetTableMetadata(t *testing.T) {
if table.Keyspace != "gocql_test" {
t.Errorf("Expected keyspace for '%s' table metadata to be 'gocql_test' but was '%s'", table.Name, table.Keyspace)
}
if *flagProto < 4 {
if session.cfg.ProtoVersion < 4 {
// TODO(zariel): there has to be a better way to detect what metadata version
// we are in, and a better way to structure the code so that it is abstracted away
// from us here
Expand Down Expand Up @@ -1777,7 +1784,7 @@ func TestGetTableMetadata(t *testing.T) {
if testTable == nil {
t.Fatal("Expected table metadata for name 'test_table_metadata'")
}
if *flagProto == protoVersion1 {
if session.cfg.ProtoVersion == protoVersion1 {
if testTable.KeyValidator != "org.apache.cassandra.db.marshal.Int32Type" {
t.Errorf("Expected test_table_metadata key validator to be 'org.apache.cassandra.db.marshal.Int32Type' but was '%s'", testTable.KeyValidator)
}
Expand Down Expand Up @@ -1853,7 +1860,7 @@ func TestGetColumnMetadata(t *testing.T) {
}
}

if *flagProto == 1 {
if session.cfg.ProtoVersion == 1 {
// V1 proto only returns "regular columns"
if len(testColumns) != 1 {
t.Errorf("Expected 1 test columns but there were %d", len(testColumns))
Expand Down Expand Up @@ -2269,13 +2276,13 @@ func TestSessionBindRoutingKey(t *testing.T) {
}

func TestJSONSupport(t *testing.T) {
if *flagProto < 4 {
t.Skip("skipping JSON support on proto < 4")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < 4 {
t.Skip("skipping JSON support on proto < 4")
}

if err := createTable(session, `CREATE TABLE gocql_test.test_json (
id text PRIMARY KEY,
age int,
Expand Down Expand Up @@ -2313,13 +2320,13 @@ func TestJSONSupport(t *testing.T) {
}

func TestUDF(t *testing.T) {
if *flagProto < 4 {
t.Skip("skipping UDF support on proto < 4")
}

session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < 4 {
t.Skip("skipping UDF support on proto < 4")
}

const query = `CREATE OR REPLACE FUNCTION uniq(state set<text>, val text)
CALLED ON NULL INPUT RETURNS set<text> LANGUAGE java
AS 'state.add(val); return state;'`
Expand Down Expand Up @@ -2469,12 +2476,13 @@ close:
}

func TestUnmarshallNestedTypes(t *testing.T) {
if *flagProto < protoVersion3 {
t.Skip("can not have frozen types in cassandra < 2.1.3")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < protoVersion3 {
t.Skip("can not have frozen types in cassandra < 2.1.3")
}

if err := createTable(session, `CREATE TABLE gocql_test.test_557 (
id text PRIMARY KEY,
val list<frozen<map<text, text> > >
Expand Down Expand Up @@ -2601,12 +2609,13 @@ func TestControl_DiscoverProtocol(t *testing.T) {

// TestUnsetCol verify unset column will not replace an existing column
func TestUnsetCol(t *testing.T) {
if *flagProto < 4 {
t.Skip("Unset Values are not supported in protocol < 4")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < 4 {
t.Skip("Unset Values are not supported in protocol < 4")
}

if err := createTable(session, "CREATE TABLE gocql_test.testUnsetInsert (id int, my_int int, my_text text, PRIMARY KEY (id))"); err != nil {
t.Fatalf("failed to create table with error '%v'", err)
}
Expand All @@ -2629,12 +2638,13 @@ func TestUnsetCol(t *testing.T) {

// TestUnsetColBatch verify unset column will not replace a column in batch
func TestUnsetColBatch(t *testing.T) {
if *flagProto < 4 {
t.Skip("Unset Values are not supported in protocol < 4")
}
session := createSession(t)
defer session.Close()

if session.cfg.ProtoVersion < 4 {
t.Skip("Unset Values are not supported in protocol < 4")
}

if err := createTable(session, "CREATE TABLE gocql_test.batchUnsetInsert (id int, my_int int, my_text text, PRIMARY KEY (id))"); err != nil {
t.Fatalf("failed to create table with error '%v'", err)
}
Expand Down
2 changes: 1 addition & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {
panic(err)
}
defer session.Close()
defer log.Println("closing keyspace session")
defer tb.Log("closing keyspace session")

err = createTable(session, `DROP KEYSPACE IF EXISTS `+keyspace)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions tuple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package gocql
import "testing"

func TestTupleSimple(t *testing.T) {
if *flagProto < protoVersion3 {
t.Skip("tuple types are only available of proto>=3")
}

session := createSession(t)
defer session.Close()
if session.cfg.ProtoVersion < protoVersion3 {
t.Skip("tuple types are only available of proto>=3")
}

err := createTable(session, `CREATE TABLE gocql_test.tuple_test(
id int,
Expand Down Expand Up @@ -51,11 +50,11 @@ func TestTupleSimple(t *testing.T) {
}

func TestTupleMapScan(t *testing.T) {
if *flagProto < protoVersion3 {
session := createSession(t)
defer session.Close()
if session.cfg.ProtoVersion < protoVersion3 {
t.Skip("tuple types are only available of proto>=3")
}

session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TABLE gocql_test.tuple_map_scan(
Expand Down
Loading

0 comments on commit 566b74b

Please sign in to comment.