Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: logdog/common/storage/bigtable/storage_test.go

Issue 2435883002: LogDog: Fix archival Get/Tail implementations. (Closed)
Patch Set: LogDog: Fix archival Get/Tail implementations. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be 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 "strconv" 10 "strconv"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 err := t.collection().VisitItemsAscend([]byte(nil), true, func(i *gkvlit e.Item) bool { 142 err := t.collection().VisitItemsAscend([]byte(nil), true, func(i *gkvlit e.Item) bool {
143 result[string(i.Key)] = i.Val 143 result[string(i.Key)] = i.Val
144 return true 144 return true
145 }) 145 })
146 if err != nil { 146 if err != nil {
147 panic(err) 147 panic(err)
148 } 148 }
149 return result 149 return result
150 } 150 }
151 151
152 func mustGetIndex(e *storage.Entry) types.MessageIndex {
153 idx, err := e.GetStreamIndex()
154 if err != nil {
155 panic(err)
156 }
157 return idx
158 }
159
152 func TestStorage(t *testing.T) { 160 func TestStorage(t *testing.T) {
153 t.Parallel() 161 t.Parallel()
154 162
155 Convey(`A BigTable storage instance bound to a testing BigTable instance `, t, func() { 163 Convey(`A BigTable storage instance bound to a testing BigTable instance `, t, func() {
156 bt := btTableTest{} 164 bt := btTableTest{}
157 defer bt.close() 165 defer bt.close()
158 166
159 s := newBTStorage(context.Background(), Options{ 167 s := newBTStorage(context.Background(), Options{
160 Project: "test-project", 168 Project: "test-project",
161 Instance: "test-instance", 169 Instance: "test-instance",
162 LogTable: "test-log-table", 170 LogTable: "test-log-table",
163 }, nil, nil) 171 }, nil, nil)
164 172
165 s.raw = &bt 173 s.raw = &bt
166 defer s.Close() 174 defer s.Close()
167 175
168 project := config.ProjectName("test-project") 176 project := config.ProjectName("test-project")
169 get := func(path string, index int, limit int, keysOnly bool) ([ ]string, error) { 177 get := func(path string, index int, limit int, keysOnly bool) ([ ]string, error) {
170 req := storage.GetRequest{ 178 req := storage.GetRequest{
171 Project: project, 179 Project: project,
172 Path: types.StreamPath(path), 180 Path: types.StreamPath(path),
173 Index: types.MessageIndex(index), 181 Index: types.MessageIndex(index),
174 Limit: limit, 182 Limit: limit,
175 KeysOnly: keysOnly, 183 KeysOnly: keysOnly,
176 } 184 }
177 got := []string{} 185 got := []string{}
178 » » » err := s.Get(req, func(idx types.MessageIndex, d []byte) bool { 186 » » » err := s.Get(req, func(e *storage.Entry) bool {
179 if keysOnly { 187 if keysOnly {
180 » » » » » got = append(got, strconv.Itoa(int(idx)) ) 188 » » » » » got = append(got, strconv.Itoa(int(mustG etIndex(e))))
181 } else { 189 } else {
182 » » » » » got = append(got, string(d)) 190 » » » » » got = append(got, string(e.D))
183 } 191 }
184 return true 192 return true
185 }) 193 })
186 return got, err 194 return got, err
187 } 195 }
188 196
189 put := func(path string, index int, d ...string) error { 197 put := func(path string, index int, d ...string) error {
190 data := make([][]byte, len(d)) 198 data := make([][]byte, len(d))
191 for i, v := range d { 199 for i, v := range d {
192 data[i] = []byte(v) 200 data[i] = []byte(v)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 328
321 Convey(`Will fetch B{12, 13} when index=11.`, fu nc() { 329 Convey(`Will fetch B{12, 13} when index=11.`, fu nc() {
322 got, err := get("B", 11, 0, true) 330 got, err := get("B", 11, 0, true)
323 So(err, ShouldBeNil) 331 So(err, ShouldBeNil)
324 So(got, ShouldResemble, []string{"12", " 13"}) 332 So(got, ShouldResemble, []string{"12", " 13"})
325 }) 333 })
326 }) 334 })
327 335
328 Convey(`Testing "Tail"...`, func() { 336 Convey(`Testing "Tail"...`, func() {
329 tail := func(path string) (string, error) { 337 tail := func(path string) (string, error) {
330 » » » » » got, _, err := s.Tail(project, types.Str eamPath(path)) 338 » » » » » e, err := s.Tail(project, types.StreamPa th(path))
331 » » » » » return string(got), err 339 » » » » » if err != nil {
340 » » » » » » return "", err
341 » » » » » }
342 » » » » » return string(e.D), nil
332 } 343 }
333 344
334 Convey(`A tail request for "A" returns A{4}.`, f unc() { 345 Convey(`A tail request for "A" returns A{4}.`, f unc() {
335 got, err := tail("A") 346 got, err := tail("A")
336 So(err, ShouldBeNil) 347 So(err, ShouldBeNil)
337 So(got, ShouldEqual, "4") 348 So(got, ShouldEqual, "4")
338 }) 349 })
339 350
340 Convey(`A tail request for "B" returns B{13}.`, func() { 351 Convey(`A tail request for "B" returns B{13}.`, func() {
341 got, err := tail("B") 352 got, err := tail("B")
342 So(err, ShouldBeNil) 353 So(err, ShouldBeNil)
343 So(got, ShouldEqual, "13") 354 So(got, ShouldEqual, "13")
344 }) 355 })
345 356
346 Convey(`A tail request for "INVALID" errors NOT FOUND.`, func() { 357 Convey(`A tail request for "INVALID" errors NOT FOUND.`, func() {
347 _, err := tail("INVALID") 358 _, err := tail("INVALID")
348 So(err, ShouldEqual, storage.ErrDoesNotE xist) 359 So(err, ShouldEqual, storage.ErrDoesNotE xist)
349 }) 360 })
350 }) 361 })
351 }) 362 })
352 }) 363 })
353 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698