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