OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package gae | 5 package wrapper |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "runtime" | 9 "runtime" |
10 "strings" | 10 "strings" |
11 "time" | 11 "time" |
12 | 12 |
13 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 14 |
| 15 "appengine" |
| 16 "appengine/datastore" |
| 17 "appengine/memcache" |
| 18 "appengine/taskqueue" |
| 19 |
| 20 "github.com/mjibson/goon" |
14 ) | 21 ) |
15 | 22 |
16 const niFmtStr = "gae: method %s.%s is not implemented" | 23 const niFmtStr = "wrapper: method %s.%s is not implemented" |
17 | 24 |
18 func ni() error { | 25 func ni() error { |
19 iface := "UNKNOWN" | 26 iface := "UNKNOWN" |
20 funcName := "UNKNOWN" | 27 funcName := "UNKNOWN" |
21 | 28 |
22 if ptr, _, _, ok := runtime.Caller(1); ok { | 29 if ptr, _, _, ok := runtime.Caller(1); ok { |
23 f := runtime.FuncForPC(ptr) | 30 f := runtime.FuncForPC(ptr) |
24 n := f.Name() | 31 n := f.Name() |
25 if n != "" { | 32 if n != "" { |
26 parts := strings.Split(n, ".") | 33 parts := strings.Split(n, ".") |
27 if len(parts) == 3 { | 34 if len(parts) == 3 { |
28 » » » » switch parts[1][len("dummy"):] { | 35 » » » » switch parts[1][len(parts[1])-2:] { |
29 » » » » case "RDS": | 36 » » » » case "DS": |
30 » » » » » iface = "RawDatastore" | 37 » » » » » iface = "Datastore" |
31 case "MC": | 38 case "MC": |
32 iface = "Memcache" | 39 iface = "Memcache" |
33 case "TQ": | 40 case "TQ": |
34 iface = "TaskQueue" | 41 iface = "TaskQueue" |
35 case "GI": | 42 case "GI": |
36 iface = "GlobalInformation" | 43 iface = "GlobalInformation" |
37 case "QY": | 44 case "QY": |
38 iface = "Query" | 45 iface = "Query" |
39 } | 46 } |
40 funcName = parts[2] | 47 funcName = parts[2] |
41 } | 48 } |
42 } | 49 } |
43 } | 50 } |
44 | 51 |
45 return fmt.Errorf(niFmtStr, iface, funcName) | 52 return fmt.Errorf(niFmtStr, iface, funcName) |
46 } | 53 } |
47 | 54 |
48 /////////////////////////////////// dummyRDS ///////////////////////////////////
/ | 55 /////////////////////////////////// dummyDS //////////////////////////////////// |
49 | 56 |
50 type dummyRDS struct{} | 57 type dummyDS struct{} |
51 | 58 |
52 func (dummyRDS) NewKey(string, string, int64, DSKey) DSKey { panic(
ni()) } | 59 func (dummyDS) Kind(interface{}) string { pa
nic(ni()) } |
53 func (dummyRDS) DecodeKey(string) (DSKey, error) { panic(
ni()) } | 60 func (dummyDS) KindNameResolver() goon.KindNameResolver { pa
nic(ni()) } |
54 func (dummyRDS) KeyFromTokens(a, n string, t []DSKeyTok) (DSKey, error) { panic(
ni()) } | 61 func (dummyDS) SetKindNameResolver(goon.KindNameResolver) { pa
nic(ni()) } |
55 func (dummyRDS) Put(DSKey, interface{}) (DSKey, error) { panic(
ni()) } | 62 func (dummyDS) NewKey(string, string, int64, *datastore.Key) *datastore.Key { pa
nic(ni()) } |
56 func (dummyRDS) Get(DSKey, interface{}) error { panic(
ni()) } | 63 func (dummyDS) NewKeyObj(interface{}) *datastore.Key { pa
nic(ni()) } |
57 func (dummyRDS) Delete(DSKey) error { panic(
ni()) } | 64 func (dummyDS) NewKeyObjError(interface{}) (*datastore.Key, error) { pa
nic(ni()) } |
58 func (dummyRDS) PutMulti([]DSKey, interface{}) ([]DSKey, error) { panic(
ni()) } | 65 func (dummyDS) Put(interface{}) (*datastore.Key, error) { pa
nic(ni()) } |
59 func (dummyRDS) GetMulti([]DSKey, interface{}) error { panic(
ni()) } | 66 func (dummyDS) Get(interface{}) error { pa
nic(ni()) } |
60 func (dummyRDS) DeleteMulti([]DSKey) error { panic(
ni()) } | 67 func (dummyDS) Delete(*datastore.Key) error { pa
nic(ni()) } |
61 func (dummyRDS) NewQuery(string) DSQuery { panic(
ni()) } | 68 func (dummyDS) PutMulti(interface{}) ([]*datastore.Key, error) { pa
nic(ni()) } |
62 func (dummyRDS) Run(DSQuery) DSIterator { panic(
ni()) } | 69 func (dummyDS) GetMulti(interface{}) error { pa
nic(ni()) } |
63 func (dummyRDS) GetAll(DSQuery, interface{}) ([]DSKey, error) { panic(
ni()) } | 70 func (dummyDS) DeleteMulti([]*datastore.Key) error { pa
nic(ni()) } |
64 func (dummyRDS) Count(DSQuery) (int, error) { panic(
ni()) } | 71 func (dummyDS) NewQuery(string) DSQuery { pa
nic(ni()) } |
65 func (dummyRDS) RunInTransaction(func(context.Context) error, *DSTransactionOpti
ons) error { | 72 func (dummyDS) Run(DSQuery) DSIterator { pa
nic(ni()) } |
| 73 func (dummyDS) GetAll(DSQuery, interface{}) ([]*datastore.Key, error) { pa
nic(ni()) } |
| 74 func (dummyDS) Count(DSQuery) (int, error) { pa
nic(ni()) } |
| 75 func (dummyDS) RunInTransaction(func(context.Context) error, *datastore.Transact
ionOptions) error { |
66 panic(ni()) | 76 panic(ni()) |
67 } | 77 } |
68 | 78 |
69 var dummyRDSInst = dummyRDS{} | 79 var dummyDSInst = dummyDS{} |
70 | 80 |
71 // DummyRDS returns a dummy RawDatastore implementation suitable for embedding. | 81 // DummyDS returns a dummy Datastore implementation suitable for embedding. |
72 // Every method panics with a message containing the name of the method which | 82 // Every method panics with a message containing the name of the method which |
73 // was unimplemented. | 83 // was unimplemented. |
74 func DummyRDS() RawDatastore { return dummyRDSInst } | 84 func DummyDS() Datastore { return dummyDSInst } |
75 | 85 |
76 /////////////////////////////////// dummyMC //////////////////////////////////// | 86 /////////////////////////////////// dummyMC //////////////////////////////////// |
77 | 87 |
78 type dummyMC struct{} | 88 type dummyMC struct{} |
79 | 89 |
80 func (dummyMC) Add(MCItem) error { panic(ni()) } | 90 func (dummyMC) Add(*memcache.Item) error { panic(ni(
)) } |
81 func (dummyMC) NewItem(key string) MCItem { panic(ni()) } | 91 func (dummyMC) Set(*memcache.Item) error { panic(ni(
)) } |
82 func (dummyMC) Set(MCItem) error { panic(ni()) } | 92 func (dummyMC) Get(string) (*memcache.Item, error) { panic(ni(
)) } |
83 func (dummyMC) Get(string) (MCItem, error) { panic(ni()) } | 93 func (dummyMC) Delete(string) error { panic(ni(
)) } |
84 func (dummyMC) Delete(string) error { panic(ni()) } | 94 func (dummyMC) CompareAndSwap(*memcache.Item) error { panic(ni(
)) } |
85 func (dummyMC) CompareAndSwap(MCItem) error { panic(ni()) } | 95 func (dummyMC) AddMulti([]*memcache.Item) error { panic(ni(
)) } |
86 func (dummyMC) AddMulti([]MCItem) error { panic(ni()) } | 96 func (dummyMC) SetMulti([]*memcache.Item) error { panic(ni(
)) } |
87 func (dummyMC) SetMulti([]MCItem) error { panic(ni()) } | 97 func (dummyMC) GetMulti([]string) (map[string]*memcache.Item, error) { panic(ni(
)) } |
88 func (dummyMC) GetMulti([]string) (map[string]MCItem, error) { panic(ni()) } | 98 func (dummyMC) DeleteMulti([]string) error { panic(ni(
)) } |
89 func (dummyMC) DeleteMulti([]string) error { panic(ni()) } | 99 func (dummyMC) CompareAndSwapMulti([]*memcache.Item) error { panic(ni(
)) } |
90 func (dummyMC) CompareAndSwapMulti([]MCItem) error { panic(ni()) } | 100 func (dummyMC) Increment(string, int64, uint64) (uint64, error) { panic(ni(
)) } |
91 func (dummyMC) Increment(string, int64, uint64) (uint64, error) { panic(ni()) } | 101 func (dummyMC) IncrementExisting(string, int64) (uint64, error) { panic(ni(
)) } |
92 func (dummyMC) IncrementExisting(string, int64) (uint64, error) { panic(ni()) } | 102 func (dummyMC) Flush() error { panic(ni(
)) } |
93 func (dummyMC) Flush() error { panic(ni()) } | 103 func (dummyMC) Stats() (*memcache.Statistics, error) { panic(ni(
)) } |
94 func (dummyMC) Stats() (*MCStatistics, error) { panic(ni()) } | 104 func (dummyMC) InflateCodec(memcache.Codec) MCCodec { panic(ni(
)) } |
95 | 105 |
96 var dummyMCInst = dummyMC{} | 106 var dummyMCInst = dummyMC{} |
97 | 107 |
98 // DummyMC returns a dummy Memcache implementation suitable for embedding. | 108 // DummyMC returns a dummy Memcache implementation suitable for embedding. |
99 // Every method panics with a message containing the name of the method which | 109 // Every method panics with a message containing the name of the method which |
100 // was unimplemented. | 110 // was unimplemented. |
101 func DummyMC() Memcache { return dummyMCInst } | 111 func DummyMC() Memcache { return dummyMCInst } |
102 | 112 |
103 /////////////////////////////////// dummyTQ //////////////////////////////////// | 113 /////////////////////////////////// dummyTQ //////////////////////////////////// |
104 | 114 |
105 type dummyTQ struct{} | 115 type dummyTQ struct{} |
106 | 116 |
107 func (dummyTQ) Add(*TQTask, string) (*TQTask, error) { panic(n
i()) } | 117 func (dummyTQ) Add(*taskqueue.Task, string) (*taskqueue.Task, error) {
panic(ni()) } |
108 func (dummyTQ) Delete(*TQTask, string) error { panic(n
i()) } | 118 func (dummyTQ) Delete(*taskqueue.Task, string) error {
panic(ni()) } |
109 func (dummyTQ) AddMulti([]*TQTask, string) ([]*TQTask, error) { panic(n
i()) } | 119 func (dummyTQ) AddMulti([]*taskqueue.Task, string) ([]*taskqueue.Task, error) {
panic(ni()) } |
110 func (dummyTQ) DeleteMulti([]*TQTask, string) error { panic(n
i()) } | 120 func (dummyTQ) DeleteMulti([]*taskqueue.Task, string) error {
panic(ni()) } |
111 func (dummyTQ) Lease(int, string, int) ([]*TQTask, error) { panic(n
i()) } | 121 func (dummyTQ) Lease(int, string, int) ([]*taskqueue.Task, error) {
panic(ni()) } |
112 func (dummyTQ) LeaseByTag(int, string, int, string) ([]*TQTask, error) { panic(n
i()) } | 122 func (dummyTQ) LeaseByTag(int, string, int, string) ([]*taskqueue.Task, error) {
panic(ni()) } |
113 func (dummyTQ) ModifyLease(*TQTask, string, int) error { panic(n
i()) } | 123 func (dummyTQ) ModifyLease(*taskqueue.Task, string, int) error {
panic(ni()) } |
114 func (dummyTQ) Purge(string) error { panic(n
i()) } | 124 func (dummyTQ) Purge(string) error {
panic(ni()) } |
115 func (dummyTQ) QueueStats([]string) ([]TQStatistics, error) { panic(n
i()) } | 125 func (dummyTQ) QueueStats([]string, int) ([]taskqueue.QueueStatistics, error) {
panic(ni()) } |
116 | 126 |
117 var dummyTQInst = dummyTQ{} | 127 var dummyTQInst = dummyTQ{} |
118 | 128 |
119 // DummyTQ returns a dummy TaskQueue implementation suitable for embedding. | 129 // DummyTQ returns a dummy TaskQueue implementation suitable for embedding. |
120 // Every method panics with a message containing the name of the method which | 130 // Every method panics with a message containing the name of the method which |
121 // was unimplemented. | 131 // was unimplemented. |
122 func DummyTQ() TaskQueue { return dummyTQInst } | 132 func DummyTQ() TaskQueue { return dummyTQInst } |
123 | 133 |
124 /////////////////////////////////// dummyQY //////////////////////////////////// | 134 /////////////////////////////////// dummyQY //////////////////////////////////// |
125 | 135 |
126 type dummyQY struct{} | 136 type dummyQY struct{} |
127 | 137 |
128 func (dummyQY) Ancestor(ancestor DSKey) DSQuery { panic(ni())
} | 138 func (dummyQY) Ancestor(ancestor *datastore.Key) DSQuery { panic(ni())
} |
129 func (dummyQY) Distinct() DSQuery { panic(ni())
} | 139 func (dummyQY) Distinct() DSQuery { panic(ni())
} |
130 func (dummyQY) End(c DSCursor) DSQuery { panic(ni())
} | 140 func (dummyQY) End(c DSCursor) DSQuery { panic(ni())
} |
131 func (dummyQY) EventualConsistency() DSQuery { panic(ni())
} | 141 func (dummyQY) EventualConsistency() DSQuery { panic(ni())
} |
132 func (dummyQY) Filter(filterStr string, value interface{}) DSQuery { panic(ni())
} | 142 func (dummyQY) Filter(filterStr string, value interface{}) DSQuery { panic(ni())
} |
133 func (dummyQY) KeysOnly() DSQuery { panic(ni())
} | 143 func (dummyQY) KeysOnly() DSQuery { panic(ni())
} |
134 func (dummyQY) Limit(limit int) DSQuery { panic(ni())
} | 144 func (dummyQY) Limit(limit int) DSQuery { panic(ni())
} |
135 func (dummyQY) Offset(offset int) DSQuery { panic(ni())
} | 145 func (dummyQY) Offset(offset int) DSQuery { panic(ni())
} |
136 func (dummyQY) Order(fieldName string) DSQuery { panic(ni())
} | 146 func (dummyQY) Order(fieldName string) DSQuery { panic(ni())
} |
137 func (dummyQY) Project(fieldNames ...string) DSQuery { panic(ni())
} | 147 func (dummyQY) Project(fieldNames ...string) DSQuery { panic(ni())
} |
138 func (dummyQY) Start(c DSCursor) DSQuery { panic(ni())
} | 148 func (dummyQY) Start(c DSCursor) DSQuery { panic(ni())
} |
139 | 149 |
140 var dummyQYInst = dummyQY{} | 150 var dummyQYInst = dummyQY{} |
141 | 151 |
142 // DummyQY returns a dummy DSQuery implementation suitable for embedding. | 152 // DummyQY returns a dummy DSQuery implementation suitable for embedding. |
143 // Every method panics with a message containing the name of the method which | 153 // Every method panics with a message containing the name of the method which |
144 // was unimplemented. | 154 // was unimplemented. |
145 func DummyQY() DSQuery { return dummyQYInst } | 155 func DummyQY() DSQuery { return dummyQYInst } |
146 | 156 |
147 /////////////////////////////////// dummyGI //////////////////////////////////// | 157 /////////////////////////////////// dummyGI //////////////////////////////////// |
148 | 158 |
149 type dummyGI struct{} | 159 type dummyGI struct{} |
150 | 160 |
151 func (dummyGI) AccessToken(scopes ...string) (token string, expiry time.Time, er
r error) { panic(ni()) } | 161 func (dummyGI) AccessToken(scopes ...string) (token string, expiry time.Time, er
r error) { panic(ni()) } |
152 func (dummyGI) AppID() string
{ panic(ni()) } | 162 func (dummyGI) AppID() string
{ panic(ni()) } |
153 func (dummyGI) ModuleHostname(module, version, instance string) (string, error)
{ panic(ni()) } | 163 func (dummyGI) ModuleHostname(module, version, instance string) (string, error)
{ panic(ni()) } |
154 func (dummyGI) ModuleName() string
{ panic(ni()) } | 164 func (dummyGI) ModuleName() string
{ panic(ni()) } |
155 func (dummyGI) DefaultVersionHostname() string
{ panic(ni()) } | 165 func (dummyGI) DefaultVersionHostname() string
{ panic(ni()) } |
156 func (dummyGI) PublicCertificates() ([]GICertificate, error)
{ panic(ni()) } | 166 func (dummyGI) PublicCertificates() ([]appengine.Certificate, error)
{ panic(ni()) } |
157 func (dummyGI) RequestID() string
{ panic(ni()) } | 167 func (dummyGI) RequestID() string
{ panic(ni()) } |
158 func (dummyGI) ServiceAccount() (string, error)
{ panic(ni()) } | 168 func (dummyGI) ServiceAccount() (string, error)
{ panic(ni()) } |
159 func (dummyGI) SignBytes(bytes []byte) (keyName string, signature []byte, err er
ror) { panic(ni()) } | 169 func (dummyGI) SignBytes(bytes []byte) (keyName string, signature []byte, err er
ror) { panic(ni()) } |
160 func (dummyGI) VersionID() string
{ panic(ni()) } | 170 func (dummyGI) VersionID() string
{ panic(ni()) } |
161 func (dummyGI) Namespace(namespace string) (context.Context, error)
{ panic(ni()) } | 171 func (dummyGI) Namespace(namespace string) (context.Context, error)
{ panic(ni()) } |
162 func (dummyGI) Datacenter() string
{ panic(ni()) } | 172 func (dummyGI) Datacenter() string
{ panic(ni()) } |
163 func (dummyGI) InstanceID() string
{ panic(ni()) } | 173 func (dummyGI) InstanceID() string
{ panic(ni()) } |
164 func (dummyGI) IsDevAppServer() bool
{ panic(ni()) } | 174 func (dummyGI) IsDevAppserver() bool
{ panic(ni()) } |
165 func (dummyGI) ServerSoftware() string
{ panic(ni()) } | 175 func (dummyGI) ServerSoftware() string
{ panic(ni()) } |
166 func (dummyGI) IsCapabilityDisabled(err error) bool
{ panic(ni()) } | 176 func (dummyGI) IsCapabilityDisabled(err error) bool
{ panic(ni()) } |
167 func (dummyGI) IsOverQuota(err error) bool
{ panic(ni()) } | 177 func (dummyGI) IsOverQuota(err error) bool
{ panic(ni()) } |
168 func (dummyGI) IsTimeoutError(err error) bool
{ panic(ni()) } | 178 func (dummyGI) IsTimeoutError(err error) bool
{ panic(ni()) } |
169 | 179 |
170 var dummyGIInst = dummyGI{} | 180 var dummyGIInst = dummyGI{} |
171 | 181 |
172 // DummyGI returns a dummy GlobalInfo implementation suitable for embedding. | 182 // DummyGI returns a dummy GlobalInfo implementation suitable for embedding. |
173 // Every method panics with a message containing the name of the method which | 183 // Every method panics with a message containing the name of the method which |
174 // was unimplemented. | 184 // was unimplemented. |
175 func DummyGI() GlobalInfo { return dummyGIInst } | 185 func DummyGI() GlobalInfo { return dummyGIInst } |
OLD | NEW |