| 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 test.src.task.driver_test; | 5 library analyzer.test.src.context.cache_test; |
| 6 | 6 |
| 7 import 'package:analyzer/exception/exception.dart'; |
| 8 import 'package:analyzer/file_system/file_system.dart'; |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 11 import 'package:analyzer/source/package_map_resolver.dart'; |
| 7 import 'package:analyzer/src/context/cache.dart'; | 12 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' | 13 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 9 show | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 10 AnalysisContext, | |
| 11 CacheState, | |
| 12 InternalAnalysisContext, | |
| 13 RetentionPriority; | |
| 14 import 'package:analyzer/src/generated/java_engine.dart'; | |
| 15 import 'package:analyzer/src/generated/sdk_io.dart'; | |
| 16 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/utilities_collection.dart'; | 16 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 18 import 'package:analyzer/src/task/model.dart'; | 17 import 'package:analyzer/src/task/model.dart'; |
| 19 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
| 19 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 20 import 'package:typed_mock/typed_mock.dart'; | 20 import 'package:typed_mock/typed_mock.dart'; |
| 21 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 22 | 22 |
| 23 import '../../generated/test_support.dart'; | 23 import '../../generated/test_support.dart'; |
| 24 import '../../reflective_tests.dart'; | |
| 25 import '../../utils.dart'; | 24 import '../../utils.dart'; |
| 26 | 25 |
| 27 main() { | 26 main() { |
| 28 initializeTestEnvironment(); | 27 initializeTestEnvironment(); |
| 29 runReflectiveTests(AnalysisCacheTest); | 28 defineReflectiveTests(AnalysisCacheTest); |
| 30 runReflectiveTests(CacheEntryTest); | 29 defineReflectiveTests(CacheEntryTest); |
| 31 runReflectiveTests(CacheFlushManagerTest); | 30 defineReflectiveTests(CacheFlushManagerTest); |
| 32 runReflectiveTests(SdkCachePartitionTest); | 31 defineReflectiveTests(SdkCachePartitionTest); |
| 33 runReflectiveTests(UniversalCachePartitionTest); | 32 defineReflectiveTests(UniversalCachePartitionTest); |
| 34 runReflectiveTests(ResultDataTest); | 33 defineReflectiveTests(ResultDataTest); |
| 35 } | 34 } |
| 36 | 35 |
| 37 AnalysisCache createCache( | 36 AnalysisCache createCache({AnalysisContext context}) { |
| 38 {AnalysisContext context, | |
| 39 RetentionPriority policy: RetentionPriority.LOW}) { | |
| 40 CachePartition partition = new UniversalCachePartition(context); | 37 CachePartition partition = new UniversalCachePartition(context); |
| 41 return new AnalysisCache(<CachePartition>[partition]); | 38 return new AnalysisCache(<CachePartition>[partition]); |
| 42 } | 39 } |
| 43 | 40 |
| 44 class AbstractCacheTest { | 41 class AbstractCacheTest { |
| 45 InternalAnalysisContext context; | 42 InternalAnalysisContext context; |
| 46 AnalysisCache cache; | 43 AnalysisCache cache; |
| 47 | 44 |
| 48 void setUp() { | 45 void setUp() { |
| 49 context = new _InternalAnalysisContextMock(); | 46 context = new _InternalAnalysisContextMock(); |
| 50 when(context.priorityTargets).thenReturn([]); | 47 when(context.prioritySources).thenReturn([]); |
| 51 cache = createCache(context: context); | 48 cache = createCache(context: context); |
| 52 when(context.analysisCache).thenReturn(cache); | 49 when(context.analysisCache).thenReturn(cache); |
| 53 } | 50 } |
| 54 } | 51 } |
| 55 | 52 |
| 56 @reflectiveTest | 53 @reflectiveTest |
| 57 class AnalysisCacheTest extends AbstractCacheTest { | 54 class AnalysisCacheTest extends AbstractCacheTest { |
| 58 void test_creation() { | 55 void test_creation() { |
| 59 expect(cache, isNotNull); | 56 expect(cache, isNotNull); |
| 60 } | 57 } |
| 61 | 58 |
| 59 test_flush() { |
| 60 AnalysisTarget target = new TestSource(); |
| 61 ResultDescriptor<String> resultA = new ResultDescriptor<String>('A', null); |
| 62 ResultDescriptor<String> resultB = new ResultDescriptor<String>('B', null); |
| 63 CacheEntry entry = new CacheEntry(target); |
| 64 cache.put(entry); |
| 65 // put values |
| 66 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); |
| 67 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); |
| 68 expect(cache.getState(target, resultA), CacheState.VALID); |
| 69 expect(cache.getState(target, resultB), CacheState.VALID); |
| 70 expect(cache.getValue(target, resultA), 'a'); |
| 71 expect(cache.getValue(target, resultB), 'b'); |
| 72 // flush A |
| 73 cache.flush((target, result) => result == resultA); |
| 74 expect(cache.getState(target, resultA), CacheState.FLUSHED); |
| 75 expect(cache.getState(target, resultB), CacheState.VALID); |
| 76 expect(cache.getValue(target, resultA), isNull); |
| 77 expect(cache.getValue(target, resultB), 'b'); |
| 78 } |
| 79 |
| 62 void test_get() { | 80 void test_get() { |
| 63 AnalysisTarget target = new TestSource(); | 81 AnalysisTarget target = new TestSource(); |
| 64 expect(cache.get(target), isNull); | 82 expect(cache.get(target), isNull); |
| 65 } | 83 } |
| 66 | 84 |
| 67 void test_getContextFor() { | 85 void test_getContextFor() { |
| 68 AnalysisTarget target = new TestSource(); | 86 AnalysisTarget target = new TestSource(); |
| 69 expect(cache.getContextFor(target), context); | 87 expect(cache.getContextFor(target), context); |
| 70 } | 88 } |
| 71 | 89 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 99 void test_getState_hasEntry_flushed() { | 117 void test_getState_hasEntry_flushed() { |
| 100 ResultDescriptor result = new ResultDescriptor('result', -1); | 118 ResultDescriptor result = new ResultDescriptor('result', -1); |
| 101 AnalysisTarget target = new TestSource(); | 119 AnalysisTarget target = new TestSource(); |
| 102 CacheEntry entry = new CacheEntry(target); | 120 CacheEntry entry = new CacheEntry(target); |
| 103 cache.put(entry); | 121 cache.put(entry); |
| 104 entry.setState(result, CacheState.FLUSHED); | 122 entry.setState(result, CacheState.FLUSHED); |
| 105 expect(cache.getState(target, result), CacheState.FLUSHED); | 123 expect(cache.getState(target, result), CacheState.FLUSHED); |
| 106 } | 124 } |
| 107 | 125 |
| 108 void test_getState_hasEntry_valid() { | 126 void test_getState_hasEntry_valid() { |
| 109 ResultDescriptor result = new ResultDescriptor('result', -1); | 127 ResultDescriptor<String> result = |
| 128 new ResultDescriptor<String>('result', null); |
| 110 AnalysisTarget target = new TestSource(); | 129 AnalysisTarget target = new TestSource(); |
| 111 CacheEntry entry = new CacheEntry(target); | 130 CacheEntry entry = new CacheEntry(target); |
| 112 cache.put(entry); | 131 cache.put(entry); |
| 113 entry.setValue(result, '', []); | 132 entry.setValue(result, '', []); |
| 114 expect(cache.getState(target, result), CacheState.VALID); | 133 expect(cache.getState(target, result), CacheState.VALID); |
| 115 } | 134 } |
| 116 | 135 |
| 117 void test_getState_noEntry() { | 136 void test_getState_noEntry() { |
| 118 ResultDescriptor result = new ResultDescriptor('result', -1); | 137 ResultDescriptor result = new ResultDescriptor('result', -1); |
| 119 AnalysisTarget target = new TestSource(); | 138 AnalysisTarget target = new TestSource(); |
| 120 expect(cache.getState(target, result), CacheState.INVALID); | 139 expect(cache.getState(target, result), CacheState.INVALID); |
| 121 } | 140 } |
| 122 | 141 |
| 123 void test_getValue_hasEntry_valid() { | 142 void test_getValue_hasEntry_valid() { |
| 124 ResultDescriptor result = new ResultDescriptor('result', -1); | 143 ResultDescriptor<int> result = new ResultDescriptor<int>('result', -1); |
| 125 AnalysisTarget target = new TestSource(); | 144 AnalysisTarget target = new TestSource(); |
| 126 CacheEntry entry = new CacheEntry(target); | 145 CacheEntry entry = new CacheEntry(target); |
| 127 cache.put(entry); | 146 cache.put(entry); |
| 128 entry.setValue(result, 111, []); | 147 entry.setValue(result, 111, []); |
| 129 expect(cache.getValue(target, result), 111); | 148 expect(cache.getValue(target, result), 111); |
| 130 } | 149 } |
| 131 | 150 |
| 132 void test_getValue_noEntry() { | 151 void test_getValue_noEntry() { |
| 133 ResultDescriptor result = new ResultDescriptor('result', -1); | 152 ResultDescriptor result = new ResultDescriptor('result', -1); |
| 134 AnalysisTarget target = new TestSource(); | 153 AnalysisTarget target = new TestSource(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 157 void test_remove() { | 176 void test_remove() { |
| 158 AnalysisTarget target1 = new TestSource('/a.dart'); | 177 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 159 AnalysisTarget target2 = new TestSource('/b.dart'); | 178 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 160 AnalysisTarget target3 = new TestSource('/c.dart'); | 179 AnalysisTarget target3 = new TestSource('/c.dart'); |
| 161 CacheEntry entry1 = new CacheEntry(target1); | 180 CacheEntry entry1 = new CacheEntry(target1); |
| 162 CacheEntry entry2 = new CacheEntry(target2); | 181 CacheEntry entry2 = new CacheEntry(target2); |
| 163 CacheEntry entry3 = new CacheEntry(target3); | 182 CacheEntry entry3 = new CacheEntry(target3); |
| 164 cache.put(entry1); | 183 cache.put(entry1); |
| 165 cache.put(entry2); | 184 cache.put(entry2); |
| 166 cache.put(entry3); | 185 cache.put(entry3); |
| 167 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 186 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 168 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 187 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 169 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 188 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 170 // set results, all of them are VALID | 189 // set results, all of them are VALID |
| 171 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 190 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 172 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 191 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
| 173 entry3.setValue(result3, 333, []); | 192 entry3.setValue(result3, 333, []); |
| 174 expect(entry1.getState(result1), CacheState.VALID); | 193 expect(entry1.getState(result1), CacheState.VALID); |
| 175 expect(entry2.getState(result2), CacheState.VALID); | 194 expect(entry2.getState(result2), CacheState.VALID); |
| 176 expect(entry3.getState(result3), CacheState.VALID); | 195 expect(entry3.getState(result3), CacheState.VALID); |
| 177 expect(entry1.getValue(result1), 111); | 196 expect(entry1.getValue(result1), 111); |
| 178 expect(entry2.getValue(result2), 222); | 197 expect(entry2.getValue(result2), 222); |
| 179 expect(entry3.getValue(result3), 333); | 198 expect(entry3.getValue(result3), 333); |
| 180 // remove entry1, invalidate result2 and remove empty entry2 | 199 // remove entry1, invalidate result2 and remove empty entry2 |
| 181 expect(cache.remove(target1), entry1); | 200 expect(cache.remove(target1), entry1); |
| 182 expect(cache.get(target1), isNull); | 201 expect(cache.get(target1), isNull); |
| 183 expect(cache.get(target2), isNull); | 202 expect(cache.get(target2), isNull); |
| 184 expect(cache.get(target3), entry3); | 203 expect(cache.get(target3), entry3); |
| 185 expect(entry3.getState(result3), CacheState.VALID); | 204 expect(entry3.getState(result3), CacheState.VALID); |
| 186 } | 205 } |
| 187 | 206 |
| 188 void test_remove_invalidateResults_sameTarget() { | 207 void test_remove_invalidateResults_sameTarget() { |
| 189 AnalysisTarget target = new TestSource('/a.dart'); | 208 AnalysisTarget target = new TestSource('/a.dart'); |
| 190 CacheEntry entry = new CacheEntry(target); | 209 CacheEntry entry = new CacheEntry(target); |
| 191 cache.put(entry); | 210 cache.put(entry); |
| 192 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 211 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 193 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 212 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 194 // set results, all of them are VALID | 213 // set results, all of them are VALID |
| 195 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 214 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 196 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 215 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 197 expect(entry.getState(result1), CacheState.VALID); | 216 expect(entry.getState(result1), CacheState.VALID); |
| 198 expect(entry.getState(result2), CacheState.VALID); | 217 expect(entry.getState(result2), CacheState.VALID); |
| 199 expect(entry.getValue(result1), 111); | 218 expect(entry.getValue(result1), 111); |
| 200 expect(entry.getValue(result2), 222); | 219 expect(entry.getValue(result2), 222); |
| 201 // remove target, invalidate result2 | 220 // remove target, invalidate result2 |
| 202 expect(cache.remove(target), entry); | 221 expect(cache.remove(target), entry); |
| 203 expect(cache.get(target), isNull); | 222 expect(cache.get(target), isNull); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 233 expect(cache.sources, unorderedEquals([source2])); | 252 expect(cache.sources, unorderedEquals([source2])); |
| 234 // remove source2 | 253 // remove source2 |
| 235 cache.remove(source2); | 254 cache.remove(source2); |
| 236 expect(cache.sources, isEmpty); | 255 expect(cache.sources, isEmpty); |
| 237 } | 256 } |
| 238 } | 257 } |
| 239 | 258 |
| 240 @reflectiveTest | 259 @reflectiveTest |
| 241 class CacheEntryTest extends AbstractCacheTest { | 260 class CacheEntryTest extends AbstractCacheTest { |
| 242 test_dispose() { | 261 test_dispose() { |
| 243 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); | 262 ResultDescriptor<int> descriptor1 = |
| 244 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); | 263 new ResultDescriptor<int>('result1', -1); |
| 264 ResultDescriptor<int> descriptor2 = |
| 265 new ResultDescriptor<int>('result2', -2); |
| 245 AnalysisTarget target1 = new TestSource('1.dart'); | 266 AnalysisTarget target1 = new TestSource('1.dart'); |
| 246 AnalysisTarget target2 = new TestSource('2.dart'); | 267 AnalysisTarget target2 = new TestSource('2.dart'); |
| 247 TargetedResult result1 = new TargetedResult(target1, descriptor1); | 268 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
| 248 TargetedResult result2 = new TargetedResult(target2, descriptor2); | 269 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
| 249 CacheEntry entry1 = new CacheEntry(target1); | 270 CacheEntry entry1 = new CacheEntry(target1); |
| 250 CacheEntry entry2 = new CacheEntry(target2); | 271 CacheEntry entry2 = new CacheEntry(target2); |
| 251 cache.put(entry1); | 272 cache.put(entry1); |
| 252 cache.put(entry2); | 273 cache.put(entry2); |
| 253 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 274 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 254 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); | 275 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 expect(entry.explicitlyAdded, false); | 287 expect(entry.explicitlyAdded, false); |
| 267 entry.explicitlyAdded = true; | 288 entry.explicitlyAdded = true; |
| 268 expect(entry.explicitlyAdded, true); | 289 expect(entry.explicitlyAdded, true); |
| 269 } | 290 } |
| 270 | 291 |
| 271 test_fixExceptionState_error_exception() { | 292 test_fixExceptionState_error_exception() { |
| 272 AnalysisTarget target = new TestSource(); | 293 AnalysisTarget target = new TestSource(); |
| 273 ResultDescriptor result = new ResultDescriptor('test', null); | 294 ResultDescriptor result = new ResultDescriptor('test', null); |
| 274 CaughtException exception = new CaughtException(null, null); | 295 CaughtException exception = new CaughtException(null, null); |
| 275 CacheEntry entry = new CacheEntry(target); | 296 CacheEntry entry = new CacheEntry(target); |
| 297 cache.put(entry); |
| 276 entry.setErrorState(exception, <ResultDescriptor>[result]); | 298 entry.setErrorState(exception, <ResultDescriptor>[result]); |
| 277 entry.fixExceptionState(); | 299 entry.fixExceptionState(); |
| 278 expect(entry.getState(result), CacheState.ERROR); | 300 expect(entry.getState(result), CacheState.ERROR); |
| 279 expect(entry.exception, exception); | 301 expect(entry.exception, exception); |
| 280 } | 302 } |
| 281 | 303 |
| 282 test_fixExceptionState_noError_exception() { | 304 test_fixExceptionState_noError_exception() { |
| 283 AnalysisTarget target = new TestSource(); | 305 AnalysisTarget target = new TestSource(); |
| 284 ResultDescriptor result = new ResultDescriptor('test', null); | 306 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
| 285 CacheEntry entry = new CacheEntry(target); | 307 CacheEntry entry = new CacheEntry(target); |
| 286 cache.put(entry); | 308 cache.put(entry); |
| 287 // set one result to ERROR | 309 // set one result to ERROR |
| 288 CaughtException exception = new CaughtException(null, null); | 310 CaughtException exception = new CaughtException(null, null); |
| 289 entry.setErrorState(exception, <ResultDescriptor>[result]); | 311 entry.setErrorState(exception, <ResultDescriptor>[result]); |
| 290 // set the same result to VALID | 312 // set the same result to VALID |
| 291 entry.setValue(result, 1, TargetedResult.EMPTY_LIST); | 313 entry.setValue(result, 1, TargetedResult.EMPTY_LIST); |
| 292 // fix the exception state | 314 // fix the exception state |
| 293 entry.fixExceptionState(); | 315 entry.fixExceptionState(); |
| 294 expect(entry.exception, isNull); | 316 expect(entry.exception, isNull); |
| 295 } | 317 } |
| 296 | 318 |
| 297 test_fixExceptionState_noError_noException() { | 319 test_fixExceptionState_noError_noException() { |
| 298 AnalysisTarget target = new TestSource(); | 320 AnalysisTarget target = new TestSource(); |
| 299 ResultDescriptor result = new ResultDescriptor('test', null); | 321 ResultDescriptor result = new ResultDescriptor('test', null); |
| 300 CacheEntry entry = new CacheEntry(target); | 322 CacheEntry entry = new CacheEntry(target); |
| 301 entry.fixExceptionState(); | 323 entry.fixExceptionState(); |
| 302 expect(entry.getState(result), CacheState.INVALID); | 324 expect(entry.getState(result), CacheState.INVALID); |
| 303 expect(entry.exception, isNull); | 325 expect(entry.exception, isNull); |
| 304 } | 326 } |
| 305 | 327 |
| 328 test_flush() { |
| 329 AnalysisTarget target = new TestSource(); |
| 330 ResultDescriptor<String> resultA = new ResultDescriptor<String>('A', null); |
| 331 ResultDescriptor<String> resultB = new ResultDescriptor<String>('B', null); |
| 332 CacheEntry entry = new CacheEntry(target); |
| 333 cache.put(entry); |
| 334 // put values |
| 335 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST); |
| 336 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST); |
| 337 expect(entry.getState(resultA), CacheState.VALID); |
| 338 expect(entry.getState(resultB), CacheState.VALID); |
| 339 expect(entry.getValue(resultA), 'a'); |
| 340 expect(entry.getValue(resultB), 'b'); |
| 341 // flush A |
| 342 entry.flush((target, result) => result == resultA); |
| 343 expect(entry.getState(resultA), CacheState.FLUSHED); |
| 344 expect(entry.getState(resultB), CacheState.VALID); |
| 345 expect(entry.getValue(resultA), isNull); |
| 346 expect(entry.getValue(resultB), 'b'); |
| 347 } |
| 348 |
| 306 test_getState() { | 349 test_getState() { |
| 307 AnalysisTarget target = new TestSource(); | 350 AnalysisTarget target = new TestSource(); |
| 308 ResultDescriptor result = new ResultDescriptor('test', null); | 351 ResultDescriptor result = new ResultDescriptor('test', null); |
| 309 CacheEntry entry = new CacheEntry(target); | 352 CacheEntry entry = new CacheEntry(target); |
| 310 expect(entry.getState(result), CacheState.INVALID); | 353 expect(entry.getState(result), CacheState.INVALID); |
| 311 } | 354 } |
| 312 | 355 |
| 313 test_getValue_default() { | 356 test_getValue_default() { |
| 314 AnalysisTarget target = new TestSource(); | 357 AnalysisTarget target = new TestSource(); |
| 315 String defaultValue = 'value'; | 358 String defaultValue = 'value'; |
| 316 ResultDescriptor result = new ResultDescriptor('test', defaultValue); | 359 ResultDescriptor result = new ResultDescriptor('test', defaultValue); |
| 317 CacheEntry entry = new CacheEntry(target); | 360 CacheEntry entry = new CacheEntry(target); |
| 318 expect(entry.getValue(result), defaultValue); | 361 expect(entry.getValue(result), defaultValue); |
| 319 } | 362 } |
| 320 | 363 |
| 321 test_getValue_flushResults() { | 364 test_getValue_flushResults() { |
| 322 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 365 ResultCachingPolicy<int> cachingPolicy = |
| 323 ResultDescriptor descriptor1 = | 366 new SimpleResultCachingPolicy<int>(2, 2); |
| 324 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); | 367 ResultDescriptor<int> descriptor1 = new ResultDescriptor<int>( |
| 325 ResultDescriptor descriptor2 = | 368 'result1', null, |
| 326 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); | 369 cachingPolicy: cachingPolicy); |
| 327 ResultDescriptor descriptor3 = | 370 ResultDescriptor<int> descriptor2 = new ResultDescriptor<int>( |
| 328 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); |
| 329 AnalysisTarget target = new TestSource(); | 376 AnalysisTarget target = new TestSource(); |
| 330 CacheEntry entry = new CacheEntry(target); | 377 CacheEntry entry = new CacheEntry(target); |
| 331 cache.put(entry); | 378 cache.put(entry); |
| 332 { | 379 { |
| 333 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 380 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 334 expect(entry.getState(descriptor1), CacheState.VALID); | 381 expect(entry.getState(descriptor1), CacheState.VALID); |
| 335 } | 382 } |
| 336 { | 383 { |
| 337 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); | 384 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); |
| 338 expect(entry.getState(descriptor1), CacheState.VALID); | 385 expect(entry.getState(descriptor1), CacheState.VALID); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 352 AnalysisTarget target = new TestSource(); | 399 AnalysisTarget target = new TestSource(); |
| 353 CacheEntry entry = new CacheEntry(target); | 400 CacheEntry entry = new CacheEntry(target); |
| 354 expect(entry.hasErrorState(), false); | 401 expect(entry.hasErrorState(), false); |
| 355 } | 402 } |
| 356 | 403 |
| 357 test_hasErrorState_true() { | 404 test_hasErrorState_true() { |
| 358 AnalysisTarget target = new TestSource(); | 405 AnalysisTarget target = new TestSource(); |
| 359 ResultDescriptor result = new ResultDescriptor('test', null); | 406 ResultDescriptor result = new ResultDescriptor('test', null); |
| 360 CaughtException exception = new CaughtException(null, null); | 407 CaughtException exception = new CaughtException(null, null); |
| 361 CacheEntry entry = new CacheEntry(target); | 408 CacheEntry entry = new CacheEntry(target); |
| 409 cache.put(entry); |
| 362 entry.setErrorState(exception, <ResultDescriptor>[result]); | 410 entry.setErrorState(exception, <ResultDescriptor>[result]); |
| 363 expect(entry.hasErrorState(), true); | 411 expect(entry.hasErrorState(), true); |
| 364 } | 412 } |
| 365 | 413 |
| 366 test_invalidateAllInformation() { | 414 test_invalidateAllInformation() { |
| 367 AnalysisTarget target = new TestSource(); | 415 AnalysisTarget target = new TestSource(); |
| 368 ResultDescriptor result = new ResultDescriptor('test', null); | 416 ResultDescriptor<String> result = |
| 417 new ResultDescriptor<String>('test', null); |
| 369 CacheEntry entry = new CacheEntry(target); | 418 CacheEntry entry = new CacheEntry(target); |
| 419 cache.put(entry); |
| 370 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); | 420 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); |
| 371 entry.invalidateAllInformation(); | 421 entry.invalidateAllInformation(); |
| 372 expect(entry.getState(result), CacheState.INVALID); | 422 expect(entry.getState(result), CacheState.INVALID); |
| 373 expect(entry.getValue(result), isNull); | 423 expect(entry.getValue(result), isNull); |
| 374 } | 424 } |
| 375 | 425 |
| 376 test_setErrorState() { | 426 test_setErrorState() { |
| 377 AnalysisTarget target = new TestSource(); | 427 AnalysisTarget target = new TestSource(); |
| 378 ResultDescriptor result1 = new ResultDescriptor('res1', 1); | 428 ResultDescriptor<int> result1 = new ResultDescriptor<int>('res1', 1); |
| 379 ResultDescriptor result2 = new ResultDescriptor('res2', 2); | 429 ResultDescriptor<int> result2 = new ResultDescriptor<int>('res2', 2); |
| 380 ResultDescriptor result3 = new ResultDescriptor('res3', 3); | 430 ResultDescriptor<int> result3 = new ResultDescriptor<int>('res3', 3); |
| 381 // prepare some good state | 431 // prepare some good state |
| 382 CacheEntry entry = new CacheEntry(target); | 432 CacheEntry entry = new CacheEntry(target); |
| 433 cache.put(entry); |
| 383 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); | 434 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); |
| 384 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); | 435 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); |
| 385 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); | 436 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); |
| 386 // set error state | 437 // set error state |
| 387 CaughtException exception = new CaughtException(null, null); | 438 CaughtException exception = new CaughtException(null, null); |
| 388 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); | 439 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); |
| 389 // verify | 440 // verify |
| 390 expect(entry.exception, exception); | 441 expect(entry.exception, exception); |
| 391 expect(entry.getState(result1), CacheState.ERROR); | 442 expect(entry.getState(result1), CacheState.ERROR); |
| 392 expect(entry.getState(result2), CacheState.ERROR); | 443 expect(entry.getState(result2), CacheState.ERROR); |
| 393 expect(entry.getState(result3), CacheState.VALID); | 444 expect(entry.getState(result3), CacheState.VALID); |
| 394 expect(entry.getValue(result1), 1); | 445 expect(entry.getValue(result1), 1); |
| 395 expect(entry.getValue(result2), 2); | 446 expect(entry.getValue(result2), 2); |
| 396 expect(entry.getValue(result3), 30); | 447 expect(entry.getValue(result3), 30); |
| 397 } | 448 } |
| 398 | 449 |
| 399 test_setErrorState_invalidateDependent() { | 450 test_setErrorState_invalidateDependent() { |
| 400 AnalysisTarget target1 = new TestSource('/a.dart'); | 451 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 401 AnalysisTarget target2 = new TestSource('/b.dart'); | 452 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 402 CacheEntry entry1 = new CacheEntry(target1); | 453 CacheEntry entry1 = new CacheEntry(target1); |
| 403 CacheEntry entry2 = new CacheEntry(target2); | 454 CacheEntry entry2 = new CacheEntry(target2); |
| 404 cache.put(entry1); | 455 cache.put(entry1); |
| 405 cache.put(entry2); | 456 cache.put(entry2); |
| 406 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 457 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 407 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 458 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 408 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 459 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 409 ResultDescriptor result4 = new ResultDescriptor('result4', -4); | 460 ResultDescriptor<int> result4 = new ResultDescriptor<int>('result4', -4); |
| 410 // set results, all of them are VALID | 461 // set results, all of them are VALID |
| 411 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 462 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 412 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 463 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
| 413 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); | 464 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); |
| 414 entry2.setValue(result4, 444, []); | 465 entry2.setValue(result4, 444, []); |
| 415 expect(entry1.getState(result1), CacheState.VALID); | 466 expect(entry1.getState(result1), CacheState.VALID); |
| 416 expect(entry2.getState(result2), CacheState.VALID); | 467 expect(entry2.getState(result2), CacheState.VALID); |
| 417 expect(entry2.getState(result3), CacheState.VALID); | 468 expect(entry2.getState(result3), CacheState.VALID); |
| 418 expect(entry2.getState(result4), CacheState.VALID); | 469 expect(entry2.getState(result4), CacheState.VALID); |
| 419 expect(entry1.getValue(result1), 111); | 470 expect(entry1.getValue(result1), 111); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 AnalysisTarget target = new TestSource(); | 509 AnalysisTarget target = new TestSource(); |
| 459 CaughtException exception = new CaughtException(null, null); | 510 CaughtException exception = new CaughtException(null, null); |
| 460 CacheEntry entry = new CacheEntry(target); | 511 CacheEntry entry = new CacheEntry(target); |
| 461 expect(() { | 512 expect(() { |
| 462 entry.setErrorState(exception, null); | 513 entry.setErrorState(exception, null); |
| 463 }, throwsArgumentError); | 514 }, throwsArgumentError); |
| 464 } | 515 } |
| 465 | 516 |
| 466 test_setState_error() { | 517 test_setState_error() { |
| 467 AnalysisTarget target = new TestSource(); | 518 AnalysisTarget target = new TestSource(); |
| 468 ResultDescriptor result = new ResultDescriptor('test', null); | 519 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
| 469 CacheEntry entry = new CacheEntry(target); | 520 CacheEntry entry = new CacheEntry(target); |
| 521 cache.put(entry); |
| 470 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 522 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
| 471 // an invalid state change | 523 // an invalid state change |
| 472 expect(() { | 524 expect(() { |
| 473 entry.setState(result, CacheState.ERROR); | 525 entry.setState(result, CacheState.ERROR); |
| 474 }, throwsArgumentError); | 526 }, throwsArgumentError); |
| 475 // no changes | 527 // no changes |
| 476 expect(entry.getState(result), CacheState.VALID); | 528 expect(entry.getState(result), CacheState.VALID); |
| 477 expect(entry.getValue(result), 42); | 529 expect(entry.getValue(result), 42); |
| 478 } | 530 } |
| 479 | 531 |
| 480 test_setState_flushed() { | 532 test_setState_flushed() { |
| 481 AnalysisTarget target = new TestSource(); | 533 AnalysisTarget target = new TestSource(); |
| 482 ResultDescriptor result = new ResultDescriptor('test', 1); | 534 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
| 483 CacheEntry entry = new CacheEntry(target); | 535 CacheEntry entry = new CacheEntry(target); |
| 536 cache.put(entry); |
| 484 // set VALID | 537 // set VALID |
| 485 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 538 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 486 expect(entry.getState(result), CacheState.VALID); | 539 expect(entry.getState(result), CacheState.VALID); |
| 487 expect(entry.getValue(result), 10); | 540 expect(entry.getValue(result), 10); |
| 488 // set FLUSHED | 541 // set FLUSHED |
| 489 entry.setState(result, CacheState.FLUSHED); | 542 entry.setState(result, CacheState.FLUSHED); |
| 490 expect(entry.getState(result), CacheState.FLUSHED); | 543 expect(entry.getState(result), CacheState.FLUSHED); |
| 491 expect(entry.getValue(result), 1); | 544 expect(entry.getValue(result), 1); |
| 492 } | 545 } |
| 493 | 546 |
| 494 test_setState_inProcess() { | 547 test_setState_inProcess() { |
| 495 AnalysisTarget target = new TestSource(); | 548 AnalysisTarget target = new TestSource(); |
| 496 ResultDescriptor result = new ResultDescriptor('test', 1); | 549 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
| 497 CacheEntry entry = new CacheEntry(target); | 550 CacheEntry entry = new CacheEntry(target); |
| 551 cache.put(entry); |
| 498 // set VALID | 552 // set VALID |
| 499 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 553 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 500 expect(entry.getState(result), CacheState.VALID); | 554 expect(entry.getState(result), CacheState.VALID); |
| 501 expect(entry.getValue(result), 10); | 555 expect(entry.getValue(result), 10); |
| 502 // set IN_PROCESS | 556 // set IN_PROCESS |
| 503 entry.setState(result, CacheState.IN_PROCESS); | 557 entry.setState(result, CacheState.IN_PROCESS); |
| 504 expect(entry.getState(result), CacheState.IN_PROCESS); | 558 expect(entry.getState(result), CacheState.IN_PROCESS); |
| 505 expect(entry.getValue(result), 10); | 559 expect(entry.getValue(result), 10); |
| 506 } | 560 } |
| 507 | 561 |
| 508 test_setState_invalid() { | 562 test_setState_invalid() { |
| 509 AnalysisTarget target = new TestSource(); | 563 AnalysisTarget target = new TestSource(); |
| 510 ResultDescriptor result = new ResultDescriptor('test', 1); | 564 ResultDescriptor<int> result = new ResultDescriptor<int>('test', 1); |
| 511 CacheEntry entry = new CacheEntry(target); | 565 CacheEntry entry = new CacheEntry(target); |
| 512 cache.put(entry); | 566 cache.put(entry); |
| 513 // set VALID | 567 // set VALID |
| 514 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 568 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 515 expect(entry.getState(result), CacheState.VALID); | 569 expect(entry.getState(result), CacheState.VALID); |
| 516 expect(entry.getValue(result), 10); | 570 expect(entry.getValue(result), 10); |
| 517 // listen, expect "result" invalidation event | 571 // listen, expect "result" invalidation event |
| 518 int numberOfEvents = 0; | 572 int numberOfEvents = 0; |
| 519 cache.onResultInvalidated.listen((event) { | 573 cache.onResultInvalidated.listen((event) { |
| 520 numberOfEvents++; | 574 numberOfEvents++; |
| 521 expect(event.entry, same(entry)); | 575 expect(event.entry, same(entry)); |
| 522 expect(event.descriptor, same(result)); | 576 expect(event.descriptor, same(result)); |
| 523 }); | 577 }); |
| 524 // set INVALID | 578 // set INVALID |
| 525 entry.setState(result, CacheState.INVALID); | 579 entry.setState(result, CacheState.INVALID); |
| 526 expect(entry.getState(result), CacheState.INVALID); | 580 expect(entry.getState(result), CacheState.INVALID); |
| 527 expect(entry.getValue(result), 1); | 581 expect(entry.getValue(result), 1); |
| 528 expect(numberOfEvents, 1); | 582 expect(numberOfEvents, 1); |
| 529 } | 583 } |
| 530 | 584 |
| 531 test_setState_invalid_dependencyCycle() { | 585 test_setState_invalid_dependencyCycle() { |
| 532 AnalysisTarget target1 = new TestSource('/a.dart'); | 586 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 533 AnalysisTarget target2 = new TestSource('/b.dart'); | 587 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 534 CacheEntry entry1 = new CacheEntry(target1); | 588 CacheEntry entry1 = new CacheEntry(target1); |
| 535 CacheEntry entry2 = new CacheEntry(target2); | 589 CacheEntry entry2 = new CacheEntry(target2); |
| 536 cache.put(entry1); | 590 cache.put(entry1); |
| 537 cache.put(entry2); | 591 cache.put(entry2); |
| 538 ResultDescriptor result = new ResultDescriptor('result', -1); | 592 ResultDescriptor<int> result = new ResultDescriptor<int>('result', -1); |
| 539 // 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. |
| 540 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); | 594 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); |
| 541 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); | 595 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); |
| 542 expect(entry1.getState(result), CacheState.VALID); | 596 expect(entry1.getState(result), CacheState.VALID); |
| 543 expect(entry2.getState(result), CacheState.VALID); | 597 expect(entry2.getState(result), CacheState.VALID); |
| 544 // Listen, expect entry1.result and entry2.result invalidation events. | 598 // Listen, expect entry1.result and entry2.result invalidation events. |
| 545 int numberOfEvents = 0; | 599 int numberOfEvents = 0; |
| 546 bool wasEntry1 = false; | 600 bool wasEntry1 = false; |
| 547 bool wasEntry2 = false; | 601 bool wasEntry2 = false; |
| 548 cache.onResultInvalidated.listen((event) { | 602 cache.onResultInvalidated.listen((event) { |
| 549 numberOfEvents++; | 603 numberOfEvents++; |
| 550 if (event.entry == entry1) wasEntry1 = true; | 604 if (event.entry == entry1) wasEntry1 = true; |
| 551 if (event.entry == entry2) wasEntry2 = true; | 605 if (event.entry == entry2) wasEntry2 = true; |
| 552 expect(event.descriptor, same(result)); | 606 expect(event.descriptor, same(result)); |
| 553 }); | 607 }); |
| 554 // Invalidate entry1.result; this should cause entry2 to be also | 608 // Invalidate entry1.result; this should cause entry2 to be also |
| 555 // cleared without going into an infinite regress. | 609 // cleared without going into an infinite regress. |
| 556 entry1.setState(result, CacheState.INVALID); | 610 entry1.setState(result, CacheState.INVALID); |
| 557 expect(cache.get(target1), isNull); | 611 expect(cache.get(target1), isNull); |
| 558 expect(cache.get(target2), isNull); | 612 expect(cache.get(target2), isNull); |
| 559 expect(numberOfEvents, 2); | 613 expect(numberOfEvents, 2); |
| 560 expect(wasEntry1, isTrue); | 614 expect(wasEntry1, isTrue); |
| 561 expect(wasEntry2, isTrue); | 615 expect(wasEntry2, isTrue); |
| 562 } | 616 } |
| 563 | 617 |
| 564 test_setState_invalid_invalidateDependent() { | 618 test_setState_invalid_invalidateDependent() { |
| 565 AnalysisTarget target = new TestSource(); | 619 AnalysisTarget target = new TestSource(); |
| 566 CacheEntry entry = new CacheEntry(target); | 620 CacheEntry entry = new CacheEntry(target); |
| 567 cache.put(entry); | 621 cache.put(entry); |
| 568 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 622 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 569 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 623 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 570 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 624 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 571 ResultDescriptor result4 = new ResultDescriptor('result4', -4); | 625 ResultDescriptor<int> result4 = new ResultDescriptor<int>('result4', -4); |
| 572 // set results, all of them are VALID | 626 // set results, all of them are VALID |
| 573 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 627 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 574 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 628 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 575 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 629 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
| 576 entry.setValue(result4, 444, []); | 630 entry.setValue(result4, 444, []); |
| 577 expect(entry.getState(result1), CacheState.VALID); | 631 expect(entry.getState(result1), CacheState.VALID); |
| 578 expect(entry.getState(result2), CacheState.VALID); | 632 expect(entry.getState(result2), CacheState.VALID); |
| 579 expect(entry.getState(result3), CacheState.VALID); | 633 expect(entry.getState(result3), CacheState.VALID); |
| 580 expect(entry.getState(result4), CacheState.VALID); | 634 expect(entry.getState(result4), CacheState.VALID); |
| 581 expect(entry.getValue(result1), 111); | 635 expect(entry.getValue(result1), 111); |
| 582 expect(entry.getValue(result2), 222); | 636 expect(entry.getValue(result2), 222); |
| 583 expect(entry.getValue(result3), 333); | 637 expect(entry.getValue(result3), 333); |
| 584 expect(entry.getValue(result4), 444); | 638 expect(entry.getValue(result4), 444); |
| 585 // invalidate result1, invalidates result2 and result3, result4 is intact | 639 // invalidate result1, invalidates result2 and result3, result4 is intact |
| 586 entry.setState(result1, CacheState.INVALID); | 640 entry.setState(result1, CacheState.INVALID); |
| 587 expect(entry.getState(result1), CacheState.INVALID); | 641 expect(entry.getState(result1), CacheState.INVALID); |
| 588 expect(entry.getState(result2), CacheState.INVALID); | 642 expect(entry.getState(result2), CacheState.INVALID); |
| 589 expect(entry.getState(result3), CacheState.INVALID); | 643 expect(entry.getState(result3), CacheState.INVALID); |
| 590 expect(entry.getState(result4), CacheState.VALID); | 644 expect(entry.getState(result4), CacheState.VALID); |
| 591 expect(entry.getValue(result1), -1); | 645 expect(entry.getValue(result1), -1); |
| 592 expect(entry.getValue(result2), -2); | 646 expect(entry.getValue(result2), -2); |
| 593 expect(entry.getValue(result3), -3); | 647 expect(entry.getValue(result3), -3); |
| 594 expect(entry.getValue(result4), 444); | 648 expect(entry.getValue(result4), 444); |
| 595 // 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 |
| 596 expect(cache.get(target), entry); | 650 expect(cache.get(target), entry); |
| 597 } | 651 } |
| 598 | 652 |
| 653 test_setState_invalid_keepEmpty_ifExplicitlyAdded() { |
| 654 AnalysisTarget target = new TestSource('/a.dart'); |
| 655 CacheEntry entry = new CacheEntry(target); |
| 656 entry.explicitlyAdded = true; |
| 657 cache.put(entry); |
| 658 ResultDescriptor<int> result = new ResultDescriptor<int>('result1', -1); |
| 659 // set results, all of them are VALID |
| 660 entry.setValue(result, 111, TargetedResult.EMPTY_LIST); |
| 661 expect(entry.getState(result), CacheState.VALID); |
| 662 expect(entry.getValue(result), 111); |
| 663 // invalidate result, keep entry |
| 664 entry.setState(result, CacheState.INVALID); |
| 665 expect(cache.get(target), isNotNull); |
| 666 } |
| 667 |
| 599 test_setState_invalid_removeEmptyEntry() { | 668 test_setState_invalid_removeEmptyEntry() { |
| 600 AnalysisTarget target1 = new TestSource('/a.dart'); | 669 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 601 AnalysisTarget target2 = new TestSource('/b.dart'); | 670 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 602 CacheEntry entry1 = new CacheEntry(target1); | 671 CacheEntry entry1 = new CacheEntry(target1); |
| 603 CacheEntry entry2 = new CacheEntry(target2); | 672 CacheEntry entry2 = new CacheEntry(target2); |
| 604 cache.put(entry1); | 673 cache.put(entry1); |
| 605 cache.put(entry2); | 674 cache.put(entry2); |
| 606 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 675 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 607 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 676 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 608 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 677 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 609 // set results, all of them are VALID | 678 // set results, all of them are VALID |
| 610 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 679 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 611 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 680 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
| 612 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); | 681 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]); |
| 613 expect(entry1.getState(result1), CacheState.VALID); | 682 expect(entry1.getState(result1), CacheState.VALID); |
| 614 expect(entry2.getState(result2), CacheState.VALID); | 683 expect(entry2.getState(result2), CacheState.VALID); |
| 615 expect(entry2.getState(result3), CacheState.VALID); | 684 expect(entry2.getState(result3), CacheState.VALID); |
| 616 expect(entry1.getValue(result1), 111); | 685 expect(entry1.getValue(result1), 111); |
| 617 expect(entry2.getValue(result2), 222); | 686 expect(entry2.getValue(result2), 222); |
| 618 expect(entry2.getValue(result3), 333); | 687 expect(entry2.getValue(result3), 333); |
| 619 // invalidate result1, remove entry1 & entry2 | 688 // invalidate result1, remove entry1 & entry2 |
| 620 entry1.setState(result1, CacheState.INVALID); | 689 entry1.setState(result1, CacheState.INVALID); |
| 621 expect(cache.get(target1), isNull); | 690 expect(cache.get(target1), isNull); |
| 622 expect(cache.get(target2), isNull); | 691 expect(cache.get(target2), isNull); |
| 623 } | 692 } |
| 624 | 693 |
| 625 test_setState_invalid_withDelta_keepDependency() { | 694 test_setState_invalid_withDelta_keepDependency() { |
| 626 Source target = new TestSource('/test.dart'); | 695 Source target = new TestSource('/test.dart'); |
| 627 CacheEntry entry = new CacheEntry(target); | 696 CacheEntry entry = new CacheEntry(target); |
| 628 cache.put(entry); | 697 cache.put(entry); |
| 629 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 698 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 630 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 699 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 631 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 700 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 632 // set results, all of them are VALID | 701 // set results, all of them are VALID |
| 633 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 702 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 634 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 703 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 635 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 704 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
| 636 expect(entry.getState(result1), CacheState.VALID); | 705 expect(entry.getState(result1), CacheState.VALID); |
| 637 expect(entry.getState(result2), CacheState.VALID); | 706 expect(entry.getState(result2), CacheState.VALID); |
| 638 expect(entry.getState(result3), CacheState.VALID); | 707 expect(entry.getState(result3), CacheState.VALID); |
| 639 // result2 depends on result1 | 708 // result2 depends on result1 |
| 640 expect(entry.getResultData(result1).dependentResults, | 709 expect(entry.getResultData(result1).dependentResults, |
| 641 unorderedEquals([new TargetedResult(target, result2)])); | 710 unorderedEquals([new TargetedResult(target, result2)])); |
| 642 expect(entry.getResultData(result2).dependedOnResults, | 711 expect(entry.getResultData(result2).dependedOnResults, |
| 643 unorderedEquals([new TargetedResult(target, result1)])); | 712 unorderedEquals([new TargetedResult(target, result1)])); |
| 713 // record invalidated results |
| 714 Set<TargetedResult> reportedInvalidatedResults = new Set<TargetedResult>(); |
| 715 cache.onResultInvalidated.listen((InvalidatedResult invalidatedResult) { |
| 716 reportedInvalidatedResults.add(new TargetedResult( |
| 717 invalidatedResult.entry.target, invalidatedResult.descriptor)); |
| 718 }); |
| 644 // invalidate result2 with Delta: keep result2, invalidate result3 | 719 // invalidate result2 with Delta: keep result2, invalidate result3 |
| 645 entry.setState(result2, CacheState.INVALID, | 720 entry.setState(result2, CacheState.INVALID, |
| 646 delta: new _KeepContinueDelta(target, result2)); | 721 delta: new _KeepContinueDelta(target, result2)); |
| 647 expect(entry.getState(result1), CacheState.VALID); | 722 expect(entry.getState(result1), CacheState.VALID); |
| 648 expect(entry.getState(result2), CacheState.VALID); | 723 expect(entry.getState(result2), CacheState.VALID); |
| 649 expect(entry.getState(result3), CacheState.INVALID); | 724 expect(entry.getState(result3), CacheState.INVALID); |
| 650 // result2 still depends on result1 | 725 // result2 still depends on result1 |
| 651 expect(entry.getResultData(result1).dependentResults, | 726 expect(entry.getResultData(result1).dependentResults, |
| 652 unorderedEquals([new TargetedResult(target, result2)])); | 727 unorderedEquals([new TargetedResult(target, result2)])); |
| 653 expect(entry.getResultData(result2).dependedOnResults, | 728 expect(entry.getResultData(result2).dependedOnResults, |
| 654 unorderedEquals([new TargetedResult(target, result1)])); | 729 unorderedEquals([new TargetedResult(target, result1)])); |
| 730 // (target, result3) was reported as invalidated |
| 731 // (target, result2) was NOT reported |
| 732 expect(reportedInvalidatedResults, |
| 733 unorderedEquals([new TargetedResult(target, result3)])); |
| 655 } | 734 } |
| 656 | 735 |
| 657 test_setState_valid() { | 736 test_setState_valid() { |
| 658 AnalysisTarget target = new TestSource(); | 737 AnalysisTarget target = new TestSource(); |
| 659 ResultDescriptor result = new ResultDescriptor('test', null); | 738 ResultDescriptor result = new ResultDescriptor('test', null); |
| 660 CacheEntry entry = new CacheEntry(target); | 739 CacheEntry entry = new CacheEntry(target); |
| 661 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 740 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
| 662 } | 741 } |
| 663 | 742 |
| 664 test_setValue() { | 743 test_setValue() { |
| 665 AnalysisTarget target = new TestSource(); | 744 AnalysisTarget target = new TestSource(); |
| 666 ResultDescriptor result = new ResultDescriptor('test', null); | 745 ResultDescriptor<String> result = |
| 746 new ResultDescriptor<String>('test', null); |
| 667 String value = 'value'; | 747 String value = 'value'; |
| 668 CacheEntry entry = new CacheEntry(target); | 748 CacheEntry entry = new CacheEntry(target); |
| 749 cache.put(entry); |
| 669 entry.setValue(result, value, TargetedResult.EMPTY_LIST); | 750 entry.setValue(result, value, TargetedResult.EMPTY_LIST); |
| 670 expect(entry.getState(result), CacheState.VALID); | 751 expect(entry.getState(result), CacheState.VALID); |
| 671 expect(entry.getValue(result), value); | 752 expect(entry.getValue(result), value); |
| 672 } | 753 } |
| 673 | 754 |
| 674 test_setValue_flushResults() { | 755 test_setValue_flushResults() { |
| 675 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 756 ResultCachingPolicy<int> cachingPolicy = |
| 676 ResultDescriptor descriptor1 = | 757 new SimpleResultCachingPolicy<int>(2, 2); |
| 677 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); | 758 ResultDescriptor<int> descriptor1 = new ResultDescriptor<int>( |
| 678 ResultDescriptor descriptor2 = | 759 'result1', null, |
| 679 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); | 760 cachingPolicy: cachingPolicy); |
| 680 ResultDescriptor descriptor3 = | 761 ResultDescriptor<int> descriptor2 = new ResultDescriptor<int>( |
| 681 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); |
| 682 AnalysisTarget target = new TestSource(); | 767 AnalysisTarget target = new TestSource(); |
| 683 CacheEntry entry = new CacheEntry(target); | 768 CacheEntry entry = new CacheEntry(target); |
| 684 cache.put(entry); | 769 cache.put(entry); |
| 685 { | 770 { |
| 686 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 771 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 687 expect(entry.getState(descriptor1), CacheState.VALID); | 772 expect(entry.getState(descriptor1), CacheState.VALID); |
| 688 } | 773 } |
| 689 { | 774 { |
| 690 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); | 775 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); |
| 691 expect(entry.getState(descriptor1), CacheState.VALID); | 776 expect(entry.getState(descriptor1), CacheState.VALID); |
| 692 expect(entry.getState(descriptor2), CacheState.VALID); | 777 expect(entry.getState(descriptor2), CacheState.VALID); |
| 693 } | 778 } |
| 694 { | 779 { |
| 695 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); | 780 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); |
| 696 expect(entry.getState(descriptor1), CacheState.FLUSHED); | 781 expect(entry.getState(descriptor1), CacheState.FLUSHED); |
| 697 expect(entry.getState(descriptor2), CacheState.VALID); | 782 expect(entry.getState(descriptor2), CacheState.VALID); |
| 698 expect(entry.getState(descriptor3), CacheState.VALID); | 783 expect(entry.getState(descriptor3), CacheState.VALID); |
| 699 } | 784 } |
| 700 } | 785 } |
| 701 | 786 |
| 787 test_setValue_flushResults_keepForPrioritySources() { |
| 788 ResultCachingPolicy<int> cachingPolicy = |
| 789 new SimpleResultCachingPolicy<int>(2, 2); |
| 790 ResultDescriptor<int> newResult(String name) => |
| 791 new ResultDescriptor<int>(name, null, cachingPolicy: cachingPolicy); |
| 792 ResultDescriptor<int> descriptor1 = newResult('result1'); |
| 793 ResultDescriptor<int> descriptor2 = newResult('result2'); |
| 794 ResultDescriptor<int> descriptor3 = newResult('result3'); |
| 795 TestSource source1 = new TestSource('/a.dart'); |
| 796 TestSource source2 = new TestSource('/b.dart'); |
| 797 TestSource source3 = new TestSource('/c.dart'); |
| 798 AnalysisTarget target1 = |
| 799 new _TestAnalysisTarget(librarySource: source1, source: source1); |
| 800 AnalysisTarget target2 = |
| 801 new _TestAnalysisTarget(librarySource: source2, source: source2); |
| 802 AnalysisTarget target3 = |
| 803 new _TestAnalysisTarget(librarySource: source3, source: source3); |
| 804 CacheEntry entry1 = new CacheEntry(target1); |
| 805 CacheEntry entry2 = new CacheEntry(target2); |
| 806 CacheEntry entry3 = new CacheEntry(target3); |
| 807 cache.put(entry1); |
| 808 cache.put(entry2); |
| 809 cache.put(entry3); |
| 810 |
| 811 // Set two results. |
| 812 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 813 entry2.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST); |
| 814 expect(entry1.getState(descriptor1), CacheState.VALID); |
| 815 expect(entry2.getState(descriptor2), CacheState.VALID); |
| 816 |
| 817 // Make source1 priority, so result2 is flushed instead. |
| 818 when(context.prioritySources).thenReturn([source1]); |
| 819 entry3.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); |
| 820 expect(entry1.getState(descriptor1), CacheState.VALID); |
| 821 expect(entry2.getState(descriptor2), CacheState.FLUSHED); |
| 822 expect(entry3.getState(descriptor3), CacheState.VALID); |
| 823 } |
| 824 |
| 702 test_setValue_keepDependent() { | 825 test_setValue_keepDependent() { |
| 703 AnalysisTarget target = new TestSource(); | 826 AnalysisTarget target = new TestSource(); |
| 704 CacheEntry entry = new CacheEntry(target); | 827 CacheEntry entry = new CacheEntry(target); |
| 705 cache.put(entry); | 828 cache.put(entry); |
| 706 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 829 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 707 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 830 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 708 // set results, all of them are VALID | 831 // set results, all of them are VALID |
| 709 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 832 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 710 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 833 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 711 expect(entry.getState(result1), CacheState.VALID); | 834 expect(entry.getState(result1), CacheState.VALID); |
| 712 expect(entry.getState(result2), CacheState.VALID); | 835 expect(entry.getState(result2), CacheState.VALID); |
| 713 expect(entry.getValue(result1), 111); | 836 expect(entry.getValue(result1), 111); |
| 714 expect(entry.getValue(result2), 222); | 837 expect(entry.getValue(result2), 222); |
| 715 // set result1; result2 is intact | 838 // set result1; result2 is intact |
| 716 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST); | 839 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST); |
| 717 expect(entry.getState(result1), CacheState.VALID); | 840 expect(entry.getState(result1), CacheState.VALID); |
| 718 expect(entry.getState(result2), CacheState.VALID); | 841 expect(entry.getState(result2), CacheState.VALID); |
| 719 expect(entry.getValue(result1), 1111); | 842 expect(entry.getValue(result1), 1111); |
| 720 expect(entry.getValue(result2), 222); | 843 expect(entry.getValue(result2), 222); |
| 721 } | 844 } |
| 722 | 845 |
| 846 test_setValue_userBeforeProvider_invalidateProvider_alsoUser() { |
| 847 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 848 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 849 CacheEntry entry1 = new CacheEntry(target1); |
| 850 CacheEntry entry2 = new CacheEntry(target2); |
| 851 cache.put(entry1); |
| 852 cache.put(entry2); |
| 853 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 854 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 855 // set results, all of them are VALID |
| 856 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
| 857 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 858 expect(entry1.getState(result1), CacheState.VALID); |
| 859 expect(entry2.getState(result2), CacheState.VALID); |
| 860 expect(entry1.getValue(result1), 111); |
| 861 expect(entry2.getValue(result2), 222); |
| 862 // invalidate result1, should invalidate also result2 |
| 863 entry1.setState(result1, CacheState.INVALID); |
| 864 expect(entry1.getState(result1), CacheState.INVALID); |
| 865 expect(entry2.getState(result2), CacheState.INVALID); |
| 866 } |
| 867 |
| 723 test_setValueIncremental() { | 868 test_setValueIncremental() { |
| 724 AnalysisTarget target = new TestSource(); | 869 AnalysisTarget target = new TestSource(); |
| 725 CacheEntry entry = new CacheEntry(target); | 870 CacheEntry entry = new CacheEntry(target); |
| 726 cache.put(entry); | 871 cache.put(entry); |
| 727 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 872 ResultDescriptor<int> result1 = new ResultDescriptor<int>('result1', -1); |
| 728 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 873 ResultDescriptor<int> result2 = new ResultDescriptor<int>('result2', -2); |
| 729 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 874 ResultDescriptor<int> result3 = new ResultDescriptor<int>('result3', -3); |
| 730 // set results, all of them are VALID | 875 // set results, all of them are VALID |
| 731 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 876 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 732 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 877 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 733 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); | 878 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
| 734 expect(entry.getState(result1), CacheState.VALID); | 879 expect(entry.getState(result1), CacheState.VALID); |
| 735 expect(entry.getState(result2), CacheState.VALID); | 880 expect(entry.getState(result2), CacheState.VALID); |
| 736 expect(entry.getState(result3), CacheState.VALID); | 881 expect(entry.getState(result3), CacheState.VALID); |
| 737 expect(entry.getValue(result1), 111); | 882 expect(entry.getValue(result1), 111); |
| 738 expect(entry.getValue(result2), 222); | 883 expect(entry.getValue(result2), 222); |
| 739 expect(entry.getValue(result3), 333); | 884 expect(entry.getValue(result3), 333); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 752 } | 897 } |
| 753 | 898 |
| 754 test_toString_empty() { | 899 test_toString_empty() { |
| 755 AnalysisTarget target = new TestSource(); | 900 AnalysisTarget target = new TestSource(); |
| 756 CacheEntry entry = new CacheEntry(target); | 901 CacheEntry entry = new CacheEntry(target); |
| 757 expect(entry.toString(), isNotNull); | 902 expect(entry.toString(), isNotNull); |
| 758 } | 903 } |
| 759 | 904 |
| 760 test_toString_nonEmpty() { | 905 test_toString_nonEmpty() { |
| 761 AnalysisTarget target = new TestSource(); | 906 AnalysisTarget target = new TestSource(); |
| 762 ResultDescriptor result = new ResultDescriptor('test', null); | 907 ResultDescriptor<int> result = new ResultDescriptor<int>('test', null); |
| 763 CacheEntry entry = new CacheEntry(target); | 908 CacheEntry entry = new CacheEntry(target); |
| 909 cache.put(entry); |
| 764 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 910 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
| 765 expect(entry.toString(), isNotNull); | 911 expect(entry.toString(), isNotNull); |
| 766 } | 912 } |
| 767 } | 913 } |
| 768 | 914 |
| 769 @reflectiveTest | 915 @reflectiveTest |
| 770 class CacheFlushManagerTest { | 916 class CacheFlushManagerTest { |
| 771 CacheFlushManager manager = new CacheFlushManager( | 917 CacheFlushManager manager = new CacheFlushManager( |
| 772 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); | 918 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); |
| 773 | 919 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 794 // make idle | 940 // make idle |
| 795 List<TargetedResult> resultsToFlush = manager.madeIdle(); | 941 List<TargetedResult> resultsToFlush = manager.madeIdle(); |
| 796 expect(manager.maxSize, 3); | 942 expect(manager.maxSize, 3); |
| 797 expect(manager.recentlyUsed, results.skip(15 - 3)); | 943 expect(manager.recentlyUsed, results.skip(15 - 3)); |
| 798 expect(resultsToFlush, results.take(15 - 3)); | 944 expect(resultsToFlush, results.take(15 - 3)); |
| 799 } | 945 } |
| 800 | 946 |
| 801 test_new() { | 947 test_new() { |
| 802 expect(manager.maxActiveSize, 15); | 948 expect(manager.maxActiveSize, 15); |
| 803 expect(manager.maxIdleSize, 3); | 949 expect(manager.maxIdleSize, 3); |
| 804 expect(manager.maxSize, 3); | 950 expect(manager.maxSize, 15); |
| 805 expect(manager.currentSize, 0); | 951 expect(manager.currentSize, 0); |
| 806 expect(manager.recentlyUsed, isEmpty); | 952 expect(manager.recentlyUsed, isEmpty); |
| 807 } | 953 } |
| 808 | 954 |
| 809 test_resultAccessed() { | 955 test_resultAccessed() { |
| 810 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); | 956 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); |
| 811 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); | 957 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); |
| 812 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); | 958 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); |
| 813 AnalysisTarget target = new TestSource(); | 959 AnalysisTarget target = new TestSource(); |
| 814 TargetedResult result1 = new TargetedResult(target, descriptor1); | 960 TargetedResult result1 = new TargetedResult(target, descriptor1); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 manager.resultStored(result2, null); | 1001 manager.resultStored(result2, null); |
| 856 expect(manager.currentSize, 2); | 1002 expect(manager.currentSize, 2); |
| 857 expect(manager.recentlyUsed, orderedEquals([result1, result2])); | 1003 expect(manager.recentlyUsed, orderedEquals([result1, result2])); |
| 858 // access result3, no-op | 1004 // access result3, no-op |
| 859 manager.resultAccessed(result3); | 1005 manager.resultAccessed(result3); |
| 860 expect(manager.currentSize, 2); | 1006 expect(manager.currentSize, 2); |
| 861 expect(manager.recentlyUsed, orderedEquals([result1, result2])); | 1007 expect(manager.recentlyUsed, orderedEquals([result1, result2])); |
| 862 } | 1008 } |
| 863 | 1009 |
| 864 test_resultStored() { | 1010 test_resultStored() { |
| 1011 CacheFlushManager manager = new CacheFlushManager( |
| 1012 new SimpleResultCachingPolicy(3, 3), (AnalysisTarget target) => false); |
| 865 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); | 1013 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); |
| 866 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); | 1014 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); |
| 867 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); | 1015 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); |
| 868 ResultDescriptor descriptor4 = new ResultDescriptor('result4', null); | 1016 ResultDescriptor descriptor4 = new ResultDescriptor('result4', null); |
| 869 AnalysisTarget target = new TestSource(); | 1017 AnalysisTarget target = new TestSource(); |
| 870 TargetedResult result1 = new TargetedResult(target, descriptor1); | 1018 TargetedResult result1 = new TargetedResult(target, descriptor1); |
| 871 TargetedResult result2 = new TargetedResult(target, descriptor2); | 1019 TargetedResult result2 = new TargetedResult(target, descriptor2); |
| 872 TargetedResult result3 = new TargetedResult(target, descriptor3); | 1020 TargetedResult result3 = new TargetedResult(target, descriptor3); |
| 873 TargetedResult result4 = new TargetedResult(target, descriptor4); | 1021 TargetedResult result4 = new TargetedResult(target, descriptor4); |
| 874 manager.resultStored(result1, null); | 1022 manager.resultStored(result1, null); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 } | 1087 } |
| 940 } | 1088 } |
| 941 | 1089 |
| 942 abstract class CachePartitionTest extends EngineTestCase { | 1090 abstract class CachePartitionTest extends EngineTestCase { |
| 943 CachePartition createPartition(); | 1091 CachePartition createPartition(); |
| 944 | 1092 |
| 945 void test_creation() { | 1093 void test_creation() { |
| 946 expect(createPartition(), isNotNull); | 1094 expect(createPartition(), isNotNull); |
| 947 } | 1095 } |
| 948 | 1096 |
| 1097 void test_dispose() { |
| 1098 CachePartition partition = createPartition(); |
| 1099 Source source1 = new TestSource('/1.dart'); |
| 1100 Source source2 = new TestSource('/2.dart'); |
| 1101 CacheEntry entry1 = new CacheEntry(source1); |
| 1102 CacheEntry entry2 = new CacheEntry(source2); |
| 1103 // add two sources |
| 1104 partition.put(entry1); |
| 1105 partition.put(entry2); |
| 1106 expect(partition.entryMap, hasLength(2)); |
| 1107 expect(partition.pathToSource, hasLength(2)); |
| 1108 expect(partition.sources, unorderedEquals([source1, source2])); |
| 1109 // dispose, no sources |
| 1110 partition.dispose(); |
| 1111 expect(partition.entryMap, isEmpty); |
| 1112 expect(partition.pathToSource, isEmpty); |
| 1113 expect(partition.sources, isEmpty); |
| 1114 } |
| 1115 |
| 949 void test_entrySet() { | 1116 void test_entrySet() { |
| 950 CachePartition partition = createPartition(); | 1117 CachePartition partition = createPartition(); |
| 951 AnalysisTarget target = new TestSource(); | 1118 AnalysisTarget target = new TestSource(); |
| 952 CacheEntry entry = new CacheEntry(target); | 1119 CacheEntry entry = new CacheEntry(target); |
| 953 partition.put(entry); | 1120 partition.put(entry); |
| 954 Map<AnalysisTarget, CacheEntry> entryMap = partition.map; | 1121 Map<AnalysisTarget, CacheEntry> entryMap = partition.entryMap; |
| 955 expect(entryMap, hasLength(1)); | 1122 expect(entryMap, hasLength(1)); |
| 956 AnalysisTarget entryKey = entryMap.keys.first; | 1123 AnalysisTarget entryKey = entryMap.keys.first; |
| 957 expect(entryKey, target); | 1124 expect(entryKey, target); |
| 958 expect(entryMap[entryKey], entry); | 1125 expect(entryMap[entryKey], entry); |
| 959 } | 1126 } |
| 960 | 1127 |
| 961 void test_get() { | 1128 void test_get() { |
| 962 CachePartition partition = createPartition(); | 1129 CachePartition partition = createPartition(); |
| 963 AnalysisTarget target = new TestSource(); | 1130 AnalysisTarget target = new TestSource(); |
| 964 expect(partition.get(target), isNull); | 1131 expect(partition.get(target), isNull); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 994 AnalysisTarget target = new TestSource(); | 1161 AnalysisTarget target = new TestSource(); |
| 995 CacheEntry entry = new CacheEntry(target); | 1162 CacheEntry entry = new CacheEntry(target); |
| 996 partition.put(entry); | 1163 partition.put(entry); |
| 997 expect(partition.get(target), entry); | 1164 expect(partition.get(target), entry); |
| 998 expect(partition.remove(target), entry); | 1165 expect(partition.remove(target), entry); |
| 999 expect(partition.get(target), isNull); | 1166 expect(partition.get(target), isNull); |
| 1000 } | 1167 } |
| 1001 } | 1168 } |
| 1002 | 1169 |
| 1003 @reflectiveTest | 1170 @reflectiveTest |
| 1171 class PackageCachePartitionTest extends CachePartitionTest { |
| 1172 MemoryResourceProvider resourceProvider; |
| 1173 Folder rootFolder; |
| 1174 |
| 1175 CachePartition createPartition() { |
| 1176 resourceProvider = new MemoryResourceProvider(); |
| 1177 rootFolder = resourceProvider.newFolder('/package/root'); |
| 1178 return new PackageCachePartition(null, rootFolder); |
| 1179 } |
| 1180 |
| 1181 void test_contains_false() { |
| 1182 CachePartition partition = createPartition(); |
| 1183 AnalysisTarget target = new TestSource(); |
| 1184 expect(partition.isResponsibleFor(target), isFalse); |
| 1185 } |
| 1186 |
| 1187 void test_contains_true() { |
| 1188 SdkCachePartition partition = new SdkCachePartition(null); |
| 1189 SourceFactory factory = new SourceFactory([ |
| 1190 new PackageMapUriResolver(resourceProvider, <String, List<Folder>>{ |
| 1191 'root': <Folder>[rootFolder] |
| 1192 }) |
| 1193 ]); |
| 1194 AnalysisTarget target = factory.forUri("package:root/root.dart"); |
| 1195 expect(partition.isResponsibleFor(target), isTrue); |
| 1196 } |
| 1197 } |
| 1198 |
| 1199 @reflectiveTest |
| 1004 class ResultDataTest extends EngineTestCase { | 1200 class ResultDataTest extends EngineTestCase { |
| 1005 test_creation() { | 1201 test_creation() { |
| 1006 String value = 'value'; | 1202 String value = 'value'; |
| 1007 ResultData data = new ResultData(new ResultDescriptor('test', value)); | 1203 ResultData data = new ResultData(new ResultDescriptor('test', value)); |
| 1008 expect(data, isNotNull); | 1204 expect(data, isNotNull); |
| 1009 expect(data.state, CacheState.INVALID); | 1205 expect(data.state, CacheState.INVALID); |
| 1010 expect(data.value, value); | 1206 expect(data.value, value); |
| 1011 } | 1207 } |
| 1012 | 1208 |
| 1013 test_flush() { | 1209 test_flush() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1028 } | 1224 } |
| 1029 | 1225 |
| 1030 void test_contains_false() { | 1226 void test_contains_false() { |
| 1031 CachePartition partition = createPartition(); | 1227 CachePartition partition = createPartition(); |
| 1032 AnalysisTarget target = new TestSource(); | 1228 AnalysisTarget target = new TestSource(); |
| 1033 expect(partition.isResponsibleFor(target), isFalse); | 1229 expect(partition.isResponsibleFor(target), isFalse); |
| 1034 } | 1230 } |
| 1035 | 1231 |
| 1036 void test_contains_true() { | 1232 void test_contains_true() { |
| 1037 SdkCachePartition partition = new SdkCachePartition(null); | 1233 SdkCachePartition partition = new SdkCachePartition(null); |
| 1038 SourceFactory factory = new SourceFactory( | 1234 ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; |
| 1039 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]); | 1235 FolderBasedDartSdk sdk = new FolderBasedDartSdk(resourceProvider, |
| 1236 FolderBasedDartSdk.defaultSdkDirectory(resourceProvider)); |
| 1237 SourceFactory factory = new SourceFactory([new DartUriResolver(sdk)]); |
| 1040 AnalysisTarget target = factory.forUri("dart:core"); | 1238 AnalysisTarget target = factory.forUri("dart:core"); |
| 1041 expect(partition.isResponsibleFor(target), isTrue); | 1239 expect(partition.isResponsibleFor(target), isTrue); |
| 1042 } | 1240 } |
| 1043 } | 1241 } |
| 1044 | 1242 |
| 1045 @reflectiveTest | 1243 @reflectiveTest |
| 1046 class UniversalCachePartitionTest extends CachePartitionTest { | 1244 class UniversalCachePartitionTest extends CachePartitionTest { |
| 1047 CachePartition createPartition() { | 1245 CachePartition createPartition() { |
| 1048 return new UniversalCachePartition(null); | 1246 return new UniversalCachePartition(null); |
| 1049 } | 1247 } |
| 1050 | 1248 |
| 1051 void test_contains() { | 1249 void test_contains() { |
| 1052 UniversalCachePartition partition = new UniversalCachePartition(null); | 1250 UniversalCachePartition partition = new UniversalCachePartition(null); |
| 1053 TestSource source = new TestSource(); | 1251 TestSource source = new TestSource(); |
| 1054 expect(partition.isResponsibleFor(source), isTrue); | 1252 expect(partition.isResponsibleFor(source), isTrue); |
| 1055 } | 1253 } |
| 1056 | 1254 |
| 1057 test_dispose() { | 1255 test_dispose() { |
| 1058 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 1256 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| 1059 CachePartition partition1 = new UniversalCachePartition(context); | 1257 CachePartition partition1 = new UniversalCachePartition(context); |
| 1060 CachePartition partition2 = new UniversalCachePartition(context); | 1258 CachePartition partition2 = new UniversalCachePartition(context); |
| 1061 AnalysisCache cache = new AnalysisCache([partition1, partition2]); | 1259 AnalysisCache cache = new AnalysisCache([partition1, partition2]); |
| 1062 when(context.analysisCache).thenReturn(cache); | 1260 when(context.analysisCache).thenReturn(cache); |
| 1063 // configure | 1261 // configure |
| 1064 // prepare entries | 1262 // prepare entries |
| 1065 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); | 1263 ResultDescriptor<int> descriptor1 = |
| 1066 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); | 1264 new ResultDescriptor<int>('result1', -1); |
| 1265 ResultDescriptor<int> descriptor2 = |
| 1266 new ResultDescriptor<int>('result2', -2); |
| 1067 AnalysisTarget target1 = new TestSource('1.dart'); | 1267 AnalysisTarget target1 = new TestSource('1.dart'); |
| 1068 AnalysisTarget target2 = new TestSource('2.dart'); | 1268 AnalysisTarget target2 = new TestSource('2.dart'); |
| 1069 TargetedResult result1 = new TargetedResult(target1, descriptor1); | 1269 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
| 1070 TargetedResult result2 = new TargetedResult(target2, descriptor2); | 1270 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
| 1071 CacheEntry entry1 = new CacheEntry(target1); | 1271 CacheEntry entry1 = new CacheEntry(target1); |
| 1072 CacheEntry entry2 = new CacheEntry(target2); | 1272 CacheEntry entry2 = new CacheEntry(target2); |
| 1073 partition1.put(entry1); | 1273 partition1.put(entry1); |
| 1074 partition2.put(entry2); | 1274 partition2.put(entry2); |
| 1075 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); | 1275 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 1076 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); | 1276 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
| 1077 // target2 is listed as dependent in target1 | 1277 // target2 is listed as dependent in target1 |
| 1078 expect( | 1278 expect( |
| 1079 entry1.getResultData(descriptor1).dependentResults, contains(result2)); | 1279 entry1.getResultData(descriptor1).dependentResults, contains(result2)); |
| 1080 // dispose | 1280 // dispose |
| 1081 partition2.dispose(); | 1281 partition2.dispose(); |
| 1082 expect(partition1.get(target1), same(entry1)); | 1282 expect(partition1.get(target1), same(entry1)); |
| 1083 expect(partition2.get(target2), isNull); | 1283 expect(partition2.get(target2), isNull); |
| 1084 // result2 is removed from result1 | 1284 // result2 is removed from result1 |
| 1085 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); | 1285 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); |
| 1086 } | 1286 } |
| 1087 } | 1287 } |
| 1088 | 1288 |
| 1089 class _InternalAnalysisContextMock extends TypedMock | 1289 class _InternalAnalysisContextMock extends TypedMock |
| 1090 implements InternalAnalysisContext { | 1290 implements InternalAnalysisContext { |
| 1091 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1291 @override |
| 1292 final AnalysisOptions analysisOptions = new AnalysisOptionsImpl(); |
| 1092 } | 1293 } |
| 1093 | 1294 |
| 1094 /** | 1295 /** |
| 1095 * Keep the given [keepDescriptor], invalidate all the other results. | 1296 * Keep the given [keepDescriptor], invalidate all the other results. |
| 1096 */ | 1297 */ |
| 1097 class _KeepContinueDelta implements Delta { | 1298 class _KeepContinueDelta implements Delta { |
| 1098 final Source source; | 1299 final Source source; |
| 1099 final ResultDescriptor keepDescriptor; | 1300 final ResultDescriptor keepDescriptor; |
| 1100 | 1301 |
| 1101 _KeepContinueDelta(this.source, this.keepDescriptor); | 1302 _KeepContinueDelta(this.source, this.keepDescriptor); |
| 1102 | 1303 |
| 1103 @override | 1304 @override |
| 1305 bool get shouldGatherChanges => false; |
| 1306 |
| 1307 @override |
| 1308 bool gatherChanges(InternalAnalysisContext context, AnalysisTarget target, |
| 1309 ResultDescriptor descriptor, Object value) { |
| 1310 return false; |
| 1311 } |
| 1312 |
| 1313 @override |
| 1314 void gatherEnd() {} |
| 1315 |
| 1316 @override |
| 1104 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, | 1317 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, |
| 1105 ResultDescriptor descriptor) { | 1318 ResultDescriptor descriptor, Object value) { |
| 1106 if (descriptor == keepDescriptor) { | 1319 if (descriptor == keepDescriptor) { |
| 1107 return DeltaResult.KEEP_CONTINUE; | 1320 return DeltaResult.KEEP_CONTINUE; |
| 1108 } | 1321 } |
| 1109 return DeltaResult.INVALIDATE; | 1322 return DeltaResult.INVALIDATE; |
| 1110 } | 1323 } |
| 1111 } | 1324 } |
| 1112 | 1325 |
| 1113 class _TestAnalysisTarget implements AnalysisTarget { | 1326 class _TestAnalysisTarget implements AnalysisTarget { |
| 1114 @override | 1327 final Source librarySource; |
| 1115 Source get source => null; | 1328 final Source source; |
| 1329 _TestAnalysisTarget({this.librarySource, this.source}); |
| 1116 } | 1330 } |
| OLD | NEW |