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

Side by Side Diff: impl/memory/taskqueue.go

Issue 1282673002: Make obtaining the Testable interface actually part of the interface. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « impl/dummy/dummy.go ('k') | impl/memory/taskqueue_data.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 memory 5 package memory
6 6
7 import ( 7 import (
8 "regexp" 8 "regexp"
9 "sync/atomic" 9 "sync/atomic"
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 s.OldestETA = t.ETA 138 s.OldestETA = t.ETA
139 } 139 }
140 } 140 }
141 cb(&s, nil) 141 cb(&s, nil)
142 } 142 }
143 } 143 }
144 144
145 return nil 145 return nil
146 } 146 }
147 147
148 func (t *taskqueueImpl) Testable() tq.Testable {
149 return t
150 }
151
148 /////////////////////////////// taskqueueTxnImpl /////////////////////////////// 152 /////////////////////////////// taskqueueTxnImpl ///////////////////////////////
149 153
150 type taskqueueTxnImpl struct { 154 type taskqueueTxnImpl struct {
151 *txnTaskQueueData 155 *txnTaskQueueData
152 156
153 ctx context.Context 157 ctx context.Context
154 ns string 158 ns string
155 } 159 }
156 160
157 var _ interface { 161 var _ interface {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 219 }
216 220
217 func (t *taskqueueTxnImpl) Purge(string) error { 221 func (t *taskqueueTxnImpl) Purge(string) error {
218 return errors.New("taskqueue: cannot Purge from a transaction") 222 return errors.New("taskqueue: cannot Purge from a transaction")
219 } 223 }
220 224
221 func (t *taskqueueTxnImpl) Stats([]string, tq.RawStatsCB) error { 225 func (t *taskqueueTxnImpl) Stats([]string, tq.RawStatsCB) error {
222 return errors.New("taskqueue: cannot Stats from a transaction") 226 return errors.New("taskqueue: cannot Stats from a transaction")
223 } 227 }
224 228
229 func (t *taskqueueTxnImpl) Testable() tq.Testable {
230 return t
231 }
232
225 ////////////////////////////// private functions /////////////////////////////// 233 ////////////////////////////// private functions ///////////////////////////////
226 234
227 var validTaskName = regexp.MustCompile("^[0-9a-zA-Z\\-\\_]{0,500}$") 235 var validTaskName = regexp.MustCompile("^[0-9a-zA-Z\\-\\_]{0,500}$")
228 236
229 const validTaskChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST UVWXYZ-_" 237 const validTaskChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST UVWXYZ-_"
230 238
231 func mkName(c context.Context, cur string, queue map[string]*tq.Task) string { 239 func mkName(c context.Context, cur string, queue map[string]*tq.Task) string {
232 _, ok := queue[cur] 240 _, ok := queue[cur]
233 for !ok && cur == "" { 241 for !ok && cur == "" {
234 name := [500]byte{} 242 name := [500]byte{}
235 for i := 0; i < 500; i++ { 243 for i := 0; i < 500; i++ {
236 name[i] = validTaskChars[mathrand.Get(c).Intn(len(validT askChars))] 244 name[i] = validTaskChars[mathrand.Get(c).Intn(len(validT askChars))]
237 } 245 }
238 cur = string(name[:]) 246 cur = string(name[:])
239 _, ok = queue[cur] 247 _, ok = queue[cur]
240 } 248 }
241 return cur 249 return cur
242 } 250 }
243 251
244 func dupQueue(q tq.QueueData) tq.QueueData { 252 func dupQueue(q tq.QueueData) tq.QueueData {
245 r := make(tq.QueueData, len(q)) 253 r := make(tq.QueueData, len(q))
246 for k, q := range q { 254 for k, q := range q {
247 r[k] = make(map[string]*tq.Task, len(q)) 255 r[k] = make(map[string]*tq.Task, len(q))
248 for tn, t := range q { 256 for tn, t := range q {
249 r[k][tn] = t.Duplicate() 257 r[k][tn] = t.Duplicate()
250 } 258 }
251 } 259 }
252 return r 260 return r
253 } 261 }
OLDNEW
« no previous file with comments | « impl/dummy/dummy.go ('k') | impl/memory/taskqueue_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698