OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.src.context.cache_test; | 5 library analyzer.test.src.context.cache_test; |
6 | 6 |
7 import 'package:analyzer/exception/exception.dart'; | 7 import 'package:analyzer/exception/exception.dart'; |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 } | 51 } |
52 | 52 |
53 @reflectiveTest | 53 @reflectiveTest |
54 class AnalysisCacheTest extends AbstractCacheTest { | 54 class AnalysisCacheTest extends AbstractCacheTest { |
55 void test_creation() { | 55 void test_creation() { |
56 expect(cache, isNotNull); | 56 expect(cache, isNotNull); |
57 } | 57 } |
58 | 58 |
59 test_flush() { | 59 test_flush() { |
60 AnalysisTarget target = new TestSource(); | 60 AnalysisTarget target = new TestSource(); |
61 ResultDescriptor resultA = new ResultDescriptor('A', null); | 61 ResultDescriptor<String> resultA = new ResultDescriptor<String>('A', null); |
scheglov
2016/09/21 00:05:07
I would just drop the LHS type.
Jennifer Messerly
2016/09/21 00:20:30
yeah +1 to that.
But I do wonder about this one.
Brian Wilkerson
2016/09/21 15:00:43
I expect someone will write a bulk edit tool at so
| |
62 ResultDescriptor resultB = new ResultDescriptor('B', null); | 62 ResultDescriptor<String> resultB = new ResultDescriptor<String>('B', null); |
63 CacheEntry entry = new CacheEntry(target); | 63 CacheEntry entry = new CacheEntry(target); |
64 cache.put(entry); | 64 cache.put(entry); |
65 // put values | 65 // put values |
66 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); | 66 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); |
67 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); | 67 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); |
68 expect(cache.getState(target, resultA), CacheState.VALID); | 68 expect(cache.getState(target, resultA), CacheState.VALID); |
69 expect(cache.getState(target, resultB), CacheState.VALID); | 69 expect(cache.getState(target, resultB), CacheState.VALID); |
70 expect(cache.getValue(target, resultA), 'a'); | 70 expect(cache.getValue(target, resultA), 'a'); |
71 expect(cache.getValue(target, resultB), 'b'); | 71 expect(cache.getValue(target, resultB), 'b'); |
72 // flush A | 72 // flush A |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 void test_getState_hasEntry_flushed() { | 117 void test_getState_hasEntry_flushed() { |
118 ResultDescriptor result = new ResultDescriptor('result', -1); | 118 ResultDescriptor result = new ResultDescriptor('result', -1); |
119 AnalysisTarget target = new TestSource(); | 119 AnalysisTarget target = new TestSource(); |
120 CacheEntry entry = new CacheEntry(target); | 120 CacheEntry entry = new CacheEntry(target); |
121 cache.put(entry); | 121 cache.put(entry); |
122 entry.setState(result, CacheState.FLUSHED); | 122 entry.setState(result, CacheState.FLUSHED); |
123 expect(cache.getState(target, result), CacheState.FLUSHED); | 123 expect(cache.getState(target, result), CacheState.FLUSHED); |
124 } | 124 } |
125 | 125 |
126 void test_getState_hasEntry_valid() { | 126 void test_getState_hasEntry_valid() { |
127 ResultDescriptor result = new ResultDescriptor('result', -1); | 127 ResultDescriptor<String> result = |
128 new ResultDescriptor<String>('result', null); | |
128 AnalysisTarget target = new TestSource(); | 129 AnalysisTarget target = new TestSource(); |
129 CacheEntry entry = new CacheEntry(target); | 130 CacheEntry entry = new CacheEntry(target); |
130 cache.put(entry); | 131 cache.put(entry); |
131 entry.setValue(result, '', []); | 132 entry.setValue(result, '', []); |
132 expect(cache.getState(target, result), CacheState.VALID); | 133 expect(cache.getState(target, result), CacheState.VALID); |
133 } | 134 } |
134 | 135 |
135 void test_getState_noEntry() { | 136 void test_getState_noEntry() { |
136 ResultDescriptor result = new ResultDescriptor('result', -1); | 137 ResultDescriptor result = new ResultDescriptor('result', -1); |
137 AnalysisTarget target = new TestSource(); | 138 AnalysisTarget target = new TestSource(); |
138 expect(cache.getState(target, result), CacheState.INVALID); | 139 expect(cache.getState(target, result), CacheState.INVALID); |
139 } | 140 } |
140 | 141 |
141 void test_getValue_hasEntry_valid() { | 142 void test_getValue_hasEntry_valid() { |
142 ResultDescriptor result = new ResultDescriptor('result', -1); | 143 ResultDescriptor<int> result = new ResultDescriptor<int>('result', -1); |
143 AnalysisTarget target = new TestSource(); | 144 AnalysisTarget target = new TestSource(); |
144 CacheEntry entry = new CacheEntry(target); | 145 CacheEntry entry = new CacheEntry(target); |
145 cache.put(entry); | 146 cache.put(entry); |
146 entry.setValue(result, 111, []); | 147 entry.setValue(result, 111, []); |
147 expect(cache.getValue(target, result), 111); | 148 expect(cache.getValue(target, result), 111); |
148 } | 149 } |
149 | 150 |
150 void test_getValue_noEntry() { | 151 void test_getValue_noEntry() { |
151 ResultDescriptor result = new ResultDescriptor('result', -1); | 152 ResultDescriptor result = new ResultDescriptor('result', -1); |
152 AnalysisTarget target = new TestSource(); | 153 AnalysisTarget target = new TestSource(); |
(...skipping 22 matching lines...) Expand all Loading... | |
175 void test_remove() { | 176 void test_remove() { |
176 AnalysisTarget target1 = new TestSource('/a.dart'); | 177 AnalysisTarget target1 = new TestSource('/a.dart'); |
177 AnalysisTarget target2 = new TestSource('/b.dart'); | 178 AnalysisTarget target2 = new TestSource('/b.dart'); |
178 AnalysisTarget target3 = new TestSource('/c.dart'); | 179 AnalysisTarget target3 = new TestSource('/c.dart'); |
179 CacheEntry entry1 = new CacheEntry(target1); | 180 CacheEntry entry1 = new CacheEntry(target1); |
180 CacheEntry entry2 = new CacheEntry(target2); | 181 CacheEntry entry2 = new CacheEntry(target2); |
181 CacheEntry entry3 = new CacheEntry(target3); | 182 CacheEntry entry3 = new CacheEntry(target3); |
182 cache.put(entry1); | 183 cache.put(entry1); |
183 cache.put(entry2); | 184 cache.put(entry2); |
184 cache.put(entry3); | 185 cache.put(entry3); |
185 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 186 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
186 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 187 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
187 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 188 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
188 // set results, all of them are VALID | 189 // set results, all of them are VALID |
189 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 190 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
190 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 191 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
191 entry3.setValue(result3, 333, []); | 192 entry3.setValue(result3, 333, []); |
192 expect(entry1.getState(result1), CacheState.VALID); | 193 expect(entry1.getState(result1), CacheState.VALID); |
193 expect(entry2.getState(result2), CacheState.VALID); | 194 expect(entry2.getState(result2), CacheState.VALID); |
194 expect(entry3.getState(result3), CacheState.VALID); | 195 expect(entry3.getState(result3), CacheState.VALID); |
195 expect(entry1.getValue(result1), 111); | 196 expect(entry1.getValue(result1), 111); |
196 expect(entry2.getValue(result2), 222); | 197 expect(entry2.getValue(result2), 222); |
197 expect(entry3.getValue(result3), 333); | 198 expect(entry3.getValue(result3), 333); |
198 // remove entry1, invalidate result2 and remove empty entry2 | 199 // remove entry1, invalidate result2 and remove empty entry2 |
199 expect(cache.remove(target1), entry1); | 200 expect(cache.remove(target1), entry1); |
200 expect(cache.get(target1), isNull); | 201 expect(cache.get(target1), isNull); |
201 expect(cache.get(target2), isNull); | 202 expect(cache.get(target2), isNull); |
202 expect(cache.get(target3), entry3); | 203 expect(cache.get(target3), entry3); |
203 expect(entry3.getState(result3), CacheState.VALID); | 204 expect(entry3.getState(result3), CacheState.VALID); |
204 } | 205 } |
205 | 206 |
206 void test_remove_invalidateResults_sameTarget() { | 207 void test_remove_invalidateResults_sameTarget() { |
207 AnalysisTarget target = new TestSource('/a.dart'); | 208 AnalysisTarget target = new TestSource('/a.dart'); |
208 CacheEntry entry = new CacheEntry(target); | 209 CacheEntry entry = new CacheEntry(target); |
209 cache.put(entry); | 210 cache.put(entry); |
210 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 211 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
211 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 212 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
212 // set results, all of them are VALID | 213 // set results, all of them are VALID |
213 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 214 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
214 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 215 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
215 expect(entry.getState(result1), CacheState.VALID); | 216 expect(entry.getState(result1), CacheState.VALID); |
216 expect(entry.getState(result2), CacheState.VALID); | 217 expect(entry.getState(result2), CacheState.VALID); |
217 expect(entry.getValue(result1), 111); | 218 expect(entry.getValue(result1), 111); |
218 expect(entry.getValue(result2), 222); | 219 expect(entry.getValue(result2), 222); |
219 // remove target, invalidate result2 | 220 // remove target, invalidate result2 |
220 expect(cache.remove(target), entry); | 221 expect(cache.remove(target), entry); |
221 expect(cache.get(target), isNull); | 222 expect(cache.get(target), isNull); |
(...skipping 29 matching lines...) Expand all Loading... | |
251 expect(cache.sources, unorderedEquals([source2])); | 252 expect(cache.sources, unorderedEquals([source2])); |
252 // remove source2 | 253 // remove source2 |
253 cache.remove(source2); | 254 cache.remove(source2); |
254 expect(cache.sources, isEmpty); | 255 expect(cache.sources, isEmpty); |
255 } | 256 } |
256 } | 257 } |
257 | 258 |
258 @reflectiveTest | 259 @reflectiveTest |
259 class CacheEntryTest extends AbstractCacheTest { | 260 class CacheEntryTest extends AbstractCacheTest { |
260 test_dispose() { | 261 test_dispose() { |
261 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); | 262 ResultDescriptor<int> descriptor1 = |
262 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); | 263 new ResultDescriptor<int>('result1', -1); |
264 ResultDescriptor<int> descriptor2 = | |
265 new ResultDescriptor<int>('result2', -2); | |
263 AnalysisTarget target1 = new TestSource('1.dart'); | 266 AnalysisTarget target1 = new TestSource('1.dart'); |
264 AnalysisTarget target2 = new TestSource('2.dart'); | 267 AnalysisTarget target2 = new TestSource('2.dart'); |
265 TargetedResult result1 = new TargetedResult(target1, descriptor1); | 268 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
266 TargetedResult result2 = new TargetedResult(target2, descriptor2); | 269 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
267 CacheEntry entry1 = new CacheEntry(target1); | 270 CacheEntry entry1 = new CacheEntry(target1); |
268 CacheEntry entry2 = new CacheEntry(target2); | 271 CacheEntry entry2 = new CacheEntry(target2); |
269 cache.put(entry1); | 272 cache.put(entry1); |
270 cache.put(entry2); | 273 cache.put(entry2); |
271 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 274 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
272 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); | 275 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
(...skipping 20 matching lines...) Expand all Loading... | |
293 CacheEntry entry = new CacheEntry(target); | 296 CacheEntry entry = new CacheEntry(target); |
294 cache.put(entry); | 297 cache.put(entry); |
295 entry.setErrorState(exception, <ResultDescriptor>[result]); | 298 entry.setErrorState(exception, <ResultDescriptor>[result]); |
296 entry.fixExceptionState(); | 299 entry.fixExceptionState(); |
297 expect(entry.getState(result), CacheState.ERROR); | 300 expect(entry.getState(result), CacheState.ERROR); |
298 expect(entry.exception, exception); | 301 expect(entry.exception, exception); |
299 } | 302 } |
300 | 303 |
301 test_fixExceptionState_noError_exception() { | 304 test_fixExceptionState_noError_exception() { |
302 AnalysisTarget target = new TestSource(); | 305 AnalysisTarget target = new TestSource(); |
303 ResultDescriptor result = new ResultDescriptor('test', null); | 306 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
304 CacheEntry entry = new CacheEntry(target); | 307 CacheEntry entry = new CacheEntry(target); |
305 cache.put(entry); | 308 cache.put(entry); |
306 // set one result to ERROR | 309 // set one result to ERROR |
307 CaughtException exception = new CaughtException(null, null); | 310 CaughtException exception = new CaughtException(null, null); |
308 entry.setErrorState(exception, <ResultDescriptor>[result]); | 311 entry.setErrorState(exception, <ResultDescriptor>[result]); |
309 // set the same result to VALID | 312 // set the same result to VALID |
310 entry.setValue(result, 1, TargetedResult.EMPTY_LIST); | 313 entry.setValue(result, 1, TargetedResult.EMPTY_LIST); |
311 // fix the exception state | 314 // fix the exception state |
312 entry.fixExceptionState(); | 315 entry.fixExceptionState(); |
313 expect(entry.exception, isNull); | 316 expect(entry.exception, isNull); |
314 } | 317 } |
315 | 318 |
316 test_fixExceptionState_noError_noException() { | 319 test_fixExceptionState_noError_noException() { |
317 AnalysisTarget target = new TestSource(); | 320 AnalysisTarget target = new TestSource(); |
318 ResultDescriptor result = new ResultDescriptor('test', null); | 321 ResultDescriptor result = new ResultDescriptor('test', null); |
319 CacheEntry entry = new CacheEntry(target); | 322 CacheEntry entry = new CacheEntry(target); |
320 entry.fixExceptionState(); | 323 entry.fixExceptionState(); |
321 expect(entry.getState(result), CacheState.INVALID); | 324 expect(entry.getState(result), CacheState.INVALID); |
322 expect(entry.exception, isNull); | 325 expect(entry.exception, isNull); |
323 } | 326 } |
324 | 327 |
325 test_flush() { | 328 test_flush() { |
326 AnalysisTarget target = new TestSource(); | 329 AnalysisTarget target = new TestSource(); |
327 ResultDescriptor resultA = new ResultDescriptor('A', null); | 330 ResultDescriptor<String> resultA = new ResultDescriptor<String>('A', null); |
328 ResultDescriptor resultB = new ResultDescriptor('B', null); | 331 ResultDescriptor<String> resultB = new ResultDescriptor<String>('B', null); |
329 CacheEntry entry = new CacheEntry(target); | 332 CacheEntry entry = new CacheEntry(target); |
330 cache.put(entry); | 333 cache.put(entry); |
331 // put values | 334 // put values |
332 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); | 335 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); |
333 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); | 336 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); |
334 expect(entry.getState(resultA), CacheState.VALID); | 337 expect(entry.getState(resultA), CacheState.VALID); |
335 expect(entry.getState(resultB), CacheState.VALID); | 338 expect(entry.getState(resultB), CacheState.VALID); |
336 expect(entry.getValue(resultA), 'a'); | 339 expect(entry.getValue(resultA), 'a'); |
337 expect(entry.getValue(resultB), 'b'); | 340 expect(entry.getValue(resultB), 'b'); |
338 // flush A | 341 // flush A |
(...skipping 13 matching lines...) Expand all Loading... | |
352 | 355 |
353 test_getValue_default() { | 356 test_getValue_default() { |
354 AnalysisTarget target = new TestSource(); | 357 AnalysisTarget target = new TestSource(); |
355 String defaultValue = 'value'; | 358 String defaultValue = 'value'; |
356 ResultDescriptor result = new ResultDescriptor('test', defaultValue); | 359 ResultDescriptor result = new ResultDescriptor('test', defaultValue); |
357 CacheEntry entry = new CacheEntry(target); | 360 CacheEntry entry = new CacheEntry(target); |
358 expect(entry.getValue(result), defaultValue); | 361 expect(entry.getValue(result), defaultValue); |
359 } | 362 } |
360 | 363 |
361 test_getValue_flushResults() { | 364 test_getValue_flushResults() { |
362 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 365 ResultCachingPolicy<int> cachingPolicy = |
363 ResultDescriptor descriptor1 = | 366 new SimpleResultCachingPolicy<int>(2, 2); |
364 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); | 367 ResultDescriptor<int> descriptor1 = new ResultDescriptor<int>( |
365 ResultDescriptor descriptor2 = | 368 'result1', null, |
366 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); | 369 cachingPolicy: cachingPolicy); |
367 ResultDescriptor descriptor3 = | 370 ResultDescriptor<int> descriptor2 = new ResultDescriptor<int>( |
368 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); | 371 'result2', null, |
372 cachingPolicy: cachingPolicy); | |
373 ResultDescriptor<int> descriptor3 = new ResultDescriptor<int>( | |
374 'result3', null, | |
375 cachingPolicy: cachingPolicy); | |
369 AnalysisTarget target = new TestSource(); | 376 AnalysisTarget target = new TestSource(); |
370 CacheEntry entry = new CacheEntry(target); | 377 CacheEntry entry = new CacheEntry(target); |
371 cache.put(entry); | 378 cache.put(entry); |
372 { | 379 { |
373 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 380 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
374 expect(entry.getState(descriptor1), CacheState.VALID); | 381 expect(entry.getState(descriptor1), CacheState.VALID); |
375 } | 382 } |
376 { | 383 { |
377 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); | 384 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); |
378 expect(entry.getState(descriptor1), CacheState.VALID); | 385 expect(entry.getState(descriptor1), CacheState.VALID); |
(...skipping 20 matching lines...) Expand all Loading... | |
399 ResultDescriptor result = new ResultDescriptor('test', null); | 406 ResultDescriptor result = new ResultDescriptor('test', null); |
400 CaughtException exception = new CaughtException(null, null); | 407 CaughtException exception = new CaughtException(null, null); |
401 CacheEntry entry = new CacheEntry(target); | 408 CacheEntry entry = new CacheEntry(target); |
402 cache.put(entry); | 409 cache.put(entry); |
403 entry.setErrorState(exception, <ResultDescriptor>[result]); | 410 entry.setErrorState(exception, <ResultDescriptor>[result]); |
404 expect(entry.hasErrorState(), true); | 411 expect(entry.hasErrorState(), true); |
405 } | 412 } |
406 | 413 |
407 test_invalidateAllInformation() { | 414 test_invalidateAllInformation() { |
408 AnalysisTarget target = new TestSource(); | 415 AnalysisTarget target = new TestSource(); |
409 ResultDescriptor result = new ResultDescriptor('test', null); | 416 ResultDescriptor<String> result = |
417 new ResultDescriptor<String>('test', null); | |
410 CacheEntry entry = new CacheEntry(target); | 418 CacheEntry entry = new CacheEntry(target); |
411 cache.put(entry); | 419 cache.put(entry); |
412 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); | 420 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); |
413 entry.invalidateAllInformation(); | 421 entry.invalidateAllInformation(); |
414 expect(entry.getState(result), CacheState.INVALID); | 422 expect(entry.getState(result), CacheState.INVALID); |
415 expect(entry.getValue(result), isNull); | 423 expect(entry.getValue(result), isNull); |
416 } | 424 } |
417 | 425 |
418 test_setErrorState() { | 426 test_setErrorState() { |
419 AnalysisTarget target = new TestSource(); | 427 AnalysisTarget target = new TestSource(); |
420 ResultDescriptor result1 = new ResultDescriptor('res1', 1); | 428 ResultDescriptor<int> result1 = new ResultDescriptor<int>('res1', 1); |
421 ResultDescriptor result2 = new ResultDescriptor('res2', 2); | 429 ResultDescriptor<int> result2 = new ResultDescriptor<int>('res2', 2); |
422 ResultDescriptor result3 = new ResultDescriptor('res3', 3); | 430 ResultDescriptor<int> result3 = new ResultDescriptor<int>('res3', 3); |
423 // prepare some good state | 431 // prepare some good state |
424 CacheEntry entry = new CacheEntry(target); | 432 CacheEntry entry = new CacheEntry(target); |
425 cache.put(entry); | 433 cache.put(entry); |
426 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); | 434 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); |
427 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); | 435 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); |
428 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); | 436 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); |
429 // set error state | 437 // set error state |
430 CaughtException exception = new CaughtException(null, null); | 438 CaughtException exception = new CaughtException(null, null); |
431 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); | 439 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); |
432 // verify | 440 // verify |
433 expect(entry.exception, exception); | 441 expect(entry.exception, exception); |
434 expect(entry.getState(result1), CacheState.ERROR); | 442 expect(entry.getState(result1), CacheState.ERROR); |
435 expect(entry.getState(result2), CacheState.ERROR); | 443 expect(entry.getState(result2), CacheState.ERROR); |
436 expect(entry.getState(result3), CacheState.VALID); | 444 expect(entry.getState(result3), CacheState.VALID); |
437 expect(entry.getValue(result1), 1); | 445 expect(entry.getValue(result1), 1); |
438 expect(entry.getValue(result2), 2); | 446 expect(entry.getValue(result2), 2); |
439 expect(entry.getValue(result3), 30); | 447 expect(entry.getValue(result3), 30); |
440 } | 448 } |
441 | 449 |
442 test_setErrorState_invalidateDependent() { | 450 test_setErrorState_invalidateDependent() { |
443 AnalysisTarget target1 = new TestSource('/a.dart'); | 451 AnalysisTarget target1 = new TestSource('/a.dart'); |
444 AnalysisTarget target2 = new TestSource('/b.dart'); | 452 AnalysisTarget target2 = new TestSource('/b.dart'); |
445 CacheEntry entry1 = new CacheEntry(target1); | 453 CacheEntry entry1 = new CacheEntry(target1); |
446 CacheEntry entry2 = new CacheEntry(target2); | 454 CacheEntry entry2 = new CacheEntry(target2); |
447 cache.put(entry1); | 455 cache.put(entry1); |
448 cache.put(entry2); | 456 cache.put(entry2); |
449 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 457 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
450 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 458 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
451 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 459 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
452 ResultDescriptor result4 = new ResultDescriptor('result4', -4); | 460 ResultDescriptor<int> result4 = new ResultDescriptor<int>('result4', -4); |
453 // set results, all of them are VALID | 461 // set results, all of them are VALID |
454 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 462 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
455 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 463 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
456 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); | 464 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); |
457 entry2.setValue(result4, 444, []); | 465 entry2.setValue(result4, 444, []); |
458 expect(entry1.getState(result1), CacheState.VALID); | 466 expect(entry1.getState(result1), CacheState.VALID); |
459 expect(entry2.getState(result2), CacheState.VALID); | 467 expect(entry2.getState(result2), CacheState.VALID); |
460 expect(entry2.getState(result3), CacheState.VALID); | 468 expect(entry2.getState(result3), CacheState.VALID); |
461 expect(entry2.getState(result4), CacheState.VALID); | 469 expect(entry2.getState(result4), CacheState.VALID); |
462 expect(entry1.getValue(result1), 111); | 470 expect(entry1.getValue(result1), 111); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 AnalysisTarget target = new TestSource(); | 509 AnalysisTarget target = new TestSource(); |
502 CaughtException exception = new CaughtException(null, null); | 510 CaughtException exception = new CaughtException(null, null); |
503 CacheEntry entry = new CacheEntry(target); | 511 CacheEntry entry = new CacheEntry(target); |
504 expect(() { | 512 expect(() { |
505 entry.setErrorState(exception, null); | 513 entry.setErrorState(exception, null); |
506 }, throwsArgumentError); | 514 }, throwsArgumentError); |
507 } | 515 } |
508 | 516 |
509 test_setState_error() { | 517 test_setState_error() { |
510 AnalysisTarget target = new TestSource(); | 518 AnalysisTarget target = new TestSource(); |
511 ResultDescriptor result = new ResultDescriptor('test', null); | 519 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
512 CacheEntry entry = new CacheEntry(target); | 520 CacheEntry entry = new CacheEntry(target); |
513 cache.put(entry); | 521 cache.put(entry); |
514 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 522 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
515 // an invalid state change | 523 // an invalid state change |
516 expect(() { | 524 expect(() { |
517 entry.setState(result, CacheState.ERROR); | 525 entry.setState(result, CacheState.ERROR); |
518 }, throwsArgumentError); | 526 }, throwsArgumentError); |
519 // no changes | 527 // no changes |
520 expect(entry.getState(result), CacheState.VALID); | 528 expect(entry.getState(result), CacheState.VALID); |
521 expect(entry.getValue(result), 42); | 529 expect(entry.getValue(result), 42); |
522 } | 530 } |
523 | 531 |
524 test_setState_flushed() { | 532 test_setState_flushed() { |
525 AnalysisTarget target = new TestSource(); | 533 AnalysisTarget target = new TestSource(); |
526 ResultDescriptor result = new ResultDescriptor('test', 1); | 534 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
527 CacheEntry entry = new CacheEntry(target); | 535 CacheEntry entry = new CacheEntry(target); |
528 cache.put(entry); | 536 cache.put(entry); |
529 // set VALID | 537 // set VALID |
530 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 538 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
531 expect(entry.getState(result), CacheState.VALID); | 539 expect(entry.getState(result), CacheState.VALID); |
532 expect(entry.getValue(result), 10); | 540 expect(entry.getValue(result), 10); |
533 // set FLUSHED | 541 // set FLUSHED |
534 entry.setState(result, CacheState.FLUSHED); | 542 entry.setState(result, CacheState.FLUSHED); |
535 expect(entry.getState(result), CacheState.FLUSHED); | 543 expect(entry.getState(result), CacheState.FLUSHED); |
536 expect(entry.getValue(result), 1); | 544 expect(entry.getValue(result), 1); |
537 } | 545 } |
538 | 546 |
539 test_setState_inProcess() { | 547 test_setState_inProcess() { |
540 AnalysisTarget target = new TestSource(); | 548 AnalysisTarget target = new TestSource(); |
541 ResultDescriptor result = new ResultDescriptor('test', 1); | 549 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
542 CacheEntry entry = new CacheEntry(target); | 550 CacheEntry entry = new CacheEntry(target); |
543 cache.put(entry); | 551 cache.put(entry); |
544 // set VALID | 552 // set VALID |
545 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 553 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
546 expect(entry.getState(result), CacheState.VALID); | 554 expect(entry.getState(result), CacheState.VALID); |
547 expect(entry.getValue(result), 10); | 555 expect(entry.getValue(result), 10); |
548 // set IN_PROCESS | 556 // set IN_PROCESS |
549 entry.setState(result, CacheState.IN_PROCESS); | 557 entry.setState(result, CacheState.IN_PROCESS); |
550 expect(entry.getState(result), CacheState.IN_PROCESS); | 558 expect(entry.getState(result), CacheState.IN_PROCESS); |
551 expect(entry.getValue(result), 10); | 559 expect(entry.getValue(result), 10); |
552 } | 560 } |
553 | 561 |
554 test_setState_invalid() { | 562 test_setState_invalid() { |
555 AnalysisTarget target = new TestSource(); | 563 AnalysisTarget target = new TestSource(); |
556 ResultDescriptor result = new ResultDescriptor('test', 1); | 564 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
557 CacheEntry entry = new CacheEntry(target); | 565 CacheEntry entry = new CacheEntry(target); |
558 cache.put(entry); | 566 cache.put(entry); |
559 // set VALID | 567 // set VALID |
560 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 568 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
561 expect(entry.getState(result), CacheState.VALID); | 569 expect(entry.getState(result), CacheState.VALID); |
562 expect(entry.getValue(result), 10); | 570 expect(entry.getValue(result), 10); |
563 // listen, expect "result" invalidation event | 571 // listen, expect "result" invalidation event |
564 int numberOfEvents = 0; | 572 int numberOfEvents = 0; |
565 cache.onResultInvalidated.listen((event) { | 573 cache.onResultInvalidated.listen((event) { |
566 numberOfEvents++; | 574 numberOfEvents++; |
567 expect(event.entry, same(entry)); | 575 expect(event.entry, same(entry)); |
568 expect(event.descriptor, same(result)); | 576 expect(event.descriptor, same(result)); |
569 }); | 577 }); |
570 // set INVALID | 578 // set INVALID |
571 entry.setState(result, CacheState.INVALID); | 579 entry.setState(result, CacheState.INVALID); |
572 expect(entry.getState(result), CacheState.INVALID); | 580 expect(entry.getState(result), CacheState.INVALID); |
573 expect(entry.getValue(result), 1); | 581 expect(entry.getValue(result), 1); |
574 expect(numberOfEvents, 1); | 582 expect(numberOfEvents, 1); |
575 } | 583 } |
576 | 584 |
577 test_setState_invalid_dependencyCycle() { | 585 test_setState_invalid_dependencyCycle() { |
578 AnalysisTarget target1 = new TestSource('/a.dart'); | 586 AnalysisTarget target1 = new TestSource('/a.dart'); |
579 AnalysisTarget target2 = new TestSource('/b.dart'); | 587 AnalysisTarget target2 = new TestSource('/b.dart'); |
580 CacheEntry entry1 = new CacheEntry(target1); | 588 CacheEntry entry1 = new CacheEntry(target1); |
581 CacheEntry entry2 = new CacheEntry(target2); | 589 CacheEntry entry2 = new CacheEntry(target2); |
582 cache.put(entry1); | 590 cache.put(entry1); |
583 cache.put(entry2); | 591 cache.put(entry2); |
584 ResultDescriptor result = new ResultDescriptor('result', -1); | 592 ResultDescriptor<int> result = new ResultDescriptor<int>('result', -1); |
585 // Set each result as VALID with a dependency on on the other. | 593 // Set each result as VALID with a dependency on on the other. |
586 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); | 594 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); |
587 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); | 595 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); |
588 expect(entry1.getState(result), CacheState.VALID); | 596 expect(entry1.getState(result), CacheState.VALID); |
589 expect(entry2.getState(result), CacheState.VALID); | 597 expect(entry2.getState(result), CacheState.VALID); |
590 // Listen, expect entry1.result and entry2.result invalidation events. | 598 // Listen, expect entry1.result and entry2.result invalidation events. |
591 int numberOfEvents = 0; | 599 int numberOfEvents = 0; |
592 bool wasEntry1 = false; | 600 bool wasEntry1 = false; |
593 bool wasEntry2 = false; | 601 bool wasEntry2 = false; |
594 cache.onResultInvalidated.listen((event) { | 602 cache.onResultInvalidated.listen((event) { |
595 numberOfEvents++; | 603 numberOfEvents++; |
596 if (event.entry == entry1) wasEntry1 = true; | 604 if (event.entry == entry1) wasEntry1 = true; |
597 if (event.entry == entry2) wasEntry2 = true; | 605 if (event.entry == entry2) wasEntry2 = true; |
598 expect(event.descriptor, same(result)); | 606 expect(event.descriptor, same(result)); |
599 }); | 607 }); |
600 // Invalidate entry1.result; this should cause entry2 to be also | 608 // Invalidate entry1.result; this should cause entry2 to be also |
601 // cleared without going into an infinite regress. | 609 // cleared without going into an infinite regress. |
602 entry1.setState(result, CacheState.INVALID); | 610 entry1.setState(result, CacheState.INVALID); |
603 expect(cache.get(target1), isNull); | 611 expect(cache.get(target1), isNull); |
604 expect(cache.get(target2), isNull); | 612 expect(cache.get(target2), isNull); |
605 expect(numberOfEvents, 2); | 613 expect(numberOfEvents, 2); |
606 expect(wasEntry1, isTrue); | 614 expect(wasEntry1, isTrue); |
607 expect(wasEntry2, isTrue); | 615 expect(wasEntry2, isTrue); |
608 } | 616 } |
609 | 617 |
610 test_setState_invalid_invalidateDependent() { | 618 test_setState_invalid_invalidateDependent() { |
611 AnalysisTarget target = new TestSource(); | 619 AnalysisTarget target = new TestSource(); |
612 CacheEntry entry = new CacheEntry(target); | 620 CacheEntry entry = new CacheEntry(target); |
613 cache.put(entry); | 621 cache.put(entry); |
614 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 622 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
615 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 623 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
616 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 624 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
617 ResultDescriptor result4 = new ResultDescriptor('result4', -4); | 625 ResultDescriptor<int> result4 = new ResultDescriptor<int>('result4', -4); |
618 // set results, all of them are VALID | 626 // set results, all of them are VALID |
619 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 627 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
620 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 628 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
621 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 629 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
622 entry.setValue(result4, 444, []); | 630 entry.setValue(result4, 444, []); |
623 expect(entry.getState(result1), CacheState.VALID); | 631 expect(entry.getState(result1), CacheState.VALID); |
624 expect(entry.getState(result2), CacheState.VALID); | 632 expect(entry.getState(result2), CacheState.VALID); |
625 expect(entry.getState(result3), CacheState.VALID); | 633 expect(entry.getState(result3), CacheState.VALID); |
626 expect(entry.getState(result4), CacheState.VALID); | 634 expect(entry.getState(result4), CacheState.VALID); |
627 expect(entry.getValue(result1), 111); | 635 expect(entry.getValue(result1), 111); |
(...skipping 12 matching lines...) Expand all Loading... | |
640 expect(entry.getValue(result4), 444); | 648 expect(entry.getValue(result4), 444); |
641 // result4 is still valid, so the entry is still in the cache | 649 // result4 is still valid, so the entry is still in the cache |
642 expect(cache.get(target), entry); | 650 expect(cache.get(target), entry); |
643 } | 651 } |
644 | 652 |
645 test_setState_invalid_keepEmpty_ifExplicitlyAdded() { | 653 test_setState_invalid_keepEmpty_ifExplicitlyAdded() { |
646 AnalysisTarget target = new TestSource('/a.dart'); | 654 AnalysisTarget target = new TestSource('/a.dart'); |
647 CacheEntry entry = new CacheEntry(target); | 655 CacheEntry entry = new CacheEntry(target); |
648 entry.explicitlyAdded = true; | 656 entry.explicitlyAdded = true; |
649 cache.put(entry); | 657 cache.put(entry); |
650 ResultDescriptor result = new ResultDescriptor('result1', -1); | 658 ResultDescriptor<int> result = new ResultDescriptor<int>('result1', -1); |
651 // set results, all of them are VALID | 659 // set results, all of them are VALID |
652 entry.setValue(result, 111, TargetedResult.EMPTY_LIST); | 660 entry.setValue(result, 111, TargetedResult.EMPTY_LIST); |
653 expect(entry.getState(result), CacheState.VALID); | 661 expect(entry.getState(result), CacheState.VALID); |
654 expect(entry.getValue(result), 111); | 662 expect(entry.getValue(result), 111); |
655 // invalidate result, keep entry | 663 // invalidate result, keep entry |
656 entry.setState(result, CacheState.INVALID); | 664 entry.setState(result, CacheState.INVALID); |
657 expect(cache.get(target), isNotNull); | 665 expect(cache.get(target), isNotNull); |
658 } | 666 } |
659 | 667 |
660 test_setState_invalid_removeEmptyEntry() { | 668 test_setState_invalid_removeEmptyEntry() { |
661 AnalysisTarget target1 = new TestSource('/a.dart'); | 669 AnalysisTarget target1 = new TestSource('/a.dart'); |
662 AnalysisTarget target2 = new TestSource('/b.dart'); | 670 AnalysisTarget target2 = new TestSource('/b.dart'); |
663 CacheEntry entry1 = new CacheEntry(target1); | 671 CacheEntry entry1 = new CacheEntry(target1); |
664 CacheEntry entry2 = new CacheEntry(target2); | 672 CacheEntry entry2 = new CacheEntry(target2); |
665 cache.put(entry1); | 673 cache.put(entry1); |
666 cache.put(entry2); | 674 cache.put(entry2); |
667 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 675 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
668 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 676 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
669 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 677 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
670 // set results, all of them are VALID | 678 // set results, all of them are VALID |
671 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 679 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
672 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 680 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
673 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); | 681 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); |
674 expect(entry1.getState(result1), CacheState.VALID); | 682 expect(entry1.getState(result1), CacheState.VALID); |
675 expect(entry2.getState(result2), CacheState.VALID); | 683 expect(entry2.getState(result2), CacheState.VALID); |
676 expect(entry2.getState(result3), CacheState.VALID); | 684 expect(entry2.getState(result3), CacheState.VALID); |
677 expect(entry1.getValue(result1), 111); | 685 expect(entry1.getValue(result1), 111); |
678 expect(entry2.getValue(result2), 222); | 686 expect(entry2.getValue(result2), 222); |
679 expect(entry2.getValue(result3), 333); | 687 expect(entry2.getValue(result3), 333); |
680 // invalidate result1, remove entry1 & entry2 | 688 // invalidate result1, remove entry1 & entry2 |
681 entry1.setState(result1, CacheState.INVALID); | 689 entry1.setState(result1, CacheState.INVALID); |
682 expect(cache.get(target1), isNull); | 690 expect(cache.get(target1), isNull); |
683 expect(cache.get(target2), isNull); | 691 expect(cache.get(target2), isNull); |
684 } | 692 } |
685 | 693 |
686 test_setState_invalid_withDelta_keepDependency() { | 694 test_setState_invalid_withDelta_keepDependency() { |
687 Source target = new TestSource('/test.dart'); | 695 Source target = new TestSource('/test.dart'); |
688 CacheEntry entry = new CacheEntry(target); | 696 CacheEntry entry = new CacheEntry(target); |
689 cache.put(entry); | 697 cache.put(entry); |
690 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 698 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
691 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 699 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
692 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 700 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
693 // set results, all of them are VALID | 701 // set results, all of them are VALID |
694 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 702 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
695 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 703 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
696 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 704 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
697 expect(entry.getState(result1), CacheState.VALID); | 705 expect(entry.getState(result1), CacheState.VALID); |
698 expect(entry.getState(result2), CacheState.VALID); | 706 expect(entry.getState(result2), CacheState.VALID); |
699 expect(entry.getState(result3), CacheState.VALID); | 707 expect(entry.getState(result3), CacheState.VALID); |
700 // result2 depends on result1 | 708 // result2 depends on result1 |
701 expect(entry.getResultData(result1).dependentResults, | 709 expect(entry.getResultData(result1).dependentResults, |
702 unorderedEquals([new TargetedResult(target, result2)])); | 710 unorderedEquals([new TargetedResult(target, result2)])); |
(...skipping 24 matching lines...) Expand all Loading... | |
727 | 735 |
728 test_setState_valid() { | 736 test_setState_valid() { |
729 AnalysisTarget target = new TestSource(); | 737 AnalysisTarget target = new TestSource(); |
730 ResultDescriptor result = new ResultDescriptor('test', null); | 738 ResultDescriptor result = new ResultDescriptor('test', null); |
731 CacheEntry entry = new CacheEntry(target); | 739 CacheEntry entry = new CacheEntry(target); |
732 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 740 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
733 } | 741 } |
734 | 742 |
735 test_setValue() { | 743 test_setValue() { |
736 AnalysisTarget target = new TestSource(); | 744 AnalysisTarget target = new TestSource(); |
737 ResultDescriptor result = new ResultDescriptor('test', null); | 745 ResultDescriptor<String> result = |
746 new ResultDescriptor<String>('test', null); | |
738 String value = 'value'; | 747 String value = 'value'; |
739 CacheEntry entry = new CacheEntry(target); | 748 CacheEntry entry = new CacheEntry(target); |
740 cache.put(entry); | 749 cache.put(entry); |
741 entry.setValue(result, value, TargetedResult.EMPTY_LIST); | 750 entry.setValue(result, value, TargetedResult.EMPTY_LIST); |
742 expect(entry.getState(result), CacheState.VALID); | 751 expect(entry.getState(result), CacheState.VALID); |
743 expect(entry.getValue(result), value); | 752 expect(entry.getValue(result), value); |
744 } | 753 } |
745 | 754 |
746 test_setValue_flushResults() { | 755 test_setValue_flushResults() { |
747 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 756 ResultCachingPolicy<int> cachingPolicy = |
748 ResultDescriptor descriptor1 = | 757 new SimpleResultCachingPolicy<int>(2, 2); |
749 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); | 758 ResultDescriptor<int> descriptor1 = new ResultDescriptor<int>( |
750 ResultDescriptor descriptor2 = | 759 'result1', null, |
751 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); | 760 cachingPolicy: cachingPolicy); |
752 ResultDescriptor descriptor3 = | 761 ResultDescriptor<int> descriptor2 = new ResultDescriptor<int>( |
753 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); | 762 'result2', null, |
763 cachingPolicy: cachingPolicy); | |
764 ResultDescriptor<int> descriptor3 = new ResultDescriptor<int>( | |
765 'result3', null, | |
766 cachingPolicy: cachingPolicy); | |
754 AnalysisTarget target = new TestSource(); | 767 AnalysisTarget target = new TestSource(); |
755 CacheEntry entry = new CacheEntry(target); | 768 CacheEntry entry = new CacheEntry(target); |
756 cache.put(entry); | 769 cache.put(entry); |
757 { | 770 { |
758 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 771 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
759 expect(entry.getState(descriptor1), CacheState.VALID); | 772 expect(entry.getState(descriptor1), CacheState.VALID); |
760 } | 773 } |
761 { | 774 { |
762 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); | 775 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); |
763 expect(entry.getState(descriptor1), CacheState.VALID); | 776 expect(entry.getState(descriptor1), CacheState.VALID); |
764 expect(entry.getState(descriptor2), CacheState.VALID); | 777 expect(entry.getState(descriptor2), CacheState.VALID); |
765 } | 778 } |
766 { | 779 { |
767 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); | 780 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); |
768 expect(entry.getState(descriptor1), CacheState.FLUSHED); | 781 expect(entry.getState(descriptor1), CacheState.FLUSHED); |
769 expect(entry.getState(descriptor2), CacheState.VALID); | 782 expect(entry.getState(descriptor2), CacheState.VALID); |
770 expect(entry.getState(descriptor3), CacheState.VALID); | 783 expect(entry.getState(descriptor3), CacheState.VALID); |
771 } | 784 } |
772 } | 785 } |
773 | 786 |
774 test_setValue_flushResults_keepForPrioritySources() { | 787 test_setValue_flushResults_keepForPrioritySources() { |
775 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 788 ResultCachingPolicy<int> cachingPolicy = |
776 ResultDescriptor newResult(String name) => | 789 new SimpleResultCachingPolicy<int>(2, 2); |
777 new ResultDescriptor(name, null, cachingPolicy: cachingPolicy); | 790 ResultDescriptor<int> newResult(String name) => |
778 ResultDescriptor descriptor1 = newResult('result1'); | 791 new ResultDescriptor<int>(name, null, cachingPolicy: cachingPolicy); |
779 ResultDescriptor descriptor2 = newResult('result2'); | 792 ResultDescriptor<int> descriptor1 = newResult('result1'); |
780 ResultDescriptor descriptor3 = newResult('result3'); | 793 ResultDescriptor<int> descriptor2 = newResult('result2'); |
794 ResultDescriptor<int> descriptor3 = newResult('result3'); | |
781 TestSource source1 = new TestSource('/a.dart'); | 795 TestSource source1 = new TestSource('/a.dart'); |
782 TestSource source2 = new TestSource('/b.dart'); | 796 TestSource source2 = new TestSource('/b.dart'); |
783 TestSource source3 = new TestSource('/c.dart'); | 797 TestSource source3 = new TestSource('/c.dart'); |
784 AnalysisTarget target1 = | 798 AnalysisTarget target1 = |
785 new _TestAnalysisTarget(librarySource: source1, source: source1); | 799 new _TestAnalysisTarget(librarySource: source1, source: source1); |
786 AnalysisTarget target2 = | 800 AnalysisTarget target2 = |
787 new _TestAnalysisTarget(librarySource: source2, source: source2); | 801 new _TestAnalysisTarget(librarySource: source2, source: source2); |
788 AnalysisTarget target3 = | 802 AnalysisTarget target3 = |
789 new _TestAnalysisTarget(librarySource: source3, source: source3); | 803 new _TestAnalysisTarget(librarySource: source3, source: source3); |
790 CacheEntry entry1 = new CacheEntry(target1); | 804 CacheEntry entry1 = new CacheEntry(target1); |
(...skipping 14 matching lines...) Expand all Loading... | |
805 entry3.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); | 819 entry3.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); |
806 expect(entry1.getState(descriptor1), CacheState.VALID); | 820 expect(entry1.getState(descriptor1), CacheState.VALID); |
807 expect(entry2.getState(descriptor2), CacheState.FLUSHED); | 821 expect(entry2.getState(descriptor2), CacheState.FLUSHED); |
808 expect(entry3.getState(descriptor3), CacheState.VALID); | 822 expect(entry3.getState(descriptor3), CacheState.VALID); |
809 } | 823 } |
810 | 824 |
811 test_setValue_keepDependent() { | 825 test_setValue_keepDependent() { |
812 AnalysisTarget target = new TestSource(); | 826 AnalysisTarget target = new TestSource(); |
813 CacheEntry entry = new CacheEntry(target); | 827 CacheEntry entry = new CacheEntry(target); |
814 cache.put(entry); | 828 cache.put(entry); |
815 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 829 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
816 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 830 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
817 // set results, all of them are VALID | 831 // set results, all of them are VALID |
818 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 832 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
819 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 833 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
820 expect(entry.getState(result1), CacheState.VALID); | 834 expect(entry.getState(result1), CacheState.VALID); |
821 expect(entry.getState(result2), CacheState.VALID); | 835 expect(entry.getState(result2), CacheState.VALID); |
822 expect(entry.getValue(result1), 111); | 836 expect(entry.getValue(result1), 111); |
823 expect(entry.getValue(result2), 222); | 837 expect(entry.getValue(result2), 222); |
824 // set result1; result2 is intact | 838 // set result1; result2 is intact |
825 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST); | 839 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST); |
826 expect(entry.getState(result1), CacheState.VALID); | 840 expect(entry.getState(result1), CacheState.VALID); |
827 expect(entry.getState(result2), CacheState.VALID); | 841 expect(entry.getState(result2), CacheState.VALID); |
828 expect(entry.getValue(result1), 1111); | 842 expect(entry.getValue(result1), 1111); |
829 expect(entry.getValue(result2), 222); | 843 expect(entry.getValue(result2), 222); |
830 } | 844 } |
831 | 845 |
832 test_setValue_userBeforeProvider_invalidateProvider_alsoUser() { | 846 test_setValue_userBeforeProvider_invalidateProvider_alsoUser() { |
833 AnalysisTarget target1 = new TestSource('/a.dart'); | 847 AnalysisTarget target1 = new TestSource('/a.dart'); |
834 AnalysisTarget target2 = new TestSource('/b.dart'); | 848 AnalysisTarget target2 = new TestSource('/b.dart'); |
835 CacheEntry entry1 = new CacheEntry(target1); | 849 CacheEntry entry1 = new CacheEntry(target1); |
836 CacheEntry entry2 = new CacheEntry(target2); | 850 CacheEntry entry2 = new CacheEntry(target2); |
837 cache.put(entry1); | 851 cache.put(entry1); |
838 cache.put(entry2); | 852 cache.put(entry2); |
839 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 853 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
840 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 854 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
841 // set results, all of them are VALID | 855 // set results, all of them are VALID |
842 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 856 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
843 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 857 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
844 expect(entry1.getState(result1), CacheState.VALID); | 858 expect(entry1.getState(result1), CacheState.VALID); |
845 expect(entry2.getState(result2), CacheState.VALID); | 859 expect(entry2.getState(result2), CacheState.VALID); |
846 expect(entry1.getValue(result1), 111); | 860 expect(entry1.getValue(result1), 111); |
847 expect(entry2.getValue(result2), 222); | 861 expect(entry2.getValue(result2), 222); |
848 // invalidate result1, should invalidate also result2 | 862 // invalidate result1, should invalidate also result2 |
849 entry1.setState(result1, CacheState.INVALID); | 863 entry1.setState(result1, CacheState.INVALID); |
850 expect(entry1.getState(result1), CacheState.INVALID); | 864 expect(entry1.getState(result1), CacheState.INVALID); |
851 expect(entry2.getState(result2), CacheState.INVALID); | 865 expect(entry2.getState(result2), CacheState.INVALID); |
852 } | 866 } |
853 | 867 |
854 test_setValueIncremental() { | 868 test_setValueIncremental() { |
855 AnalysisTarget target = new TestSource(); | 869 AnalysisTarget target = new TestSource(); |
856 CacheEntry entry = new CacheEntry(target); | 870 CacheEntry entry = new CacheEntry(target); |
857 cache.put(entry); | 871 cache.put(entry); |
858 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 872 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
859 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 873 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
860 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 874 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
861 // set results, all of them are VALID | 875 // set results, all of them are VALID |
862 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 876 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
863 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 877 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
864 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 878 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
865 expect(entry.getState(result1), CacheState.VALID); | 879 expect(entry.getState(result1), CacheState.VALID); |
866 expect(entry.getState(result2), CacheState.VALID); | 880 expect(entry.getState(result2), CacheState.VALID); |
867 expect(entry.getState(result3), CacheState.VALID); | 881 expect(entry.getState(result3), CacheState.VALID); |
868 expect(entry.getValue(result1), 111); | 882 expect(entry.getValue(result1), 111); |
869 expect(entry.getValue(result2), 222); | 883 expect(entry.getValue(result2), 222); |
870 expect(entry.getValue(result3), 333); | 884 expect(entry.getValue(result3), 333); |
(...skipping 12 matching lines...) Expand all Loading... | |
883 } | 897 } |
884 | 898 |
885 test_toString_empty() { | 899 test_toString_empty() { |
886 AnalysisTarget target = new TestSource(); | 900 AnalysisTarget target = new TestSource(); |
887 CacheEntry entry = new CacheEntry(target); | 901 CacheEntry entry = new CacheEntry(target); |
888 expect(entry.toString(), isNotNull); | 902 expect(entry.toString(), isNotNull); |
889 } | 903 } |
890 | 904 |
891 test_toString_nonEmpty() { | 905 test_toString_nonEmpty() { |
892 AnalysisTarget target = new TestSource(); | 906 AnalysisTarget target = new TestSource(); |
893 ResultDescriptor result = new ResultDescriptor('test', null); | 907 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
894 CacheEntry entry = new CacheEntry(target); | 908 CacheEntry entry = new CacheEntry(target); |
895 cache.put(entry); | 909 cache.put(entry); |
896 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 910 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
897 expect(entry.toString(), isNotNull); | 911 expect(entry.toString(), isNotNull); |
898 } | 912 } |
899 } | 913 } |
900 | 914 |
901 @reflectiveTest | 915 @reflectiveTest |
902 class CacheFlushManagerTest { | 916 class CacheFlushManagerTest { |
903 CacheFlushManager manager = new CacheFlushManager( | 917 CacheFlushManager manager = new CacheFlushManager( |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 } | 1253 } |
1240 | 1254 |
1241 test_dispose() { | 1255 test_dispose() { |
1242 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 1256 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
1243 CachePartition partition1 = new UniversalCachePartition(context); | 1257 CachePartition partition1 = new UniversalCachePartition(context); |
1244 CachePartition partition2 = new UniversalCachePartition(context); | 1258 CachePartition partition2 = new UniversalCachePartition(context); |
1245 AnalysisCache cache = new AnalysisCache([partition1, partition2]); | 1259 AnalysisCache cache = new AnalysisCache([partition1, partition2]); |
1246 when(context.analysisCache).thenReturn(cache); | 1260 when(context.analysisCache).thenReturn(cache); |
1247 // configure | 1261 // configure |
1248 // prepare entries | 1262 // prepare entries |
1249 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); | 1263 ResultDescriptor<int> descriptor1 = |
1250 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); | 1264 new ResultDescriptor<int>('result1', -1); |
1265 ResultDescriptor<int> descriptor2 = | |
1266 new ResultDescriptor<int>('result2', -2); | |
1251 AnalysisTarget target1 = new TestSource('1.dart'); | 1267 AnalysisTarget target1 = new TestSource('1.dart'); |
1252 AnalysisTarget target2 = new TestSource('2.dart'); | 1268 AnalysisTarget target2 = new TestSource('2.dart'); |
1253 TargetedResult result1 = new TargetedResult(target1, descriptor1); | 1269 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
1254 TargetedResult result2 = new TargetedResult(target2, descriptor2); | 1270 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
1255 CacheEntry entry1 = new CacheEntry(target1); | 1271 CacheEntry entry1 = new CacheEntry(target1); |
1256 CacheEntry entry2 = new CacheEntry(target2); | 1272 CacheEntry entry2 = new CacheEntry(target2); |
1257 partition1.put(entry1); | 1273 partition1.put(entry1); |
1258 partition2.put(entry2); | 1274 partition2.put(entry2); |
1259 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 1275 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
1260 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); | 1276 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 } | 1318 } |
1303 return DeltaResult.INVALIDATE; | 1319 return DeltaResult.INVALIDATE; |
1304 } | 1320 } |
1305 } | 1321 } |
1306 | 1322 |
1307 class _TestAnalysisTarget implements AnalysisTarget { | 1323 class _TestAnalysisTarget implements AnalysisTarget { |
1308 final Source librarySource; | 1324 final Source librarySource; |
1309 final Source source; | 1325 final Source source; |
1310 _TestAnalysisTarget({this.librarySource, this.source}); | 1326 _TestAnalysisTarget({this.librarySource, this.source}); |
1311 } | 1327 } |
OLD | NEW |