| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package bigtable | 5 package bigtable |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "testing" | 10 "testing" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/luci/gkvlite" | 13 "github.com/luci/gkvlite" |
| 14 "github.com/luci/luci-go/common/config" |
| 14 "github.com/luci/luci-go/common/logdog/types" | 15 "github.com/luci/luci-go/common/logdog/types" |
| 15 "github.com/luci/luci-go/common/recordio" | 16 "github.com/luci/luci-go/common/recordio" |
| 16 "github.com/luci/luci-go/server/logdog/storage" | 17 "github.com/luci/luci-go/server/logdog/storage" |
| 17 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 18 | 19 |
| 19 . "github.com/luci/luci-go/common/testing/assertions" | 20 . "github.com/luci/luci-go/common/testing/assertions" |
| 20 . "github.com/smartystreets/goconvey/convey" | 21 . "github.com/smartystreets/goconvey/convey" |
| 21 ) | 22 ) |
| 22 | 23 |
| 23 // btTableTest is an in-memory implementation of btTable interface for testing. | 24 // btTableTest is an in-memory implementation of btTable interface for testing. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 s := newBTStorage(context.Background(), Options{ | 169 s := newBTStorage(context.Background(), Options{ |
| 169 Project: "test-project", | 170 Project: "test-project", |
| 170 Zone: "test-zone", | 171 Zone: "test-zone", |
| 171 Cluster: "test-cluster", | 172 Cluster: "test-cluster", |
| 172 LogTable: "test-log-table", | 173 LogTable: "test-log-table", |
| 173 }, nil, nil) | 174 }, nil, nil) |
| 174 | 175 |
| 175 s.raw = &bt | 176 s.raw = &bt |
| 176 defer s.Close() | 177 defer s.Close() |
| 177 | 178 |
| 179 project := config.ProjectName("test-project") |
| 178 get := func(path string, index int, limit int) ([]string, error)
{ | 180 get := func(path string, index int, limit int) ([]string, error)
{ |
| 179 req := storage.GetRequest{ | 181 req := storage.GetRequest{ |
| 180 » » » » Path: types.StreamPath(path), | 182 » » » » Project: project, |
| 181 » » » » Index: types.MessageIndex(index), | 183 » » » » Path: types.StreamPath(path), |
| 182 » » » » Limit: limit, | 184 » » » » Index: types.MessageIndex(index), |
| 185 » » » » Limit: limit, |
| 183 } | 186 } |
| 184 got := []string{} | 187 got := []string{} |
| 185 err := s.Get(req, func(idx types.MessageIndex, d []byte)
bool { | 188 err := s.Get(req, func(idx types.MessageIndex, d []byte)
bool { |
| 186 got = append(got, string(d)) | 189 got = append(got, string(d)) |
| 187 return true | 190 return true |
| 188 }) | 191 }) |
| 189 return got, err | 192 return got, err |
| 190 } | 193 } |
| 191 | 194 |
| 192 put := func(path string, index int, d ...string) error { | 195 put := func(path string, index int, d ...string) error { |
| 193 data := make([][]byte, len(d)) | 196 data := make([][]byte, len(d)) |
| 194 for i, v := range d { | 197 for i, v := range d { |
| 195 data[i] = []byte(v) | 198 data[i] = []byte(v) |
| 196 } | 199 } |
| 197 | 200 |
| 198 return s.Put(storage.PutRequest{ | 201 return s.Put(storage.PutRequest{ |
| 199 » » » » Path: types.StreamPath(path), | 202 » » » » Project: project, |
| 200 » » » » Index: types.MessageIndex(index), | 203 » » » » Path: types.StreamPath(path), |
| 201 » » » » Values: data, | 204 » » » » Index: types.MessageIndex(index), |
| 205 » » » » Values: data, |
| 202 }) | 206 }) |
| 203 } | 207 } |
| 204 | 208 |
| 205 » » ekey := func(p string, v, c int64) string { | 209 » » ekey := func(path string, v, c int64) string { |
| 206 » » » return newRowKey(p, v, c).encode() | 210 » » » return newRowKey(string(project), path, v, c).encode() |
| 207 } | 211 } |
| 208 records := func(s ...string) []byte { | 212 records := func(s ...string) []byte { |
| 209 buf := bytes.Buffer{} | 213 buf := bytes.Buffer{} |
| 210 w := recordio.NewWriter(&buf) | 214 w := recordio.NewWriter(&buf) |
| 211 | 215 |
| 212 for _, v := range s { | 216 for _, v := range s { |
| 213 if _, err := w.Write([]byte(v)); err != nil { | 217 if _, err := w.Write([]byte(v)); err != nil { |
| 214 panic(err) | 218 panic(err) |
| 215 } | 219 } |
| 216 if err := w.Flush(); err != nil { | 220 if err := w.Flush(); err != nil { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 294 |
| 291 Convey(`Will fetch {} for INVALID.`, func() { | 295 Convey(`Will fetch {} for INVALID.`, func() { |
| 292 got, err := get("INVALID", 0, 0) | 296 got, err := get("INVALID", 0, 0) |
| 293 So(err, ShouldBeNil) | 297 So(err, ShouldBeNil) |
| 294 So(got, ShouldResemble, []string{}) | 298 So(got, ShouldResemble, []string{}) |
| 295 }) | 299 }) |
| 296 }) | 300 }) |
| 297 | 301 |
| 298 Convey(`Testing "Tail"...`, func() { | 302 Convey(`Testing "Tail"...`, func() { |
| 299 tail := func(path string) (string, error) { | 303 tail := func(path string) (string, error) { |
| 300 » » » » » got, _, err := s.Tail(types.StreamPath(p
ath)) | 304 » » » » » got, _, err := s.Tail(project, types.Str
eamPath(path)) |
| 301 return string(got), err | 305 return string(got), err |
| 302 } | 306 } |
| 303 | 307 |
| 304 Convey(`A tail request for "A" returns A{4}.`, f
unc() { | 308 Convey(`A tail request for "A" returns A{4}.`, f
unc() { |
| 305 got, err := tail("A") | 309 got, err := tail("A") |
| 306 So(err, ShouldBeNil) | 310 So(err, ShouldBeNil) |
| 307 So(got, ShouldEqual, "4") | 311 So(got, ShouldEqual, "4") |
| 308 }) | 312 }) |
| 309 | 313 |
| 310 Convey(`A tail request for "B" returns B{13}.`,
func() { | 314 Convey(`A tail request for "B" returns B{13}.`,
func() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 322 }) | 326 }) |
| 323 } | 327 } |
| 324 | 328 |
| 325 func TestStorage(t *testing.T) { | 329 func TestStorage(t *testing.T) { |
| 326 testStorageImpl(t, false) | 330 testStorageImpl(t, false) |
| 327 } | 331 } |
| 328 | 332 |
| 329 func TestStorageLegacy(t *testing.T) { | 333 func TestStorageLegacy(t *testing.T) { |
| 330 testStorageImpl(t, true) | 334 testStorageImpl(t, true) |
| 331 } | 335 } |
| OLD | NEW |