Skip to content

Commit

Permalink
use control connection to create tables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zariel committed Oct 18, 2015
1 parent e5248ed commit 1b70812
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cass1batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestProto1BatchInsert(t *testing.T) {
session := createSession(t)
if err := createTable(session, "CREATE TABLE large (id int primary key)"); err != nil {
if err := createTable(session, "CREATE TABLE gocql_test.large (id int primary key)"); err != nil {
t.Fatal(err)
}
defer session.Close()
Expand Down
93 changes: 44 additions & 49 deletions cassandra_test.go

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *controlConn) HandleError(conn *Conn, err error, closed bool) {

oldConn := c.conn.Load().(*Conn)
if oldConn != conn {
panic("controlConn: got error for connection which we did not create")
return
}

c.reconnect()
Expand Down Expand Up @@ -151,11 +151,8 @@ func (c *controlConn) query(statement string, values ...interface{}) (iter *Iter
}

iter = conn.executeQuery(q)
if iter.err == nil {
break
}

if !c.retry.Attempt(q) {
q.attempts++
if iter.err == nil || !c.retry.Attempt(q) {
break
}
}
Expand Down
8 changes: 4 additions & 4 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ func TestErrorsParse(t *testing.T) {
session := createSession(t)
defer session.Close()

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

if err := createTable(session, `CREATE TABLE errors_parse (id int primary key)`); err == nil {
if err := createTable(session, `CREATE TABLE gocql_test.errors_parse (id int primary key)`); err == nil {
t.Fatal("Should have gotten already exists error from cassandra server.")
} else {
switch e := err.(type) {
case *RequestErrAlreadyExists:
if e.Table != "errors_parse" {
t.Fatal("Failed to parse error response from cassandra for ErrAlreadyExists.")
t.Fatalf("expected error table to be 'errors_parse' but was %q", e.Table)
}
default:
t.Fatal("Failed to parse error response from cassandra for ErrAlreadyExists.")
t.Fatalf("expected to get RequestErrAlreadyExists instead got %T", e)
}
}
}
8 changes: 6 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ func (s *Session) executeQuery(qry *Query) *Iter {

//Assign the error unavailable to the iterator
if conn == nil {
iter = &Iter{err: ErrNoConnections}
break
if qry.rt == nil || !qry.rt.Attempt(qry) {
iter = &Iter{err: ErrNoConnections}
break
}

continue
}

t := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion tuple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestTupleSimple(t *testing.T) {
session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TABLE tuple_test(
err := createTable(session, `CREATE TABLE gocql_test.tuple_test(
id int,
coord frozen<tuple<int, int>>,
Expand Down
20 changes: 10 additions & 10 deletions udt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func TestUDT_Marshaler(t *testing.T) {
session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TYPE position(
err := createTable(session, `CREATE TYPE gocql_test.position(
lat int,
lon int,
padding text);`)
if err != nil {
t.Fatal(err)
}

err = createTable(session, `CREATE TABLE houses(
err = createTable(session, `CREATE TABLE gocql_test.houses(
id int,
name text,
loc frozen<position>,
Expand Down Expand Up @@ -108,14 +108,14 @@ func TestUDT_Reflect(t *testing.T) {
session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TYPE horse(
err := createTable(session, `CREATE TYPE gocql_test.horse(
name text,
owner text);`)
if err != nil {
t.Fatal(err)
}

err = createTable(session, `CREATE TABLE horse_race(
err = createTable(session, `CREATE TABLE gocql_test.horse_race(
position int,
horse frozen<horse>,
Expand Down Expand Up @@ -167,14 +167,14 @@ func TestUDT_Proto2error(t *testing.T) {
}
defer session.Close()

err = createTable(session, `CREATE TYPE fish(
err = createTable(session, `CREATE TYPE gocql_test.fish(
name text,
owner text);`)
if err != nil {
t.Fatal(err)
}

err = createTable(session, `CREATE TABLE fish_race(
err = createTable(session, `CREATE TABLE gocql_test.fish_race(
position int,
fish frozen<fish>,
Expand Down Expand Up @@ -208,14 +208,14 @@ func TestUDT_NullObject(t *testing.T) {
session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TYPE udt_null_type(
err := createTable(session, `CREATE TYPE gocql_test.udt_null_type(
name text,
owner text);`)
if err != nil {
t.Fatal(err)
}

err = createTable(session, `CREATE TABLE udt_null_table(
err = createTable(session, `CREATE TABLE gocql_test.udt_null_table(
id uuid,
udt_col frozen<udt_null_type>,
Expand Down Expand Up @@ -262,15 +262,15 @@ func TestMapScanUDT(t *testing.T) {
session := createSession(t)
defer session.Close()

err := createTable(session, `CREATE TYPE log_entry (
err := createTable(session, `CREATE TYPE gocql_test.log_entry (
created_timestamp timestamp,
message text
);`)
if err != nil {
t.Fatal(err)
}

err = createTable(session, `CREATE TABLE requests_by_id (
err = createTable(session, `CREATE TABLE gocql_test.requests_by_id (
id uuid PRIMARY KEY,
type int,
log_entries list<frozen <log_entry>>
Expand Down
4 changes: 2 additions & 2 deletions wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type WikiTest struct {

func CreateSchema(session *Session, tb testing.TB, table string) *WikiTest {
table = "wiki_" + table
if err := session.Query(fmt.Sprintf("DROP TABLE IF EXISTS %s", table)).Exec(); err != nil {
if err := createTable(session, fmt.Sprintf("DROP TABLE IF EXISTS gocql_test.%s", table)); err != nil {
tb.Fatal("CreateSchema:", err)
}

err := createTable(session, fmt.Sprintf(`CREATE TABLE %s (
err := createTable(session, fmt.Sprintf(`CREATE TABLE gocql_test.%s (
title varchar,
revid timeuuid,
body varchar,
Expand Down

0 comments on commit 1b70812

Please sign in to comment.