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

Unified Diff: go/src/infra/gae/libs/wrapper/memory/gkvliteUtils.go

Issue 1152383003: Simple memory testing for gae/wrapper (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@better_context_lite
Patch Set: use funnybase directly Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: go/src/infra/gae/libs/wrapper/memory/gkvliteUtils.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/gkvliteUtils.go b/go/src/infra/gae/libs/wrapper/memory/gkvliteUtils.go
new file mode 100644
index 0000000000000000000000000000000000000000..338b5f0e28fed8e17be038155b63968860c9fe52
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/memory/gkvliteUtils.go
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium 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 memory
+
+import (
+ "github.com/luci/gkvlite"
+)
+
+// boomStore is a gkvlite.Store which will panic for anything which might
+// otherwise return an error.
+//
+// This is reasonable for in-memory Store objects, since the only errors that
+// should occur happen with file IO on the underlying file (which of course
+// doesn't exist.
Vadim Sh. 2015/05/24 19:43:26 typo: forgot ")" :)
iannucci 2015/05/24 20:33:54 done
+type boomStore gkvlite.Store
+
+func newBoomStore() *boomStore {
+ ret, err := gkvlite.NewStore(nil)
+ if err != nil {
+ panic(err)
+ }
+ return (*boomStore)(ret)
+}
+
+func (bs *boomStore) Snapshot() *boomStore {
+ return (*boomStore)((*gkvlite.Store)(bs).Snapshot())
+}
+
+func (bs *boomStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *boomCollection {
+ return (*boomCollection)((*gkvlite.Store)(bs).MakePrivateCollection(cmp))
+}
+
+func (bs *boomStore) GetCollection(name string) *boomCollection {
+ return (*boomCollection)((*gkvlite.Store)(bs).GetCollection(name))
+}
+
+func (bs *boomStore) SetCollection(name string, cmp gkvlite.KeyCompare) *boomCollection {
+ return (*boomCollection)((*gkvlite.Store)(bs).SetCollection(name, cmp))
+}
+
+// boomCollection is a gkvlite.Collection which will panic for anything which
+// might otherwise return an error.
+//
+// This is reasonable for in-memory Store objects, since the only errors that
+// should occur happen with file IO on the underlying file (which of course
+// doesn't exist.
+type boomCollection gkvlite.Collection
+
+func (bc *boomCollection) Get(k []byte) []byte {
+ ret, err := (*gkvlite.Collection)(bc).Get(k)
+ if err != nil {
+ panic(err)
+ }
+ return ret
+}
+
+func (bc *boomCollection) Set(k, v []byte) {
+ err := (*gkvlite.Collection)(bc).Set(k, v)
+ if err != nil {
+ panic(err)
+ }
+}
+
+func (bc *boomCollection) Delete(k []byte) bool {
+ ret, err := (*gkvlite.Collection)(bc).Delete(k)
+ if err != nil {
+ panic(err)
+ }
+ return ret
+}
+
+func (bc *boomCollection) VisitItemsAscend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
+ err := (*gkvlite.Collection)(bc).VisitItemsAscend(target, withValue, visitor)
+ if err != nil {
+ panic(err)
+ }
+}
+
+func (bc *boomCollection) VisitItemsDescend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
+ err := (*gkvlite.Collection)(bc).VisitItemsDescend(target, withValue, visitor)
+ if err != nil {
+ panic(err)
+ }
+}
+
+func (bc *boomCollection) GetTotals() (numItems, numBytes uint64) {
+ numItems, numBytes, err := (*gkvlite.Collection)(bc).GetTotals()
+ if err != nil {
+ panic(err)
+ }
+ return
+}

Powered by Google App Engine
This is Rietveld 408576698