Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

compact and timeseries tests

  • Loading branch information...
commit d6ce8bd0cd54e81ed910e07ea7129ed254d84a5d 1 parent 3c72660
@carloscm authored
View
6 schema-test.txt
@@ -52,3 +52,9 @@ create column family Timeseries with
key_validation_class = UTF8Type and
default_validation_class = BytesType
;
+
+create column family CompositeFull with
+ comparator = 'CompositeType(BytesType,AsciiType,UTF8Type,LongType,Int32Type,UUIDType,LexicalUUIDType,TimeUUIDType,BooleanType,FloatType,DoubleType,DateType)' and
+ key_validation_class = BytesType and
+ default_validation_class = BytesType
+;
View
186 src/gossie/query_test.go
@@ -3,6 +3,7 @@ package gossie
import (
"reflect"
"testing"
+ "time"
)
/*
@@ -25,6 +26,12 @@ type ReasonableOne struct {
Body string
}
+type Timeseries struct {
+ Username string `cf:"Timeseries" key:"Username" cols:"TimeUUID"`
+ TimeUUID UUID
+ Seq int
+}
+
type ReasonableTwo struct {
Username string `cf:"ReasonableTwo" key:"Username" cols:"TweetID,Version"`
TweetID int64
@@ -34,6 +41,107 @@ type ReasonableTwo struct {
Body string
}
+type CompositeFull struct {
+ Username string `mapping:"compact" cf:"CompositeFull" key:"Username" cols:"Bytes,Ascii,UTF8,Long,Int32,UUIDf,LexicalUUID,TimeUUID,Boolean,Float,Double,Date" value:"Value"`
+ Bytes []byte
+ Ascii string
+ UTF8 string
+ Long int64
+ Int32 int `type:"Int32Type"`
+ UUIDf UUID
+ LexicalUUID UUID
+ TimeUUID UUID
+ Boolean bool
+ Float float32
+ Double float64
+ Date time.Time
+ Value int
+}
+
+func createTimeseries(t *testing.T, cp ConnectionPool) int {
+ cp.Writer().Delete("Timeseries", []byte("testuser")).Run()
+
+ mT, err := NewMapping(&Timeseries{})
+
+ // pseudo random number based on the sub-ms part of the current unix nano time
+ seqBase := int(time.Now().UnixNano() % 1e6)
+
+ w := cp.Writer()
+ for i := 0; i < 100; i++ {
+ u, err := NewTimeUUID(time.Now())
+ if err != nil {
+ t.Fatal("Error generating TimeUUID:", err)
+ }
+ r := &Timeseries{
+ Username: "testuser",
+ TimeUUID: u,
+ Seq: seqBase + i,
+ }
+ row, err := mT.Map(r)
+ if err != nil {
+ t.Fatal("Error mapping:", err)
+ }
+ w.InsertTtl("Timeseries", row, 60)
+ }
+ err = w.Run()
+ if err != nil {
+ t.Fatal("Error writing:", err)
+ }
+ return seqBase
+}
+
+func createCompositeFull(t *testing.T, cp ConnectionPool) int {
+ cp.Writer().Delete("CompositeFull", []byte("testuser")).Run()
+
+ mC, err := NewMapping(&CompositeFull{})
+
+ // pseudo random number based on the sub-ms part of the current unix nano time
+ seqBase := int(time.Now().UnixNano() % 1e6)
+
+ w := cp.Writer()
+
+ uR1, err := NewRandomUUID()
+ if err != nil {
+ t.Fatal("Error generating random UUID:", err)
+ }
+ uR2, err := NewRandomUUID()
+ if err != nil {
+ t.Fatal("Error generating random UUID:", err)
+ }
+ for i := 0; i < 100; i++ {
+ uT, err := NewTimeUUID(time.Now())
+ if err != nil {
+ t.Fatal("Error generating TimeUUID:", err)
+ }
+ r := &CompositeFull{
+ Username: "testuser",
+ Bytes: []byte("yep"),
+ Ascii: "good",
+ UTF8: "works",
+ Long: int64(i / 10),
+ Int32: -42,
+ UUIDf: uR1,
+ LexicalUUID: uR2,
+ TimeUUID: uT,
+ Boolean: true,
+ Float: 42.42,
+ Double: 4e42,
+ Date: time.Now(),
+ Value: seqBase + i,
+ }
+ row, err := mC.Map(r)
+ if err != nil {
+ t.Fatal("Error mapping:", err)
+ }
+ w.InsertTtl("CompositeFull", row, 60)
+ }
+ err = w.Run()
+ if err != nil {
+ t.Fatal("Error writing:", err)
+ }
+ return seqBase
+}
+
func TestQueryGet(t *testing.T) {
cp, err := NewConnectionPool([]string{"127.0.0.1:9160"}, "TestGossie", PoolOptions{Size: 1, Timeout: 1000})
if err != nil {
@@ -52,6 +160,14 @@ func TestQueryGet(t *testing.T) {
if err != nil {
t.Fatal("Error building mapping:", err)
}
+ mT, err := NewMapping(&Timeseries{})
+ if err != nil {
+ t.Fatal("Error building mapping:", err)
+ }
+ mC, err := NewMapping(&CompositeFull{})
+ if err != nil {
+ t.Fatal("Error building mapping:", err)
+ }
w := cp.Writer()
r := &ReasonableZero{"testuser", 1.00002, -38.11, "hey this thing appears to work, nice!"}
@@ -59,7 +175,7 @@ func TestQueryGet(t *testing.T) {
if err != nil {
t.Fatal("Error mapping:", err)
}
- w.Insert("ReasonableZero", row)
+ w.InsertTtl("ReasonableZero", row, 60)
err = w.Run()
if err != nil {
t.Fatal("Error writing:", err)
@@ -78,7 +194,7 @@ func TestQueryGet(t *testing.T) {
if err != nil {
t.Fatal("Error mapping:", err)
}
- w.Insert("ReasonableOne", row)
+ w.InsertTtl("ReasonableOne", row, 60)
}
err = w.Run()
if err != nil {
@@ -100,7 +216,7 @@ func TestQueryGet(t *testing.T) {
if err != nil {
t.Fatal("Error mapping:", err)
}
- w.Insert("ReasonableTwo", row)
+ w.InsertTtl("ReasonableTwo", row, 60)
}
}
err = w.Run()
@@ -221,6 +337,47 @@ func TestQueryGet(t *testing.T) {
/////
+ seqBase := createTimeseries(t, cp)
+ qT := cp.Query(mT)
+ rT := &Timeseries{}
+
+ res, err = qT.Get("testuser")
+ if err != nil {
+ t.Fatal("Query get error:", err)
+ }
+ for i := 99; i >= 0; i-- {
+ err = res.Next(rT)
+ if err != nil {
+ t.Fatal("Result next error:", err)
+ }
+ if rT.Seq != seqBase+i {
+ t.Log(rT)
+ t.Error("Read does not match Write")
+ }
+ }
+
+ seqBase = createTimeseries(t, cp)
+
+ qT.Reversed(true)
+
+ res, err = qT.Get("testuser")
+ if err != nil {
+ t.Fatal("Query get error:", err)
+ }
+ for i := 0; i < 100; i++ {
+ err = res.Next(rT)
+ if err != nil {
+ t.Fatal("Result next error:", err)
+ }
+ if rT.Seq != seqBase+i {
+ t.Log(seqBase + i)
+ t.Log(rT)
+ t.Error("Read does not match Write")
+ }
+ }
+
+ /////
+
q2 := cp.Query(m2)
r2 := &ReasonableTwo{}
@@ -357,4 +514,27 @@ func TestQueryGet(t *testing.T) {
t.Fatal("Result Next is not Done:", err)
}
+ /////
+
+ seqBase = createCompositeFull(t, cp)
+
+ qC := cp.Query(mC)
+ rC := &CompositeFull{}
+
+ res, err = qC.Get("testuser")
+ if err != nil {
+ t.Fatal("Query get error:", err)
+ }
+ for i := 0; i < 100; i++ {
+ err = res.Next(rC)
+ if err != nil {
+ t.Fatal("Result next error:", err)
+ }
+ if rC.Value != seqBase+i {
+ t.Log(seqBase + i)
+ t.Log(rT)
+ t.Error("Read does not match Write")
+ }
+ }
+
}
View
4 src/gossie/schema_test.go
@@ -16,8 +16,8 @@ func TestSchema(t *testing.T) {
schema := newSchema(ksDef)
defer c.close()
- if len(schema.ColumnFamilies) != 7 {
- t.Error("Test schema must have 7 CFs")
+ if len(schema.ColumnFamilies) != 8 {
+ t.Error("Test schema must have 8 CFs")
}
if schema.ColumnFamilies["AllTypes"] == nil {
View
5 src/gossie/types.go
@@ -733,6 +733,11 @@ func defaultType(t reflect.Type) TypeDesc {
return UUIDType
}
return UnknownType
+ case reflect.Struct:
+ if t.Name() == "Time" && t.PkgPath() == "time" {
+ return DateType
+ }
+ return UnknownType
case reflect.Slice:
if et := t.Elem(); et.Kind() == reflect.Uint8 {
return BytesType
View
1  src/gossie/uuid.go
@@ -11,6 +11,7 @@ import (
/*
to do:
+ implement concurrent get with atomic increment of prev timestamp, like in Java
check correctness of NewTimeUUID
comparison
comp func
View
13 src/gossie/writer.go
@@ -22,6 +22,9 @@ type Writer interface {
// Insert adds a new row insertion to the mutation
Insert(cf string, row *Row) Writer
+ // InsertTtl adds a new row insertion to the mutation, overriding the columns Ttl with the passed value
+ InsertTtl(cf string, row *Row, ttl int) Writer
+
// DeltaCounters add a new delta operation over counters
DeltaCounters(cf string, row *Row) Writer
@@ -81,13 +84,21 @@ func (w *writer) ConsistencyLevel(l int) Writer {
}
func (w *writer) Insert(cf string, row *Row) Writer {
+ return w.InsertTtl(cf, row, -1)
+}
+
+func (w *writer) InsertTtl(cf string, row *Row, ttl int) Writer {
t := now()
for _, col := range row.Columns {
tm := w.addWriter(cf, row.Key)
c := cassandra.NewColumn()
c.Name = col.Name
c.Value = col.Value
- c.Ttl = col.Ttl
+ if ttl > 0 {
+ c.Ttl = int32(ttl)
+ } else {
+ c.Ttl = c.Ttl
+ }
if col.Timestamp > 0 {
c.Timestamp = col.Timestamp
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.