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

Unified Diff: impl/memory/datastore.go

Issue 1285703002: Add testable interface for datastore. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fixes after Raw change Created 5 years, 4 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 | « impl/dummy/dummy.go ('k') | impl/memory/datastore_data.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore.go
diff --git a/impl/memory/datastore.go b/impl/memory/datastore.go
index 3c5a14c716d174608a2abf72d55570f08809daa9..53e72be7ec9a424817465115a894ea1cfd845554 100644
--- a/impl/memory/datastore.go
+++ b/impl/memory/datastore.go
@@ -6,6 +6,7 @@ package memory
import (
"errors"
+ "fmt"
"golang.org/x/net/context"
@@ -68,11 +69,34 @@ func (d *dsImpl) NewQuery(kind string) ds.Query {
func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
return nil
- /*
- rq := q.(*queryImpl)
- rq = rq.normalize().checkCorrectness(d.ns, false)
- return &queryIterImpl{rq}
- */
+}
+
+func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) {
+ for _, i := range idxs {
+ if !i.Compound() {
+ panic(fmt.Errorf("Attempted to add non-compound index: %s", i))
+ }
+ }
+
+ d.data.Lock()
+ defer d.data.Unlock()
+ addIndex(d.data.store, d.ns, idxs)
+}
+
+func (d *dsImpl) TakeIndexSnapshot() ds.TestingSnapshot {
+ return d.data.takeSnapshot()
+}
+
+func (d *dsImpl) SetIndexSnapshot(snap ds.TestingSnapshot) {
+ d.data.setSnapshot(snap.(*memStore))
+}
+
+func (d *dsImpl) CatchupIndexes() {
+ d.data.catchupIndexes()
+}
+
+func (d *dsImpl) Testable() ds.Testable {
+ return d
}
////////////////////////////////// txnDsImpl ///////////////////////////////////
@@ -114,8 +138,13 @@ func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error {
func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
rq := q.(*queryImpl)
if rq.ancestor == nil {
- return errors.New("memory: queries in transactions only support ancestor queries")
+ return errors.New("gae/impl/memory: queries in transactions only support ancestor queries")
}
+ if rq.eventualConsistency {
+ rq = rq.clone()
+ rq.eventualConsistency = false
+ }
+ // TODO(riannucci): use head instead of snap for indexes
panic("NOT IMPLEMENTED")
}
@@ -126,3 +155,7 @@ func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
func (d *txnDsImpl) NewQuery(kind string) ds.Query {
return &queryImpl{ns: d.ns, kind: kind}
}
+
+func (*txnDsImpl) Testable() ds.Testable {
+ return nil
+}
« no previous file with comments | « impl/dummy/dummy.go ('k') | impl/memory/datastore_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698