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

Side by Side 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, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "github.com/luci/gkvlite"
9 )
10
11 // memStore is a gkvlite.Store which will panic for anything which might
12 // otherwise return an error.
13 //
14 // This is reasonable for in-memory Store objects, since the only errors that
15 // should occur happen with file IO on the underlying file (which of course
16 // doesn't exist).
17 type memStore gkvlite.Store
18
19 func newMemStore() *memStore {
20 ret, err := gkvlite.NewStore(nil)
21 if err != nil {
22 panic(err)
23 }
24 return (*memStore)(ret)
25 }
26
27 func (ms *memStore) Snapshot() *memStore {
28 return (*memStore)((*gkvlite.Store)(ms).Snapshot())
29 }
30
31 func (ms *memStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *memCollection {
32 return (*memCollection)((*gkvlite.Store)(ms).MakePrivateCollection(cmp))
33 }
34
35 func (ms *memStore) GetCollection(name string) *memCollection {
36 return (*memCollection)((*gkvlite.Store)(ms).GetCollection(name))
37 }
38
39 func (ms *memStore) SetCollection(name string, cmp gkvlite.KeyCompare) *memColle ction {
40 return (*memCollection)((*gkvlite.Store)(ms).SetCollection(name, cmp))
41 }
42
43 // memCollection is a gkvlite.Collection which will panic for anything which
44 // might otherwise return an error.
45 //
46 // This is reasonable for in-memory Store objects, since the only errors that
47 // should occur happen with file IO on the underlying file (which of course
48 // doesn't exist.
49 type memCollection gkvlite.Collection
50
51 func (mc *memCollection) Get(k []byte) []byte {
52 ret, err := (*gkvlite.Collection)(mc).Get(k)
53 if err != nil {
54 panic(err)
55 }
56 return ret
57 }
58
59 func (mc *memCollection) Set(k, v []byte) {
60 if err := (*gkvlite.Collection)(mc).Set(k, v); err != nil {
61 panic(err)
62 }
63 }
64
65 func (mc *memCollection) Delete(k []byte) bool {
66 ret, err := (*gkvlite.Collection)(mc).Delete(k)
67 if err != nil {
68 panic(err)
69 }
70 return ret
71 }
72
73 func (mc *memCollection) VisitItemsAscend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
74 if err := (*gkvlite.Collection)(mc).VisitItemsAscend(target, withValue, visitor); err != nil {
75 panic(err)
76 }
77 }
78
79 func (mc *memCollection) VisitItemsDescend(target []byte, withValue bool, visito r gkvlite.ItemVisitor) {
80 if err := (*gkvlite.Collection)(mc).VisitItemsDescend(target, withValue, visitor); err != nil {
81 panic(err)
82 }
83 }
84
85 func (mc *memCollection) GetTotals() (numItems, numBytes uint64) {
86 numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals()
87 if err != nil {
88 panic(err)
89 }
90 return
91 }
OLDNEW
« 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