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

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

Issue 1152383003: Simple memory testing for gae/wrapper (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@better_context_lite
Patch Set: add go-slab dependency 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
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/doc.go ('k') | go/src/infra/gae/libs/wrapper/memory/globalinfo.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go b/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go
new file mode 100644
index 0000000000000000000000000000000000000000..ea8fb200d9abf1b649d20f440b7e7452feed4834
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go
@@ -0,0 +1,91 @@
+// 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"
+)
+
+// memStore 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).
+type memStore gkvlite.Store
+
+func newMemStore() *memStore {
+ ret, err := gkvlite.NewStore(nil)
+ if err != nil {
+ panic(err)
+ }
+ return (*memStore)(ret)
+}
+
+func (ms *memStore) Snapshot() *memStore {
+ return (*memStore)((*gkvlite.Store)(ms).Snapshot())
+}
+
+func (ms *memStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *memCollection {
+ return (*memCollection)((*gkvlite.Store)(ms).MakePrivateCollection(cmp))
+}
+
+func (ms *memStore) GetCollection(name string) *memCollection {
+ return (*memCollection)((*gkvlite.Store)(ms).GetCollection(name))
+}
+
+func (ms *memStore) SetCollection(name string, cmp gkvlite.KeyCompare) *memCollection {
+ return (*memCollection)((*gkvlite.Store)(ms).SetCollection(name, cmp))
+}
+
+// memCollection 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 memCollection gkvlite.Collection
+
+func (mc *memCollection) Get(k []byte) []byte {
+ ret, err := (*gkvlite.Collection)(mc).Get(k)
+ if err != nil {
+ panic(err)
+ }
+ return ret
+}
+
+func (mc *memCollection) Set(k, v []byte) {
+ if err := (*gkvlite.Collection)(mc).Set(k, v); err != nil {
+ panic(err)
+ }
+}
+
+func (mc *memCollection) Delete(k []byte) bool {
+ ret, err := (*gkvlite.Collection)(mc).Delete(k)
+ if err != nil {
+ panic(err)
+ }
+ return ret
+}
+
+func (mc *memCollection) VisitItemsAscend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
+ if err := (*gkvlite.Collection)(mc).VisitItemsAscend(target, withValue, visitor); err != nil {
+ panic(err)
+ }
+}
+
+func (mc *memCollection) VisitItemsDescend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
+ if err := (*gkvlite.Collection)(mc).VisitItemsDescend(target, withValue, visitor); err != nil {
+ panic(err)
+ }
+}
+
+func (mc *memCollection) GetTotals() (numItems, numBytes uint64) {
+ numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals()
+ if err != nil {
+ panic(err)
+ }
+ return
+}
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/doc.go ('k') | go/src/infra/gae/libs/wrapper/memory/globalinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698