Pārlūkot izejas kodu

better test cases

Christoph Hack 12 gadi atpakaļ
vecāks
revīzija
2d4323d020
6 mainītis faili ar 321 papildinājumiem un 328 dzēšanām
  1. 281 0
      cassandra_test.go
  2. 20 6
      conn_test.go
  3. 0 289
      gocql_test/main.go
  4. 9 1
      marshal.go
  5. 10 31
      uuid/uuid.go
  6. 1 1
      uuid/uuid_test.go

+ 281 - 0
cassandra_test.go

@@ -0,0 +1,281 @@
+// Copyright (c) 2012 The gocql Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package gocql
+
+import (
+	"bytes"
+	"flag"
+	"reflect"
+	"sort"
+	"strings"
+	"sync"
+	"testing"
+	"time"
+
+	"tux21b.org/v1/gocql/uuid"
+)
+
+var (
+	flagCluster = flag.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
+	flagProto   = flag.Int("proto", 2, "protcol version")
+	flagCQL     = flag.String("cql", "3.0.0", "CQL version")
+)
+
+var initOnce sync.Once
+
+func createSession(t *testing.T) *Session {
+	cluster := NewCluster(strings.Split(*flagCluster, ",")...)
+	cluster.ProtoVersion = *flagProto
+	cluster.CQLVersion = *flagCQL
+
+	session, err := cluster.CreateSession()
+	if err != nil {
+		t.Fatal("createSession:", err)
+	}
+
+	initOnce.Do(func() {
+		// Drop and re-create the keyspace once. Different tests should use their own
+		// individual tables, but can assume that the table does not exist before.
+		if err := session.Query(`DROP KEYSPACE gocql_test`).Exec(); err != nil {
+			t.Log("drop keyspace:", err)
+		}
+		if err := session.Query(`CREATE KEYSPACE gocql_test
+			WITH replication = {
+				'class' : 'SimpleStrategy',
+				'replication_factor' : 1
+			}`).Exec(); err != nil {
+			t.Fatal("create keyspace:", err)
+		}
+	})
+
+	if err := session.Query(`USE gocql_test`).Exec(); err != nil {
+		t.Fatal("createSession:", err)
+	}
+
+	return session
+}
+
+func TestEmptyHosts(t *testing.T) {
+	cluster := NewCluster()
+	if session, err := cluster.CreateSession(); err == nil {
+		session.Close()
+		t.Error("expected err, got nil")
+	}
+}
+
+func TestCRUD(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+
+	if err := session.Query(`CREATE TABLE page (
+			title       varchar,
+			revid       timeuuid,
+			body        varchar,
+			views       bigint,
+			protected   boolean,
+			modified    timestamp,
+			tags        set<varchar>,
+			attachments map<varchar, text>,
+			PRIMARY KEY (title, revid)
+		)`).Exec(); err != nil {
+		t.Fatal("create table:", err)
+	}
+
+	for _, page := range pageTestData {
+		if err := session.Query(`INSERT INTO page
+			(title, revid, body, views, protected, modified, tags, attachments)
+			VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
+			page.Title, page.RevId, page.Body, page.Views, page.Protected,
+			page.Modified, page.Tags, page.Attachments).Exec(); err != nil {
+			t.Fatal("insert:", err)
+		}
+	}
+
+	var count int
+	if err := session.Query("SELECT COUNT(*) FROM page").Scan(&count); err != nil {
+		t.Error("select count:", err)
+	}
+	if count != len(pageTestData) {
+		t.Errorf("count: expected %d, got %d\n", len(pageTestData), count)
+	}
+
+	for _, original := range pageTestData {
+		page := new(Page)
+		err := session.Query(`SELECT title, revid, body, views, protected, modified,
+			tags, attachments
+			FROM page WHERE title = ? AND revid = ? LIMIT 1`,
+			original.Title, original.RevId).Scan(&page.Title, &page.RevId,
+			&page.Body, &page.Views, &page.Protected, &page.Modified, &page.Tags,
+			&page.Attachments)
+		if err != nil {
+			t.Error("select page:", err)
+			continue
+		}
+		sort.Sort(sort.StringSlice(page.Tags))
+		sort.Sort(sort.StringSlice(original.Tags))
+		if !reflect.DeepEqual(page, original) {
+			t.Errorf("page: expected %#v, got %#v\n", original, page)
+		}
+	}
+}
+
+func TestTracing(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+
+	if err := session.Query(`CREATE TABLE trace (id int primary key)`).Exec(); err != nil {
+		t.Fatal("create:", err)
+	}
+
+	buf := &bytes.Buffer{}
+	trace := NewTraceWriter(session, buf)
+
+	if err := session.Query(`INSERT INTO trace (id) VALUES (?)`, 42).Trace(trace).Exec(); err != nil {
+		t.Error("insert:", err)
+	} else if buf.Len() == 0 {
+		t.Error("insert: failed to obtain any tracing")
+	}
+	buf.Reset()
+
+	var value int
+	if err := session.Query(`SELECT id FROM trace WHERE id = ?`, 42).Trace(trace).Scan(&value); err != nil {
+		t.Error("select:", err)
+	} else if value != 42 {
+		t.Errorf("value: expected %d, got %d", 42, value)
+	} else if buf.Len() == 0 {
+		t.Error("select: failed to obtain any tracing")
+	}
+}
+
+func TestPaging(t *testing.T) {
+	if *flagProto == 1 {
+		t.Skip("Paging not supported. Please use Cassandra >= 2.0")
+	}
+
+	session := createSession(t)
+	defer session.Close()
+
+	if err := session.Query("CREATE TABLE large (id int primary key)").Exec(); err != nil {
+		t.Fatal("create table:", err)
+	}
+	for i := 0; i < 100; i++ {
+		if err := session.Query("INSERT INTO large (id) VALUES (?)", i).Exec(); err != nil {
+			t.Fatal("insert:", err)
+		}
+	}
+
+	iter := session.Query("SELECT id FROM large").PageSize(10).Iter()
+	var id int
+	count := 0
+	for iter.Scan(&id) {
+		count++
+	}
+	if err := iter.Close(); err != nil {
+		t.Fatal("close:", err)
+	}
+	if count != 100 {
+		t.Fatalf("expected %d, got %d", 100, count)
+	}
+}
+
+func TestCAS(t *testing.T) {
+	if *flagProto == 1 {
+		t.Skip("lightweight transactions not supported. Please use Cassandra >= 2.0")
+	}
+
+	session := createSession(t)
+	defer session.Close()
+
+	if err := session.Query(`CREATE TABLE cas_table (
+			title   varchar,
+			revid   timeuuid,
+			PRIMARY KEY (title, revid)
+		)`).Exec(); err != nil {
+		t.Fatal("create:", err)
+	}
+
+	title, revid := "baz", uuid.TimeUUID()
+	var titleCAS string
+	var revidCAS uuid.UUID
+
+	if applied, err := session.Query(`INSERT INTO cas_table (title, revid)
+		VALUES (?, ?) IF NOT EXISTS`,
+		title, revid).ScanCAS(&titleCAS, &revidCAS); err != nil {
+		t.Fatal("insert:", err)
+	} else if !applied {
+		t.Fatal("insert should have been applied")
+	}
+
+	if applied, err := session.Query(`INSERT INTO cas_table (title, revid)
+		VALUES (?, ?) IF NOT EXISTS`,
+		title, revid).ScanCAS(&titleCAS, &revidCAS); err != nil {
+		t.Fatal("insert:", err)
+	} else if applied {
+		t.Fatal("insert should not have been applied")
+	} else if title != titleCAS || revid != revidCAS {
+		t.Fatalf("expected %s/%v but got %s/%v", title, revid, titleCAS, revidCAS)
+	}
+}
+
+func TestBatch(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_table (id int primary key)`).Exec(); err != nil {
+		t.Fatal("create table:", err)
+	}
+
+	batch := NewBatch(LoggedBatch)
+	for i := 0; i < 100; i++ {
+		batch.Query(`INSERT INTO batch_table (id) VALUES (?)`, i)
+	}
+	if err := session.ExecuteBatch(batch); err != nil {
+		t.Fatal("execute batch:", err)
+	}
+
+	count := 0
+	if err := session.Query(`SELECT COUNT(*) FROM batch_table`).Scan(&count); err != nil {
+		t.Fatal("select count:", err)
+	} else if count != 100 {
+		t.Fatalf("count: expected %d, got %d\n", 100, count)
+	}
+}
+
+type Page struct {
+	Title       string
+	RevId       uuid.UUID
+	Body        string
+	Views       int64
+	Protected   bool
+	Modified    time.Time
+	Tags        []string
+	Attachments map[string]Attachment
+}
+
+type Attachment []byte
+
+var pageTestData = []*Page{
+	&Page{
+		Title:    "Frontpage",
+		RevId:    uuid.TimeUUID(),
+		Body:     "Welcome to this wiki page!",
+		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
+		Tags:     []string{"start", "important", "test"},
+		Attachments: map[string]Attachment{
+			"logo":    Attachment("\x00company logo\x00"),
+			"favicon": Attachment("favicon.ico"),
+		},
+	},
+	&Page{
+		Title:    "Foobar",
+		RevId:    uuid.TimeUUID(),
+		Body:     "foo::Foo f = new foo::Foo(foo::Foo::INIT);",
+		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
+	},
+}

+ 20 - 6
conn_test.go

@@ -25,7 +25,10 @@ func TestSimple(t *testing.T) {
 	srv := NewTestServer(t)
 	defer srv.Stop()
 
-	db := NewCluster(srv.Address).CreateSession()
+	db, err := NewCluster(srv.Address).CreateSession()
+	if err != nil {
+		t.Errorf("NewCluster: %v", err)
+	}
 
 	if err := db.Query("void").Exec(); err != nil {
 		t.Error(err)
@@ -36,8 +39,10 @@ func TestClosed(t *testing.T) {
 	srv := NewTestServer(t)
 	defer srv.Stop()
 
-	session := NewCluster(srv.Address).CreateSession()
-
+	session, err := NewCluster(srv.Address).CreateSession()
+	if err != nil {
+		t.Errorf("NewCluster: %v", err)
+	}
 	session.Close()
 
 	if err := session.Query("void").Exec(); err != ErrUnavailable {
@@ -49,7 +54,10 @@ func TestTimeout(t *testing.T) {
 	srv := NewTestServer(t)
 	defer srv.Stop()
 
-	db := NewCluster(srv.Address).CreateSession()
+	db, err := NewCluster(srv.Address).CreateSession()
+	if err != nil {
+		t.Errorf("NewCluster: %v", err)
+	}
 
 	go func() {
 		<-time.After(1 * time.Second)
@@ -65,7 +73,10 @@ func TestSlowQuery(t *testing.T) {
 	srv := NewTestServer(t)
 	defer srv.Stop()
 
-	db := NewCluster(srv.Address).CreateSession()
+	db, err := NewCluster(srv.Address).CreateSession()
+	if err != nil {
+		t.Errorf("NewCluster: %v", err)
+	}
 
 	if err := db.Query("slow").Exec(); err != nil {
 		t.Fatal(err)
@@ -82,7 +93,10 @@ func TestRoundRobin(t *testing.T) {
 	}
 	cluster := NewCluster(addrs...)
 	cluster.StartupMin = len(addrs)
-	db := cluster.CreateSession()
+	db, err := cluster.CreateSession()
+	if err != nil {
+		t.Errorf("NewCluster: %v", err)
+	}
 
 	var wg sync.WaitGroup
 	wg.Add(5)

+ 0 - 289
gocql_test/main.go

@@ -1,289 +0,0 @@
-// Copyright (c) 2012 The gocql Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import (
-	"fmt"
-	"log"
-	"os"
-	"reflect"
-	"sort"
-	"time"
-
-	"tux21b.org/v1/gocql"
-	"tux21b.org/v1/gocql/uuid"
-)
-
-var cluster *gocql.ClusterConfig
-var session *gocql.Session
-
-func init() {
-	cluster = gocql.NewCluster("127.0.0.1")
-	// uncomment the following two lines if you want to use Cassandra 1.2
-	// cluster.ProtoVersion = 1
-	// cluster.CQLVersion = "3.0.0"
-	session, _ = cluster.CreateSession()
-}
-
-type Page struct {
-	Title       string
-	RevId       uuid.UUID
-	Body        string
-	Views       int64
-	Protected   bool
-	Modified    time.Time
-	Tags        []string
-	Attachments map[string]Attachment
-}
-
-type Attachment []byte
-
-func initSchema() error {
-	if err := session.Query("DROP KEYSPACE gocql_test").Exec(); err != nil {
-		log.Println("drop keyspace", err)
-	}
-
-	if err := session.Query(`CREATE KEYSPACE gocql_test
-		WITH replication = {
-			'class' : 'SimpleStrategy',
-			'replication_factor' : 1
-		}`).Exec(); err != nil {
-		return err
-	}
-	log.Println("Testing that the connections do not reconnect in an infinite loop.")
-	session.Close()
-	time.Sleep(15 * time.Second)
-	log.Println("If there were error messages that an address cannot be assigned then the test failed.")
-	cluster.Keyspace = "gocql_test"
-	session, _ = cluster.CreateSession()
-
-	if err := session.Query(`CREATE TABLE page (
-			title       varchar,
-			revid       timeuuid,
-			body        varchar,
-			views       bigint,
-			protected   boolean,
-			modified    timestamp,
-			tags        set<varchar>,
-			attachments map<varchar, text>,
-			PRIMARY KEY (title, revid)
-		)`).Exec(); err != nil {
-		return err
-	}
-
-	if err := session.Query(`CREATE TABLE page_stats (
-			title varchar,
-			views counter,
-			PRIMARY KEY (title)
-		)`).Exec(); err != nil {
-		return err
-	}
-
-	if err := session.Query(`CREATE TABLE cas_table (
-            title   varchar,
-            revid   timeuuid,
-            PRIMARY KEY (title, revid)
-        )`).Exec(); err != nil {
-		return err
-	}
-
-	return nil
-}
-
-var pageTestData = []*Page{
-	&Page{
-		Title:    "Frontpage",
-		RevId:    uuid.TimeUUID(),
-		Body:     "Welcome to this wiki page!",
-		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
-		Tags:     []string{"start", "important", "test"},
-		Attachments: map[string]Attachment{
-			"logo":    Attachment("\x00company logo\x00"),
-			"favicon": Attachment("favicon.ico"),
-		},
-	},
-	&Page{
-		Title:    "Foobar",
-		RevId:    uuid.TimeUUID(),
-		Body:     "foo::Foo f = new foo::Foo(foo::Foo::INIT);",
-		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
-	},
-}
-
-func insertTestData() error {
-	for _, page := range pageTestData {
-		if err := session.Query(`INSERT INTO page
-			(title, revid, body, views, protected, modified, tags, attachments)
-			VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
-			page.Title, page.RevId, page.Body, page.Views, page.Protected,
-			page.Modified, page.Tags, page.Attachments).Exec(); err != nil {
-			return err
-		}
-	}
-	return nil
-}
-
-func insertBatch() error {
-	batch := gocql.NewBatch(gocql.LoggedBatch)
-	for _, page := range pageTestData {
-		batch.Query(`INSERT INTO page
-			(title, revid, body, views, protected, modified, tags, attachments)
-			VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
-			page.Title, page.RevId, page.Body, page.Views, page.Protected,
-			page.Modified, page.Tags, page.Attachments)
-	}
-	if err := session.ExecuteBatch(batch); err != nil {
-		return err
-	}
-	return nil
-}
-
-func insertCAS() error {
-	title := "baz"
-	revid := uuid.TimeUUID()
-
-	var titleCAS string
-	var revidCAS uuid.UUID
-
-	applied, err := session.Query(
-		`INSERT INTO cas_table (title, revid)
-        VALUES (?,?) IF NOT EXISTS`,
-		title, revid).ScanCAS(&titleCAS, &revidCAS)
-
-	if err != nil {
-		return err
-	}
-
-	if !applied {
-		return fmt.Errorf("Should have applied update for new random title %s", title)
-	}
-
-	applied, err = session.Query(
-		`INSERT INTO cas_table (title, revid)
-        VALUES (?,?) IF NOT EXISTS`,
-		title, revid).ScanCAS(&titleCAS, &revidCAS)
-
-	if err != nil {
-		return err
-	}
-
-	if applied {
-		return fmt.Errorf("Should NOT have applied update for existing random title %s", title)
-	}
-
-	if title != titleCAS || revid != revidCAS {
-		return fmt.Errorf("Expected %s/%v but got %s/%v", title, revid, titleCAS, revidCAS)
-	}
-
-	return nil
-}
-
-func getPage(title string, revid uuid.UUID) (*Page, error) {
-	p := new(Page)
-	err := session.Query(`SELECT title, revid, body, views, protected, modified,
-			tags, attachments
-			FROM page WHERE title = ? AND revid = ? LIMIT 1`, title, revid).Scan(
-		&p.Title, &p.RevId, &p.Body, &p.Views, &p.Protected, &p.Modified,
-		&p.Tags, &p.Attachments)
-	return p, err
-}
-
-//This test checks to make sure a valid error and a nil reference to
-//a session are returned when an empty array of hosts are provided
-//to the cluster configuration
-func TestEmptyHosts() error {
-	empty := make([]string, 0)
-	cfg := gocql.NewCluster(empty...)
-	_, err := cfg.CreateSession()
-	return err
-}
-
-func main() {
-	if err := TestEmptyHosts(); err == nil {
-		log.Fatal("Failed to error when empty host list is provided.")
-	}
-	if err := initSchema(); err != nil {
-		log.Fatal("initSchema: ", err)
-	}
-
-	if err := insertTestData(); err != nil {
-		log.Fatal("insertTestData: ", err)
-	}
-
-	var count int
-	if err := session.Query("SELECT COUNT(*) FROM page").Scan(&count); err != nil {
-		log.Fatal("getCount: ", err)
-	}
-	if count != len(pageTestData) {
-		log.Printf("count: expected %d, got %d", len(pageTestData), count)
-	}
-
-	for _, original := range pageTestData {
-		page, err := getPage(original.Title, original.RevId)
-		if err != nil {
-			log.Print("getPage: ", err)
-			continue
-		}
-		sort.Sort(sort.StringSlice(page.Tags))
-		sort.Sort(sort.StringSlice(original.Tags))
-		if !reflect.DeepEqual(page, original) {
-			log.Printf("page: expected %#v, got %#v\n", original, page)
-		}
-	}
-
-	// Query Tracing
-	trace := gocql.NewTraceWriter(session, os.Stdout)
-	if err := session.Query("SELECT COUNT(*) FROM page").Trace(trace).Scan(&count); err != nil {
-		log.Fatal("trace: ", err)
-	}
-
-	if err := session.Query("CREATE TABLE large (id int primary key)").Exec(); err != nil {
-		log.Fatal("create table: ", err)
-	}
-	for i := 0; i < 100; i++ {
-		if err := session.Query("INSERT INTO large (id) VALUES (?)", i).Exec(); err != nil {
-			log.Fatal("insert: ", err)
-		}
-	}
-
-	if cluster.ProtoVersion >= 2 {
-		// Result Paging
-		iter := session.Query("SELECT id FROM large").PageSize(10).Iter()
-		var id int
-		count = 0
-		for iter.Scan(&id) {
-			count++
-		}
-		if err := iter.Close(); err != nil {
-			log.Fatal("large iter:", err)
-		}
-		if count != 100 {
-			log.Fatalf("expected %d, got %d", 100, count)
-		}
-
-		// Atomic Batches
-		for _, original := range pageTestData {
-			if err := session.Query("DELETE FROM page WHERE title = ? AND revid = ?",
-				original.Title, original.RevId).Exec(); err != nil {
-				log.Println("delete:", err)
-			}
-		}
-		if err := session.Query("SELECT COUNT(*) FROM page").Scan(&count); err != nil {
-			log.Fatal("getCount: ", err)
-		}
-		if count != 0 {
-			log.Printf("count: expected %d, got %d", len(pageTestData), count)
-		}
-
-		if err := insertBatch(); err != nil {
-			log.Fatal("insertBatch: ", err)
-		}
-
-		// CAS
-		if err := insertCAS(); err != nil {
-			log.Fatal("insertCAS: ", err)
-		}
-	}
-}

+ 9 - 1
marshal.go

@@ -10,6 +10,8 @@ import (
 	"math"
 	"reflect"
 	"time"
+
+	"tux21b.org/v1/gocql/uuid"
 )
 
 // Marshaler is the interface implemented by objects that can marshal
@@ -49,7 +51,7 @@ func Marshal(info *TypeInfo, value interface{}) ([]byte, error) {
 		return marshalList(info, value)
 	case TypeMap:
 		return marshalMap(info, value)
-	case TypeUUID:
+	case TypeUUID, TypeTimeUUID:
 		return marshalUUID(info, value)
 	}
 	// TODO(tux21b): add the remaining types
@@ -904,6 +906,9 @@ func marshalUUID(info *TypeInfo, value interface{}) ([]byte, error) {
 	if val, ok := value.([]byte); ok && len(val) == 16 {
 		return val, nil
 	}
+	if val, ok := value.(uuid.UUID); ok {
+		return val.Bytes(), nil
+	}
 	return nil, marshalErrorf("can not marshal %T into %s", value, info)
 }
 
@@ -911,6 +916,9 @@ func unmarshalTimeUUID(info *TypeInfo, data []byte, value interface{}) error {
 	switch v := value.(type) {
 	case Unmarshaler:
 		return v.UnmarshalCQL(info, data)
+	case *uuid.UUID:
+		*v = uuid.FromBytes(data)
+		return nil
 	case *time.Time:
 		if len(data) != 16 {
 			return unmarshalErrorf("invalid timeuuid")

+ 10 - 31
uuid/uuid.go

@@ -14,8 +14,6 @@ import (
 	"io"
 	"net"
 	"time"
-
-	"tux21b.org/v1/gocql"
 )
 
 type UUID [16]byte
@@ -174,44 +172,25 @@ func (u UUID) Node() []byte {
 
 // Timestamp extracts the timestamp information from a time based UUID
 // (version 1).
-func (u UUID) Timestamp() uint64 {
+func (u UUID) Timestamp() int64 {
 	if u.Version() != 1 {
 		return 0
 	}
-	return uint64(u[0])<<24 + uint64(u[1])<<16 + uint64(u[2])<<8 +
-		uint64(u[3]) + uint64(u[4])<<40 + uint64(u[5])<<32 +
-		uint64(u[7])<<48 + uint64(u[6]&0x0F)<<56
+	return int64(uint64(u[0])<<24|uint64(u[1])<<16|
+		uint64(u[2])<<8|uint64(u[3])) +
+		int64(uint64(u[4])<<40|uint64(u[5])<<32) +
+		int64(uint64(u[6]&0x0F)<<56|uint64(u[7])<<48)
 }
 
 // Time is like Timestamp, except that it returns a time.Time.
 func (u UUID) Time() time.Time {
-	t := u.Timestamp()
-	if t == 0 {
+	if u.Version() != 1 {
 		return time.Time{}
 	}
-	sec := t / 10000000
+	t := u.Timestamp() - timeEpoch
+	sec := t / 1e7
 	nsec := t - sec
-	return time.Unix(int64(sec)+timeBase, int64(nsec))
-}
-
-func (u UUID) MarshalCQL(info *gocql.TypeInfo) ([]byte, error) {
-	switch info.Type {
-	case gocql.TypeUUID, gocql.TypeTimeUUID:
-		return u[:], nil
-	}
-	return gocql.Marshal(info, u[:])
+	return time.Unix(int64(sec), int64(nsec)).UTC()
 }
 
-func (u *UUID) UnmarshalCQL(info *gocql.TypeInfo, data []byte) error {
-	switch info.Type {
-	case gocql.TypeUUID, gocql.TypeTimeUUID:
-		*u = FromBytes(data)
-		return nil
-	}
-	var val []byte
-	if err := gocql.Unmarshal(info, data, &val); err != nil {
-		return err
-	}
-	*u = FromBytes(val)
-	return nil
-}
+var timeEpoch int64 = 0x01B21DD213814000

+ 1 - 1
uuid/uuid_test.go

@@ -76,7 +76,7 @@ func TestRandomUUID(t *testing.T) {
 
 func TestTimeUUID(t *testing.T) {
 	var node []byte
-	timestamp := uint64(0)
+	timestamp := int64(0)
 	for i := 0; i < 20; i++ {
 		uuid := TimeUUID()