OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var overallTestStartTime = Date.now(); | 5 var overallTestStartTime = Date.now(); |
6 var kUseIndex = true; | 6 var kUseIndex = true; |
7 var kDontUseIndex = false; | 7 var kDontUseIndex = false; |
8 var kReadKeysOnly = true; | 8 var kReadKeysOnly = true; |
9 var kReadDataToo = false; | 9 var kReadDataToo = false; |
10 var kWriteToo = true; | 10 var kWriteToo = true; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 [testSporadicWrites, 5, 0], | 70 [testSporadicWrites, 5, 0], |
71 // Make large batches of random writes into a store, triggered by periodic | 71 // Make large batches of random writes into a store, triggered by periodic |
72 // setTimeout calls. | 72 // setTimeout calls. |
73 [testSporadicWrites, 500, 0], | 73 [testSporadicWrites, 500, 0], |
74 // Make batches of random writes into a store with many indices, triggered by | 74 // Make batches of random writes into a store with many indices, triggered by |
75 // periodic setTimeout calls. | 75 // periodic setTimeout calls. |
76 [testSporadicWrites, 5, 10], | 76 [testSporadicWrites, 5, 10], |
77 // Make large batches of random writes into a store with many indices, triggered | 77 // Make large batches of random writes into a store with many indices, triggered |
78 // by periodic setTimeout calls. | 78 // by periodic setTimeout calls. |
79 [testSporadicWrites, 500, 10], | 79 [testSporadicWrites, 500, 10], |
| 80 // Make a small bunch of batches of reads of the same keys from an object store. |
| 81 [testReadCache, 10, kDontUseIndex], |
| 82 // Make a bunch of batches of reads of the same keys from an index. |
| 83 [testReadCache, 50, kUseIndex], |
| 84 // Make a small bunch of batches of reads of the same keys from an object store. |
| 85 [testReadCache, 10, kDontUseIndex], |
| 86 // Make a bunch of batches of reads of the same keys from an index. |
| 87 [testReadCache, 50, kUseIndex], |
80 // Create and delete an index on a store that already contains data [produces | 88 // Create and delete an index on a store that already contains data [produces |
81 // a timing result for each of creation and deletion]. | 89 // a timing result for each of creation and deletion]. |
82 [testCreateAndDeleteIndex, 5000] | 90 [testCreateAndDeleteIndex, 5000] |
83 ]; | 91 ]; |
84 | 92 |
85 var currentTest = 0; | 93 var currentTest = 0; |
86 | 94 |
87 function test() { | 95 function test() { |
88 runNextTest(); | 96 runNextTest(); |
89 } | 97 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 186 } |
179 } | 187 } |
180 | 188 |
181 function testRandomReadsAndWrites( | 189 function testRandomReadsAndWrites( |
182 numKeys, numReadsPerTransaction, numWritesPerTransaction, numTransactions, | 190 numKeys, numReadsPerTransaction, numWritesPerTransaction, numTransactions, |
183 useIndexForReads, onTestComplete) { | 191 useIndexForReads, onTestComplete) { |
184 var indexName; | 192 var indexName; |
185 if (useIndexForReads) | 193 if (useIndexForReads) |
186 indexName = "index"; | 194 indexName = "index"; |
187 var testName = getDisplayName(arguments); | 195 var testName = getDisplayName(arguments); |
188 var numTransactionsLeft = numTransactions; | |
189 var objectStoreNames = ["store"]; | 196 var objectStoreNames = ["store"]; |
190 var numTransactionsRunning; | |
191 | 197 |
192 automation.setStatus("Creating database."); | 198 automation.setStatus("Creating database."); |
193 var options; | 199 var options; |
194 if (useIndexForReads) { | 200 if (useIndexForReads) { |
195 options = [{ | 201 options = [{ |
196 indexName: indexName, | 202 indexName: indexName, |
197 indexKeyPath: "", | 203 indexKeyPath: "", |
198 indexIsUnique: false, | 204 indexIsUnique: false, |
199 indexIsMultiEntry: false, | 205 indexIsMultiEntry: false, |
200 }]; | 206 }]; |
201 } | 207 } |
202 createDatabase(testName, objectStoreNames, onCreated, onError, options); | 208 createDatabase(testName, objectStoreNames, onCreated, onError, options); |
203 | 209 |
204 function onCreated(db) { | 210 function onCreated(db) { |
205 automation.setStatus("Setting up test database."); | 211 automation.setStatus("Setting up test database."); |
206 var transaction = getTransaction(db, objectStoreNames, "readwrite", | 212 var transaction = getTransaction(db, objectStoreNames, "readwrite", |
207 function() { onSetupComplete(db); }); | 213 function() { onSetupComplete(db); }); |
208 putLinearValues(transaction, objectStoreNames, numKeys, null, | 214 putLinearValues(transaction, objectStoreNames, numKeys, null, |
209 function () { return "test value"; }); | 215 function() { return "test value"; }); |
210 } | 216 } |
211 | 217 |
212 var completionFunc; | |
213 function onSetupComplete(db) { | 218 function onSetupComplete(db) { |
214 automation.setStatus("Setup complete."); | 219 automation.setStatus("Setup complete."); |
215 completionFunc = | 220 var completionFunc = |
216 getCompletionFunc(db, testName, Date.now(), onTestComplete); | 221 getCompletionFunc(db, testName, Date.now(), onTestComplete); |
217 runOneBatch(db); | |
218 } | |
219 | |
220 function runOneBatch(db) { | |
221 if (numTransactionsLeft <= 0) { | |
222 return; | |
223 } | |
224 --numTransactionsLeft; | |
225 ++numTransactionsRunning; | |
226 var mode = "readonly"; | 222 var mode = "readonly"; |
227 if (numWritesPerTransaction) | 223 if (numWritesPerTransaction) |
228 mode = "readwrite"; | 224 mode = "readwrite"; |
229 var transaction = getTransaction(db, objectStoreNames, mode, | 225 runTransactionBatch(db, numTransactions, batchFunc, objectStoreNames, mode, |
230 function() { | 226 completionFunc); |
231 assert(!--numTransactionsRunning); | 227 } |
232 if (numTransactionsLeft <= 0) { | |
233 completionFunc(); | |
234 } else { | |
235 runOneBatch(db); | |
236 } | |
237 }); | |
238 | 228 |
| 229 function batchFunc(transaction) { |
239 getRandomValues(transaction, objectStoreNames, numReadsPerTransaction, | 230 getRandomValues(transaction, objectStoreNames, numReadsPerTransaction, |
240 numKeys, indexName); | 231 numKeys, indexName); |
241 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, | 232 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, |
242 numKeys); | 233 numKeys); |
243 } | 234 } |
244 } | 235 } |
245 | 236 |
| 237 function testReadCache(numTransactions, useIndexForReads, onTestComplete) { |
| 238 var numKeys = 10000; |
| 239 var numReadsPerTransaction = 50; |
| 240 var numTransactionsLeft = numTransactions; |
| 241 var indexName; |
| 242 if (useIndexForReads) |
| 243 indexName = "index"; |
| 244 var testName = getDisplayName(arguments); |
| 245 var objectStoreNames = ["store"]; |
| 246 var keys = []; |
| 247 |
| 248 for (var i=0; i < numReadsPerTransaction; ++i) { |
| 249 keys.push(getSimpleKey(Math.floor(Math.random() * numKeys))); |
| 250 } |
| 251 |
| 252 automation.setStatus("Creating database."); |
| 253 var options; |
| 254 if (useIndexForReads) { |
| 255 options = [{ |
| 256 indexName: indexName, |
| 257 indexKeyPath: "", |
| 258 indexIsUnique: false, |
| 259 indexIsMultiEntry: false, |
| 260 }]; |
| 261 } |
| 262 createDatabase(testName, objectStoreNames, onCreated, onError, options); |
| 263 |
| 264 function onCreated(db) { |
| 265 automation.setStatus("Setting up test database."); |
| 266 var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| 267 function() { onSetupComplete(db); }); |
| 268 putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey, |
| 269 function () { return "test value"; }); |
| 270 } |
| 271 |
| 272 var completionFunc; |
| 273 function onSetupComplete(db) { |
| 274 automation.setStatus("Setup complete."); |
| 275 completionFunc = |
| 276 getCompletionFunc(db, testName, Date.now(), onTestComplete); |
| 277 runTransactionBatch(db, numTransactions, batchFunc, objectStoreNames, |
| 278 "readonly", completionFunc); |
| 279 } |
| 280 |
| 281 function batchFunc(transaction) { |
| 282 getSpecificValues(transaction, objectStoreNames, indexName, keys); |
| 283 } |
| 284 } |
| 285 |
246 function testCreateAndDeleteIndex(numKeys, onTestComplete) { | 286 function testCreateAndDeleteIndex(numKeys, onTestComplete) { |
247 var testName = getDisplayName(arguments); | 287 var testName = getDisplayName(arguments); |
248 var objectStoreNames = ["store"]; | 288 var objectStoreNames = ["store"]; |
249 | 289 |
250 automation.setStatus("Creating database."); | 290 automation.setStatus("Creating database."); |
251 createDatabase(testName, objectStoreNames, onCreated, onError); | 291 createDatabase(testName, objectStoreNames, onCreated, onError); |
252 | 292 |
253 var startTime; | 293 var startTime; |
254 function onCreated(db) { | 294 function onCreated(db) { |
255 automation.setStatus("Initializing data."); | 295 automation.setStatus("Initializing data."); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 468 |
429 var mode = "readonly"; | 469 var mode = "readonly"; |
430 if (numWritesPerTransaction) | 470 if (numWritesPerTransaction) |
431 mode = "readwrite"; | 471 mode = "readwrite"; |
432 | 472 |
433 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete); | 473 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete); |
434 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, | 474 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, |
435 numKeys); | 475 numKeys); |
436 } | 476 } |
437 } | 477 } |
OLD | NEW |