Skip to content

Commit

Permalink
Merge pull request apache#463 from Zariel/proto-v4
Browse files Browse the repository at this point in the history
Proto v4
  • Loading branch information
Zariel committed Sep 5, 2015
2 parents 5c2d890 + 40e33bf commit 3bc659a
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ env:
global:
- GOMAXPROCS=2
matrix:
- CASS=1.2.19 AUTH=false
- CASS=2.0.14 AUTH=false
- CASS=2.0.16 AUTH=false
- CASS=2.1.5 AUTH=false
- CASS=2.1.5 AUTH=true
- CASS=2.2.0 AUTH=false

go:
- 1.4
Expand Down
1 change: 0 additions & 1 deletion cass1batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestProto1BatchInsert(t *testing.T) {
if err := session.Query(fullQuery, args...).Consistency(Quorum).Exec(); err != nil {
t.Fatal(err)
}

}

func TestShouldPrepareFunction(t *testing.T) {
Expand Down
61 changes: 39 additions & 22 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,34 @@ func createCluster() *ClusterConfig {
}

func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {
session, err := cluster.CreateSession()
c := *cluster
c.Keyspace = "system"
session, err := c.CreateSession()
if err != nil {
tb.Fatal("createSession:", err)
}
defer session.Close()
if err = session.Query(`DROP KEYSPACE IF EXISTS ` + keyspace).Exec(); err != nil {
tb.Log("drop keyspace:", err)

// should reuse the same conn apparently
conn := session.Pool.Pick(nil)
if conn == nil {
tb.Fatal("no connections available in the pool")
}

err = conn.executeQuery(session.Query(`DROP KEYSPACE IF EXISTS ` + keyspace).Consistency(All)).Close()
if err != nil {
tb.Fatal(err)
}
if err := session.Query(fmt.Sprintf(`CREATE KEYSPACE %s

query := session.Query(fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'SimpleStrategy',
'replication_factor' : %d
}`, keyspace, *flagRF)).Consistency(All).Exec(); err != nil {
tb.Fatalf("error creating keyspace %s: %v", keyspace, err)
}`, keyspace, *flagRF)).Consistency(All)

if err = conn.executeQuery(query).Close(); err != nil {
tb.Fatal(err)
}

tb.Logf("Created keyspace %s", keyspace)
}

Expand Down Expand Up @@ -1072,14 +1085,16 @@ func injectInvalidPreparedStatement(t *testing.T, session *Session, table string
stmtsLRU.Unlock()
flight.info = &resultPreparedFrame{
preparedID: []byte{'f', 'o', 'o', 'b', 'a', 'r'},
reqMeta: resultMetadata{
columns: []ColumnInfo{
{
Keyspace: "gocql_test",
Table: table,
Name: "foo",
TypeInfo: NativeType{
typ: TypeVarchar,
reqMeta: preparedMetadata{
resultMetadata: resultMetadata{
columns: []ColumnInfo{
{
Keyspace: "gocql_test",
Table: table,
Name: "foo",
TypeInfo: NativeType{
typ: TypeVarchar,
},
},
},
}},
Expand Down Expand Up @@ -1638,13 +1653,15 @@ func TestGetTableMetadata(t *testing.T) {
if testTable.DefaultValidator != "org.apache.cassandra.db.marshal.BytesType" {
t.Errorf("Expected test_table_metadata key validator to be 'org.apache.cassandra.db.marshal.BytesType' but was '%s'", testTable.DefaultValidator)
}
expectedKeyAliases := []string{"first_id"}
if !reflect.DeepEqual(testTable.KeyAliases, expectedKeyAliases) {
t.Errorf("Expected key aliases %v but was %v", expectedKeyAliases, testTable.KeyAliases)
}
expectedColumnAliases := []string{"second_id"}
if !reflect.DeepEqual(testTable.ColumnAliases, expectedColumnAliases) {
t.Errorf("Expected key aliases %v but was %v", expectedColumnAliases, testTable.ColumnAliases)
if *flagProto < protoVersion4 {
expectedKeyAliases := []string{"first_id"}
if !reflect.DeepEqual(testTable.KeyAliases, expectedKeyAliases) {
t.Errorf("Expected key aliases %v but was %v", expectedKeyAliases, testTable.KeyAliases)
}
expectedColumnAliases := []string{"second_id"}
if !reflect.DeepEqual(testTable.ColumnAliases, expectedColumnAliases) {
t.Errorf("Expected key aliases %v but was %v", expectedColumnAliases, testTable.ColumnAliases)
}
}
if testTable.ValueAlias != "" {
t.Errorf("Expected value alias '' but was '%s'", testTable.ValueAlias)
Expand Down
6 changes: 3 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func Connect(addr string, cfg ConnConfig, errorHandler ConnErrorHandler) (*Conn,
}

// going to default to proto 2
if cfg.ProtoVersion < protoVersion1 || cfg.ProtoVersion > protoVersion3 {
if cfg.ProtoVersion < protoVersion1 || cfg.ProtoVersion > protoVersion4 {
log.Printf("unsupported protocol version: %d using 2\n", cfg.ProtoVersion)
cfg.ProtoVersion = 2
}
Expand Down Expand Up @@ -653,7 +653,7 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
}

return iter
case *resultKeyspaceFrame, *resultSchemaChangeFrame:
case *resultKeyspaceFrame, *resultSchemaChangeFrame, *schemaChangeKeyspace, *schemaChangeTable:
return &Iter{}
case *RequestErrUnprepared:
stmtsLRU.Lock()
Expand All @@ -668,7 +668,7 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
case error:
return &Iter{err: x}
default:
return &Iter{err: NewErrProtocol("Unknown type in response to execute query: %s", x)}
return &Iter{err: NewErrProtocol("Unknown type in response to execute query (%T): %s", x, x)}
}
}

Expand Down
48 changes: 33 additions & 15 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package gocql
import "fmt"

const (
errServer = 0x0000
errProtocol = 0x000A
errCredentials = 0x0100
errUnavailable = 0x1000
errOverloaded = 0x1001
errBootstrapping = 0x1002
errTruncate = 0x1003
errWriteTimeout = 0x1100
errReadTimeout = 0x1200
errSyntax = 0x2000
errUnauthorized = 0x2100
errInvalid = 0x2200
errConfig = 0x2300
errAlreadyExists = 0x2400
errUnprepared = 0x2500
errServer = 0x0000
errProtocol = 0x000A
errCredentials = 0x0100
errUnavailable = 0x1000
errOverloaded = 0x1001
errBootstrapping = 0x1002
errTruncate = 0x1003
errWriteTimeout = 0x1100
errReadTimeout = 0x1200
errReadFailure = 0x1300
errFunctionFailure = 0x1400
errSyntax = 0x2000
errUnauthorized = 0x2100
errInvalid = 0x2200
errConfig = 0x2300
errAlreadyExists = 0x2400
errUnprepared = 0x2500
)

type RequestError interface {
Expand Down Expand Up @@ -86,3 +88,19 @@ type RequestErrUnprepared struct {
errorFrame
StatementId []byte
}

type RequestErrReadFailure struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
NumFailures int
DataPresent bool
}

type RequestErrFunctionFailure struct {
errorFrame
Keyspace string
Function string
ArgTypes []string
}
Loading

0 comments on commit 3bc659a

Please sign in to comment.