Skip to content

Commit

Permalink
run TestWriteFailure against all versions (apache#1203)
Browse files Browse the repository at this point in the history
* run TestWriteFailure against all versions

* Build independently tests that need environment variables

* Move ccm dependant tests under integration tag, add cassandra build tag, remove unit build tag
  • Loading branch information
beltran authored and Zariel committed Oct 19, 2018
1 parent 85b7b57 commit fa8dbda
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 152 deletions.
2 changes: 1 addition & 1 deletion batch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build all integration
// +build all cassandra

package gocql

Expand Down
2 changes: 1 addition & 1 deletion cass1batch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build all integration
// +build all cassandra

package gocql

Expand Down
131 changes: 1 addition & 130 deletions cassandra_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build all integration
// +build all cassandra

package gocql

Expand All @@ -22,59 +22,6 @@ import (
inf "gopkg.in/inf.v0"
)

// TestAuthentication verifies that gocql will work with a host configured to only accept authenticated connections
func TestAuthentication(t *testing.T) {

if *flagProto < 2 {
t.Skip("Authentication is not supported with protocol < 2")
}

if !*flagRunAuthTest {
t.Skip("Authentication is not configured in the target cluster")
}

cluster := createCluster()

cluster.Authenticator = PasswordAuthenticator{
Username: "cassandra",
Password: "cassandra",
}

session, err := cluster.CreateSession()

if err != nil {
t.Fatalf("Authentication error: %s", err)
}

session.Close()
}

//TestRingDiscovery makes sure that you can autodiscover other cluster members when you seed a cluster config with just one node
func TestRingDiscovery(t *testing.T) {
cluster := createCluster()
cluster.Hosts = clusterHosts[:1]

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

if *clusterSize > 1 {
// wait for autodiscovery to update the pool with the list of known hosts
time.Sleep(*flagAutoWait)
}

session.pool.mu.RLock()
defer session.pool.mu.RUnlock()
size := len(session.pool.hostConnPools)

if *clusterSize != size {
for p, pool := range session.pool.hostConnPools {
t.Logf("p=%q host=%v ips=%s", p, pool.host, pool.host.ConnectAddress().String())

}
t.Errorf("Expected a cluster size of %d, but actual size was %d", *clusterSize, size)
}
}

func TestEmptyHosts(t *testing.T) {
cluster := createCluster()
cluster.Hosts = nil
Expand Down Expand Up @@ -2467,64 +2414,6 @@ func TestTokenAwareConnPool(t *testing.T) {
// TODO add verification that the query went to the correct host
}

func TestCustomPayloadMessages(t *testing.T) {
cluster := createCluster()
session := createSessionFromCluster(cluster, t)
defer session.Close()

if err := createTable(session, "CREATE TABLE gocql_test.testCustomPayloadMessages (id int, value int, PRIMARY KEY (id))"); err != nil {
t.Fatal(err)
}

// QueryMessage
var customPayload = map[string][]byte{"a": []byte{10, 20}, "b": []byte{20, 30}}
query := session.Query("SELECT id FROM testCustomPayloadMessages where id = ?", 42).Consistency(One).CustomPayload(customPayload)
iter := query.Iter()
rCustomPayload := iter.GetCustomPayload()
if !reflect.DeepEqual(customPayload, rCustomPayload) {
t.Fatal("The received custom payload should match the sent")
}
iter.Close()

// Insert query
query = session.Query("INSERT INTO testCustomPayloadMessages(id,value) VALUES(1, 1)").Consistency(One).CustomPayload(customPayload)
iter = query.Iter()
rCustomPayload = iter.GetCustomPayload()
if !reflect.DeepEqual(customPayload, rCustomPayload) {
t.Fatal("The received custom payload should match the sent")
}
iter.Close()

// Batch Message
b := session.NewBatch(LoggedBatch)
b.CustomPayload = customPayload
b.Query("INSERT INTO testCustomPayloadMessages(id,value) VALUES(1, 1)")
if err := session.ExecuteBatch(b); err != nil {
t.Fatalf("query failed. %v", err)
}
}

func TestCustomPayloadValues(t *testing.T) {
cluster := createCluster()
session := createSessionFromCluster(cluster, t)
defer session.Close()

if err := createTable(session, "CREATE TABLE gocql_test.testCustomPayloadValues (id int, value int, PRIMARY KEY (id))"); err != nil {
t.Fatal(err)
}

values := []map[string][]byte{map[string][]byte{"a": []byte{10, 20}, "b": []byte{20, 30}}, nil, map[string][]byte{"a": []byte{10, 20}, "b": nil}}

for _, customPayload := range values {
query := session.Query("SELECT id FROM testCustomPayloadValues where id = ?", 42).Consistency(One).CustomPayload(customPayload)
iter := query.Iter()
rCustomPayload := iter.GetCustomPayload()
if !reflect.DeepEqual(customPayload, rCustomPayload) {
t.Fatal("The received custom payload should match the sent")
}
}
}

func TestNegativeStream(t *testing.T) {
session := createSession(t)
defer session.Close()
Expand Down Expand Up @@ -2703,24 +2592,6 @@ func TestJSONSupport(t *testing.T) {
}
}

func TestUDF(t *testing.T) {
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;'`

err := session.Query(query).Exec()
if err != nil {
t.Fatal(err)
}
}

func TestDiscoverViaProxy(t *testing.T) {
// This (complicated) test tests that when the driver is given an initial host
// that is infact a proxy it discovers the rest of the ring behind the proxy
Expand Down
2 changes: 0 additions & 2 deletions compressor_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build all unit

package gocql

import (
Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build all integration
// +build all cassandra

package gocql

Expand Down
13 changes: 1 addition & 12 deletions host_source_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build all integration
// +build all cassandra

package gocql

Expand Down Expand Up @@ -68,17 +68,6 @@ func TestIsValidPeer(t *testing.T) {
}
}

func TestGetHosts(t *testing.T) {
cluster := createCluster()
session := createSessionFromCluster(cluster, t)

hosts, partitioner, err := session.hostSource.GetHosts()

assertTrue(t, "err == nil", err == nil)
assertEqual(t, "len(hosts)", len(clusterHosts), len(hosts))
assertTrue(t, "len(partitioner) != 0", len(partitioner) != 0)
}

func TestHostInfo_ConnectAddress(t *testing.T) {
var localhost = net.IPv4(127, 0, 0, 1)
tests := []struct {
Expand Down
1 change: 1 addition & 0 deletions integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function run_tests() {
go test -run=TestAuthentication -tags "integration gocql_debug" -timeout=15s -runauth $args
else
sleep 1s
go test -tags "cassandra gocql_debug" -timeout=5m -race $args
go test -tags "integration gocql_debug" -timeout=5m -race $args

ccm clear
Expand Down
Loading

0 comments on commit fa8dbda

Please sign in to comment.