Skip to content

Commit

Permalink
Add test for writeFailure (apache#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
beltran authored and Zariel committed Sep 29, 2018
1 parent a16518d commit 7ce14ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,48 @@ func TestPrepare_PreparedCacheEviction(t *testing.T) {
}
}

func TestWriteFailure(t *testing.T) {
if flagCassVersion.Major == 0 || flagCassVersion.Before(3, 11, 0) {
t.Skipf("write failure can only be tested against Cassandra 3.11 or higher version=%v", flagCassVersion)
}
cluster := createCluster()
createKeyspace(t, cluster, "test")
cluster.Keyspace = "test"
session, err := cluster.CreateSession()
if err != nil {
t.Fatal("create session:", err)
}
defer session.Close()

if err := createTable(session, "CREATE TABLE test.test (id int,value int,PRIMARY KEY (id))"); err != nil {
t.Fatalf("failed to create table with error '%v'", err)
}
if err := session.Query(`INSERT INTO test.test (id, value) VALUES (1, 1)`).Exec(); err != nil {
errWrite, ok := err.(*RequestErrWriteFailure)
if ok {
if session.cfg.ProtoVersion >= 5 {
// ErrorMap should be filled with some hosts that should've errored
if len(errWrite.ErrorMap) == 0 {
t.Fatal("errWrite.ErrorMap should have some failed hosts but it didn't have any")
}
} else {
// Map doesn't get filled for V4
if len(errWrite.ErrorMap) != 0 {
t.Fatal("errWrite.ErrorMap should have length 0, it's: ", len(errWrite.ErrorMap))
}
}
} else {
t.Fatal("error should be RequestErrWriteFailure, it's: ", errWrite)
}
} else {
t.Fatal("a write fail error should have happened when querying test keyspace")
}

if err = session.Query("DROP KEYSPACE test").Exec(); err != nil {
t.Fatal(err)
}
}

func TestPrepare_PreparedCacheKey(t *testing.T) {
session := createSession(t)
defer session.Close()
Expand Down
4 changes: 2 additions & 2 deletions integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ function run_tests() {
elif [[ $version == 2.2.* || $version == 3.0.* ]]; then
proto=4
ccm updateconf 'enable_user_defined_functions: true'
export JVM_EXTRA_OPTS=" -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
elif [[ $version == 3.*.* ]]; then
proto=5
ccm updateconf 'enable_user_defined_functions: true'
export JVM_EXTRA_OPTS=" -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
fi

sleep 1s
Expand Down

0 comments on commit 7ce14ec

Please sign in to comment.