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 provides a fakable wrapped interface for the appengine SDK's | 5 // Package gae provides a fakable wrapped interface for the appengine SDK's |
6 // APIs. This means that it's possible to mock all of the supported appengine | 6 // APIs. This means that it's possible to mock all of the supported appengine |
7 // APIs for testing (or potentially implement a different backend for them). | 7 // APIs for testing (or potentially implement a different backend for them). |
8 // | 8 // |
9 // Features | 9 // Features |
10 // | 10 // |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // } | 190 // } |
191 // | 191 // |
192 // Filters | 192 // Filters |
193 // | 193 // |
194 // Each service also supports "filters". Filters are proxy objects which have | 194 // Each service also supports "filters". Filters are proxy objects which have |
195 // the same interface as the service they're filtering, and pass data through to | 195 // the same interface as the service they're filtering, and pass data through to |
196 // the previous filter in the stack. Conceptually, a filtered version of, for | 196 // the previous filter in the stack. Conceptually, a filtered version of, for |
197 // example, the Datastore, could look like: | 197 // example, the Datastore, could look like: |
198 // User code | 198 // User code |
199 // <count filter (counts how many times each API is called by the user)> | 199 // <count filter (counts how many times each API is called by the user)> |
200 // <dscache filter (attempts to use memcache as a cache for datastore)> | 200 // <dscache filter (attempts to use memcache as a cache for rawdatastore)> |
201 // <count filter (counts how many times each API is actually hit)> | 201 // <count filter (counts how many times each API is actually hit)> |
202 // memory datastore.RawInterface implementation | 202 // memory datastore.RawInterface implementation |
203 // | 203 // |
204 // So datastore.Get would return the full stack. In code, this would look | 204 // So datastore.Get would return the full stack. In code, this would look |
205 // like: | 205 // like: |
206 // func HTTPHandler(r *http.Request) { | 206 // func HTTPHandler(r *http.Request) { |
207 // c := prod.UseRequest(r)
// production datastore | 207 // c := prod.UseRequest(r)
// production datastore |
208 // c, rawCount := count.FilterRDS(c) // add count filter | 208 // c, rawCount := count.FilterRDS(c) // add count filter |
209 // c = dscache.FilterRDS(c) // add dscache filter | 209 // c = dscache.FilterRDS(c) // add dscache filter |
210 // c, userCount := count.FilterRDS(c) // add another count filter | 210 // c, userCount := count.FilterRDS(c) // add another count filter |
211 // } | 211 // } |
212 // | 212 // |
213 // Filters may or may not have state, it's up to the filter itself. In the case | 213 // Filters may or may not have state, it's up to the filter itself. In the case |
214 // of the count filter, it returns its state from the Filter<Service> method, | 214 // of the count filter, it returns its state from the Filter<Service> method, |
215 // and the state can be observed to see how many times each API was invoked. | 215 // and the state can be observed to see how many times each API was invoked. |
216 // Since filters stack, we can compare counts from rawCount versus userCount to | 216 // Since filters stack, we can compare counts from rawCount versus userCount to |
217 // see how many calls to the actual real datastore went through, vs. how many | 217 // see how many calls to the actual real datastore went through, vs. how many |
218 // went to memcache, for example. | 218 // went to memcache, for example. |
219 // | 219 // |
220 // Note that Filters apply only to the service.RawInterface. All implementations | 220 // Note that Filters apply only to the service.RawInterface. All implementations |
221 // of service.Interface boil down to calls to service.RawInterface methods, but | 221 // of service.Interface boil down to calls to service.RawInterface methods, but |
222 // it's possible that bad calls to the service.Interface methods could return | 222 // it's possible that bad calls to the service.Interface methods could return |
223 // an error before ever reaching the filters or service implementation. | 223 // an error before ever reaching the filters or service implementation. |
224 package gae | 224 package gae |
OLD | NEW |