|
|
@@ -27,6 +27,10 @@ func createSession(t *testing.T) *Session {
|
|
|
cluster := NewCluster(strings.Split(*flagCluster, ",")...)
|
|
|
cluster.ProtoVersion = *flagProto
|
|
|
cluster.CQLVersion = *flagCQL
|
|
|
+ cluster.Authenticator = PasswordAuthenticator{
|
|
|
+ Username: "cassandra",
|
|
|
+ Password: "cassandra",
|
|
|
+ }
|
|
|
|
|
|
session, err := cluster.CreateSession()
|
|
|
if err != nil {
|
|
|
@@ -148,6 +152,9 @@ func TestTracing(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestPaging(t *testing.T) {
|
|
|
+
|
|
|
+ t.Skip("Skip until https://github.com/gocql/gocql/issues/110 is resolved")
|
|
|
+
|
|
|
if *flagProto == 1 {
|
|
|
t.Skip("Paging not supported. Please use Cassandra >= 2.0")
|
|
|
}
|
|
|
@@ -245,6 +252,29 @@ func TestBatch(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 err := session.Query(`CREATE TABLE batch_table2 (id int primary key)`).Exec(); err != nil {
|
|
|
+ t.Fatal("create table:", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ batch := NewBatch(LoggedBatch)
|
|
|
+ for i := 0; i < 65537; i++ {
|
|
|
+ batch.Query(`INSERT INTO batch_table2 (id) VALUES (?)`, i)
|
|
|
+ }
|
|
|
+ if err := session.ExecuteBatch(batch); err != ErrTooManyStmts {
|
|
|
+ t.Fatal("gocql attempted to execute a batch larger than the support limit of statements.")
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
type Page struct {
|
|
|
Title string
|
|
|
RevId UUID
|
|
|
@@ -277,3 +307,109 @@ var pageTestData = []*Page{
|
|
|
Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
|
|
|
},
|
|
|
}
|
|
|
+
|
|
|
+func TestSliceMap(t *testing.T) {
|
|
|
+ session := createSession(t)
|
|
|
+ defer session.Close()
|
|
|
+ if err := session.Query(`CREATE TABLE slice_map_table (
|
|
|
+ testuuid timeuuid PRIMARY KEY,
|
|
|
+ testvarchar varchar,
|
|
|
+ testbigint bigint,
|
|
|
+ testblob blob,
|
|
|
+ testbool boolean,
|
|
|
+ testfloat float,
|
|
|
+ testdouble double,
|
|
|
+ testint int,
|
|
|
+ testset set<int>,
|
|
|
+ testmap map<varchar, varchar>
|
|
|
+ )`).Exec(); err != nil {
|
|
|
+ t.Fatal("create table:", err)
|
|
|
+ }
|
|
|
+ m := make(map[string]interface{})
|
|
|
+ m["testuuid"] = TimeUUID()
|
|
|
+ m["testvarchar"] = "Test VarChar"
|
|
|
+ m["testbigint"] = time.Now().Unix()
|
|
|
+ m["testblob"] = []byte("test blob")
|
|
|
+ m["testbool"] = true
|
|
|
+ m["testfloat"] = float32(4.564)
|
|
|
+ m["testdouble"] = float64(4.815162342)
|
|
|
+ m["testint"] = 2343
|
|
|
+ m["testset"] = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
|
+ m["testmap"] = map[string]string{"field1": "val1", "field2": "val2", "field3": "val3"}
|
|
|
+ sliceMap := []map[string]interface{}{m}
|
|
|
+ if err := session.Query(`INSERT INTO slice_map_table (testuuid, testvarchar, testbigint, testblob, testbool, testfloat, testdouble, testint, testset, testmap) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
+ m["testuuid"], m["testvarchar"], m["testbigint"], m["testblob"], m["testbool"], m["testfloat"], m["testdouble"], m["testint"], m["testset"], m["testmap"]).Exec(); err != nil {
|
|
|
+ t.Fatal("insert:", err)
|
|
|
+ }
|
|
|
+ if returned, retErr := session.Query(`SELECT * FROM slice_map_table`).Iter().SliceMap(); retErr != nil {
|
|
|
+ t.Fatal("select:", retErr)
|
|
|
+ } else {
|
|
|
+ if sliceMap[0]["testuuid"] != returned[0]["testuuid"] {
|
|
|
+ t.Fatal("returned testuuid did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testvarchar"] != returned[0]["testvarchar"] {
|
|
|
+ t.Fatal("returned testvarchar did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testbigint"] != returned[0]["testbigint"] {
|
|
|
+ t.Fatal("returned testbigint did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testblob"], returned[0]["testblob"]) {
|
|
|
+ t.Fatal("returned testblob did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testbool"] != returned[0]["testbool"] {
|
|
|
+ t.Fatal("returned testbool did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testfloat"] != returned[0]["testfloat"] {
|
|
|
+ t.Fatal("returned testfloat did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testdouble"] != returned[0]["testdouble"] {
|
|
|
+ t.Fatal("returned testdouble did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testint"] != returned[0]["testint"] {
|
|
|
+ t.Fatal("returned testint did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testset"], returned[0]["testset"]) {
|
|
|
+ t.Fatal("returned testset did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testmap"], returned[0]["testmap"]) {
|
|
|
+ t.Fatal("returned testmap did not match")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Test for MapScan()
|
|
|
+ testMap := make(map[string]interface{})
|
|
|
+ if !session.Query(`SELECT * FROM slice_map_table`).Iter().MapScan(testMap) {
|
|
|
+ t.Fatal("MapScan failed to work with one row")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testuuid"] != testMap["testuuid"] {
|
|
|
+ t.Fatal("returned testuuid did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testvarchar"] != testMap["testvarchar"] {
|
|
|
+ t.Fatal("returned testvarchar did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testbigint"] != testMap["testbigint"] {
|
|
|
+ t.Fatal("returned testbigint did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testblob"], testMap["testblob"]) {
|
|
|
+ t.Fatal("returned testblob did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testbool"] != testMap["testbool"] {
|
|
|
+ t.Fatal("returned testbool did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testfloat"] != testMap["testfloat"] {
|
|
|
+ t.Fatal("returned testfloat did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testdouble"] != testMap["testdouble"] {
|
|
|
+ t.Fatal("returned testdouble did not match")
|
|
|
+ }
|
|
|
+ if sliceMap[0]["testint"] != testMap["testint"] {
|
|
|
+ t.Fatal("returned testint did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testset"], testMap["testset"]) {
|
|
|
+ t.Fatal("returned testset did not match")
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(sliceMap[0]["testmap"], testMap["testmap"]) {
|
|
|
+ t.Fatal("returned testmap did not match")
|
|
|
+ }
|
|
|
+
|
|
|
+}
|