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

Side by Side Diff: pkg/analyzer/test/src/context/cache_test.dart

Issue 1121963002: Record dependencies and invalidate results. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 test.src.task.driver_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart' 9 import 'package:analyzer/src/generated/engine.dart'
10 show AnalysisContext, CacheState, RetentionPriority; 10 show AnalysisContext, CacheState, RetentionPriority;
(...skipping 10 matching lines...) Expand all
21 21
22 main() { 22 main() {
23 groupSep = ' | '; 23 groupSep = ' | ';
24 runReflectiveTests(AnalysisCacheTest); 24 runReflectiveTests(AnalysisCacheTest);
25 runReflectiveTests(CacheEntryTest); 25 runReflectiveTests(CacheEntryTest);
26 runReflectiveTests(SdkCachePartitionTest); 26 runReflectiveTests(SdkCachePartitionTest);
27 runReflectiveTests(UniversalCachePartitionTest); 27 runReflectiveTests(UniversalCachePartitionTest);
28 runReflectiveTests(ResultDataTest); 28 runReflectiveTests(ResultDataTest);
29 } 29 }
30 30
31 AnalysisCache _createCache({AnalysisContext context,
Brian Wilkerson 2015/05/03 15:35:33 Is there a reason for making this private?
scheglov 2015/05/03 20:26:28 No, nothing new. I will make it public.
32 RetentionPriority policy: RetentionPriority.LOW}) {
33 CachePartition partition = new UniversalCachePartition(
34 context, 8, new TestCacheRetentionPolicy(policy));
35 return new AnalysisCache(<CachePartition>[partition]);
36 }
37
31 @reflectiveTest 38 @reflectiveTest
32 class AnalysisCacheTest extends EngineTestCase { 39 class AnalysisCacheTest extends EngineTestCase {
33 AnalysisCache createCache({AnalysisContext context,
34 RetentionPriority policy: RetentionPriority.LOW}) {
35 CachePartition partition = new UniversalCachePartition(
36 context, 8, new TestCacheRetentionPolicy(policy));
37 return new AnalysisCache(<CachePartition>[partition]);
38 }
39
40 void test_astSize_empty() { 40 void test_astSize_empty() {
41 AnalysisCache cache = createCache(); 41 AnalysisCache cache = _createCache();
42 expect(cache.astSize, 0); 42 expect(cache.astSize, 0);
43 } 43 }
44 44
45 void test_astSize_nonEmpty() { 45 void test_astSize_nonEmpty() {
46 ResultDescriptor result = new ResultDescriptor('test', null); 46 ResultDescriptor result = new ResultDescriptor('test', null);
47 AstNode node = new NullLiteral(null); 47 AstNode node = new NullLiteral(null);
48 AnalysisCache cache = createCache(); 48 AnalysisCache cache = _createCache();
49 AnalysisTarget target1 = new TestSource('/test1.dart'); 49 AnalysisTarget target1 = new TestSource('/test1.dart');
50 CacheEntry entry1 = new CacheEntry(); 50 CacheEntry entry1 = new CacheEntry();
51 entry1.setValue(result, node); 51 entry1.setValue(result, node, TargetedResult.EMPTY_LIST);
52 AnalysisTarget target2 = new TestSource('/test2.dart'); 52 AnalysisTarget target2 = new TestSource('/test2.dart');
53 CacheEntry entry2 = new CacheEntry(); 53 CacheEntry entry2 = new CacheEntry();
54 entry2.setValue(result, node); 54 entry2.setValue(result, node, TargetedResult.EMPTY_LIST);
55 cache.put(target1, entry1); 55 cache.put(target1, entry1);
56 cache.accessedAst(target1); 56 cache.accessedAst(target1);
57 cache.put(target2, entry2); 57 cache.put(target2, entry2);
58 cache.accessedAst(target2); 58 cache.accessedAst(target2);
59 expect(cache.astSize, 2); 59 expect(cache.astSize, 2);
60 } 60 }
61 61
62 void test_creation() { 62 void test_creation() {
63 expect(createCache(), isNotNull); 63 expect(_createCache(), isNotNull);
64 } 64 }
65 65
66 void test_get() { 66 void test_get() {
67 AnalysisCache cache = createCache(); 67 AnalysisCache cache = _createCache();
68 AnalysisTarget target = new TestSource(); 68 AnalysisTarget target = new TestSource();
69 expect(cache.get(target), isNull); 69 expect(cache.get(target), isNull);
70 } 70 }
71 71
72 void test_getContextFor() { 72 void test_getContextFor() {
73 AnalysisContext context = new TestAnalysisContext(); 73 AnalysisContext context = new TestAnalysisContext();
74 AnalysisCache cache = createCache(context: context); 74 AnalysisCache cache = _createCache(context: context);
75 AnalysisTarget target = new TestSource(); 75 AnalysisTarget target = new TestSource();
76 expect(cache.getContextFor(target), context); 76 expect(cache.getContextFor(target), context);
77 } 77 }
78 78
79 void test_iterator() { 79 void test_iterator() {
80 AnalysisCache cache = createCache(); 80 AnalysisCache cache = _createCache();
81 AnalysisTarget target = new TestSource(); 81 AnalysisTarget target = new TestSource();
82 CacheEntry entry = new CacheEntry(); 82 CacheEntry entry = new CacheEntry();
83 cache.put(target, entry); 83 cache.put(target, entry);
84 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); 84 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
85 expect(iterator.moveNext(), isTrue); 85 expect(iterator.moveNext(), isTrue);
86 expect(iterator.key, same(target)); 86 expect(iterator.key, same(target));
87 expect(iterator.value, same(entry)); 87 expect(iterator.value, same(entry));
88 expect(iterator.moveNext(), isFalse); 88 expect(iterator.moveNext(), isFalse);
89 } 89 }
90 90
91 void test_put() { 91 void test_put() {
92 AnalysisCache cache = createCache(); 92 AnalysisCache cache = _createCache();
93 AnalysisTarget target = new TestSource(); 93 AnalysisTarget target = new TestSource();
94 CacheEntry entry = new CacheEntry(); 94 CacheEntry entry = new CacheEntry();
95 expect(cache.get(target), isNull); 95 expect(cache.get(target), isNull);
96 cache.put(target, entry); 96 cache.put(target, entry);
97 expect(cache.get(target), entry); 97 expect(cache.get(target), entry);
98 } 98 }
99 99
100 void test_remove() { 100 void test_remove() {
101 AnalysisCache cache = createCache(); 101 AnalysisCache cache = _createCache();
102 AnalysisTarget target = new TestSource(); 102 AnalysisTarget target = new TestSource();
103 cache.remove(target); 103 cache.remove(target);
104 } 104 }
105 105
106 void test_setMaxCacheSize() { 106 void test_setMaxCacheSize() {
107 CachePartition partition = new UniversalCachePartition( 107 CachePartition partition = new UniversalCachePartition(
108 null, 8, new TestCacheRetentionPolicy(RetentionPriority.MEDIUM)); 108 null, 8, new TestCacheRetentionPolicy(RetentionPriority.MEDIUM));
109 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); 109 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]);
110 ResultDescriptor result = new ResultDescriptor('test', null); 110 ResultDescriptor result = new ResultDescriptor('test', null);
111 AstNode node = new NullLiteral(null); 111 AstNode node = new NullLiteral(null);
112 int size = 6; 112 int size = 6;
113 for (int i = 0; i < size; i++) { 113 for (int i = 0; i < size; i++) {
114 AnalysisTarget target = new TestSource("/test$i.dart"); 114 AnalysisTarget target = new TestSource("/test$i.dart");
115 CacheEntry entry = new CacheEntry(); 115 CacheEntry entry = new CacheEntry();
116 entry.setValue(result, node); 116 entry.setValue(result, node, TargetedResult.EMPTY_LIST);
117 cache.put(target, entry); 117 cache.put(target, entry);
118 cache.accessedAst(target); 118 cache.accessedAst(target);
119 } 119 }
120 120
121 void _assertNonFlushedCount(int expectedCount, AnalysisCache cache) { 121 void _assertNonFlushedCount(int expectedCount, AnalysisCache cache) {
122 int nonFlushedCount = 0; 122 int nonFlushedCount = 0;
123 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); 123 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
124 while (iterator.moveNext()) { 124 while (iterator.moveNext()) {
125 if (iterator.value.getState(result) != CacheState.FLUSHED) { 125 if (iterator.value.getState(result) != CacheState.FLUSHED) {
126 nonFlushedCount++; 126 nonFlushedCount++;
127 } 127 }
128 } 128 }
129 expect(nonFlushedCount, expectedCount); 129 expect(nonFlushedCount, expectedCount);
130 } 130 }
131 131
132 _assertNonFlushedCount(size, cache); 132 _assertNonFlushedCount(size, cache);
133 int newSize = size - 2; 133 int newSize = size - 2;
134 partition.maxCacheSize = newSize; 134 partition.maxCacheSize = newSize;
135 _assertNonFlushedCount(newSize, cache); 135 _assertNonFlushedCount(newSize, cache);
136 } 136 }
137 137
138 void test_size() { 138 void test_size() {
139 AnalysisCache cache = createCache(); 139 AnalysisCache cache = _createCache();
140 int size = 4; 140 int size = 4;
141 for (int i = 0; i < size; i++) { 141 for (int i = 0; i < size; i++) {
142 AnalysisTarget target = new TestSource("/test$i.dart"); 142 AnalysisTarget target = new TestSource("/test$i.dart");
143 cache.put(target, new CacheEntry()); 143 cache.put(target, new CacheEntry());
144 } 144 }
145 expect(cache.size(), size); 145 expect(cache.size(), size);
146 } 146 }
147 } 147 }
148 148
149 @reflectiveTest 149 @reflectiveTest
(...skipping 15 matching lines...) Expand all
165 expect(entry.exception, exception); 165 expect(entry.exception, exception);
166 } 166 }
167 167
168 test_fixExceptionState_noError_exception() { 168 test_fixExceptionState_noError_exception() {
169 ResultDescriptor result = new ResultDescriptor('test', null); 169 ResultDescriptor result = new ResultDescriptor('test', null);
170 CacheEntry entry = new CacheEntry(); 170 CacheEntry entry = new CacheEntry();
171 // set one result to ERROR 171 // set one result to ERROR
172 CaughtException exception = new CaughtException(null, null); 172 CaughtException exception = new CaughtException(null, null);
173 entry.setErrorState(exception, <ResultDescriptor>[result]); 173 entry.setErrorState(exception, <ResultDescriptor>[result]);
174 // set the same result to VALID 174 // set the same result to VALID
175 entry.setValue(result, 1); 175 entry.setValue(result, 1, TargetedResult.EMPTY_LIST);
176 // fix the exception state 176 // fix the exception state
177 entry.fixExceptionState(); 177 entry.fixExceptionState();
178 expect(entry.exception, isNull); 178 expect(entry.exception, isNull);
179 } 179 }
180 180
181 test_fixExceptionState_noError_noException() { 181 test_fixExceptionState_noError_noException() {
182 ResultDescriptor result = new ResultDescriptor('test', null); 182 ResultDescriptor result = new ResultDescriptor('test', null);
183 CacheEntry entry = new CacheEntry(); 183 CacheEntry entry = new CacheEntry();
184 entry.fixExceptionState(); 184 entry.fixExceptionState();
185 expect(entry.getState(result), CacheState.INVALID); 185 expect(entry.getState(result), CacheState.INVALID);
186 expect(entry.exception, isNull); 186 expect(entry.exception, isNull);
187 } 187 }
188 188
189 test_flushAstStructures() { 189 test_flushAstStructures() {
190 ResultDescriptor result = new ResultDescriptor('test', null); 190 ResultDescriptor result = new ResultDescriptor('test', null);
191 CacheEntry entry = new CacheEntry(); 191 CacheEntry entry = new CacheEntry();
192 entry.setValue(result, new NullLiteral(null)); 192 entry.setValue(result, new NullLiteral(null), TargetedResult.EMPTY_LIST);
193 expect(entry.hasAstStructure, true); 193 expect(entry.hasAstStructure, true);
194 entry.flushAstStructures(); 194 entry.flushAstStructures();
195 expect(entry.hasAstStructure, false); 195 expect(entry.hasAstStructure, false);
196 } 196 }
197 197
198 test_getState() { 198 test_getState() {
199 ResultDescriptor result = new ResultDescriptor('test', null); 199 ResultDescriptor result = new ResultDescriptor('test', null);
200 CacheEntry entry = new CacheEntry(); 200 CacheEntry entry = new CacheEntry();
201 expect(entry.getState(result), CacheState.INVALID); 201 expect(entry.getState(result), CacheState.INVALID);
202 } 202 }
203 203
204 test_getValue() { 204 test_getValue() {
205 String defaultValue = 'value'; 205 String defaultValue = 'value';
206 ResultDescriptor result = new ResultDescriptor('test', defaultValue); 206 ResultDescriptor result = new ResultDescriptor('test', defaultValue);
207 CacheEntry entry = new CacheEntry(); 207 CacheEntry entry = new CacheEntry();
208 expect(entry.getValue(result), defaultValue); 208 expect(entry.getValue(result), defaultValue);
209 } 209 }
210 210
211 test_hasAstStructure_false() { 211 test_hasAstStructure_false() {
212 CacheEntry entry = new CacheEntry(); 212 CacheEntry entry = new CacheEntry();
213 expect(entry.hasAstStructure, false); 213 expect(entry.hasAstStructure, false);
214 } 214 }
215 215
216 test_hasAstStructure_true() { 216 test_hasAstStructure_true() {
217 ResultDescriptor result = new ResultDescriptor('test', null); 217 ResultDescriptor result = new ResultDescriptor('test', null);
218 CacheEntry entry = new CacheEntry(); 218 CacheEntry entry = new CacheEntry();
219 entry.setValue(result, new NullLiteral(null)); 219 entry.setValue(result, new NullLiteral(null), TargetedResult.EMPTY_LIST);
220 expect(entry.hasAstStructure, true); 220 expect(entry.hasAstStructure, true);
221 } 221 }
222 222
223 test_hasErrorState_false() { 223 test_hasErrorState_false() {
224 CacheEntry entry = new CacheEntry(); 224 CacheEntry entry = new CacheEntry();
225 expect(entry.hasErrorState(), false); 225 expect(entry.hasErrorState(), false);
226 } 226 }
227 227
228 test_hasErrorState_true() { 228 test_hasErrorState_true() {
229 ResultDescriptor result = new ResultDescriptor('test', null); 229 ResultDescriptor result = new ResultDescriptor('test', null);
230 CaughtException exception = new CaughtException(null, null); 230 CaughtException exception = new CaughtException(null, null);
231 CacheEntry entry = new CacheEntry(); 231 CacheEntry entry = new CacheEntry();
232 entry.setErrorState(exception, <ResultDescriptor>[result]); 232 entry.setErrorState(exception, <ResultDescriptor>[result]);
233 expect(entry.hasErrorState(), true); 233 expect(entry.hasErrorState(), true);
234 } 234 }
235 235
236 test_invalidateAllInformation() { 236 test_invalidateAllInformation() {
237 ResultDescriptor result = new ResultDescriptor('test', null); 237 ResultDescriptor result = new ResultDescriptor('test', null);
238 CacheEntry entry = new CacheEntry(); 238 CacheEntry entry = new CacheEntry();
239 entry.setValue(result, 'value'); 239 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST);
240 entry.invalidateAllInformation(); 240 entry.invalidateAllInformation();
241 expect(entry.getState(result), CacheState.INVALID); 241 expect(entry.getState(result), CacheState.INVALID);
242 expect(entry.getValue(result), isNull); 242 expect(entry.getValue(result), isNull);
243 } 243 }
244 244
245 test_setErrorState() { 245 test_setErrorState() {
246 ResultDescriptor result1 = new ResultDescriptor('res1', 1); 246 ResultDescriptor result1 = new ResultDescriptor('res1', 1);
247 ResultDescriptor result2 = new ResultDescriptor('res2', 2); 247 ResultDescriptor result2 = new ResultDescriptor('res2', 2);
248 ResultDescriptor result3 = new ResultDescriptor('res3', 3); 248 ResultDescriptor result3 = new ResultDescriptor('res3', 3);
249 // prepare some good state 249 // prepare some good state
250 CacheEntry entry = new CacheEntry(); 250 CacheEntry entry = new CacheEntry();
251 entry.setValue(result1, 10); 251 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST);
252 entry.setValue(result2, 20); 252 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST);
253 entry.setValue(result3, 30); 253 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST);
254 // set error state 254 // set error state
255 CaughtException exception = new CaughtException(null, null); 255 CaughtException exception = new CaughtException(null, null);
256 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); 256 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]);
257 // verify 257 // verify
258 expect(entry.exception, exception); 258 expect(entry.exception, exception);
259 expect(entry.getState(result1), CacheState.ERROR); 259 expect(entry.getState(result1), CacheState.ERROR);
260 expect(entry.getState(result2), CacheState.ERROR); 260 expect(entry.getState(result2), CacheState.ERROR);
261 expect(entry.getState(result3), CacheState.VALID); 261 expect(entry.getState(result3), CacheState.VALID);
262 expect(entry.getValue(result1), 1); 262 expect(entry.getValue(result1), 1);
263 expect(entry.getValue(result2), 2); 263 expect(entry.getValue(result2), 2);
264 expect(entry.getValue(result3), 30); 264 expect(entry.getValue(result3), 30);
265 } 265 }
266 266
267 test_setErrorState_invalidateDependent() {
268 AnalysisCache cache = _createCache();
269 AnalysisTarget target = new TestSource();
270 CacheEntry entry = new CacheEntry();
271 cache.put(target, entry);
272 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
273 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
274 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
275 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
276 // set results, all of them are VALID
277 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
278 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
279 entry.setValue(result3, 333, [new TargetedResult(target, result2)]);
280 entry.setValue(result4, 444, []);
281 expect(entry.getState(result1), CacheState.VALID);
282 expect(entry.getState(result2), CacheState.VALID);
283 expect(entry.getState(result3), CacheState.VALID);
284 expect(entry.getState(result4), CacheState.VALID);
285 expect(entry.getValue(result1), 111);
286 expect(entry.getValue(result2), 222);
287 expect(entry.getValue(result3), 333);
288 expect(entry.getValue(result4), 444);
289 // set error state
290 CaughtException exception = new CaughtException(null, null);
291 entry.setErrorState(exception, <ResultDescriptor>[result1]);
292 // result2 and result3 are invalidated, result4 is intact
293 expect(entry.getState(result1), CacheState.ERROR);
294 expect(entry.getState(result2), CacheState.INVALID);
Brian Wilkerson 2015/05/03 15:35:33 I'd need to look at the code or write some test co
scheglov 2015/05/03 20:26:28 Yes, I was pondering this too. Done.
295 expect(entry.getState(result3), CacheState.INVALID);
296 expect(entry.getState(result4), CacheState.VALID);
297 expect(entry.getValue(result1), -1);
298 expect(entry.getValue(result2), -2);
299 expect(entry.getValue(result3), -3);
300 expect(entry.getValue(result4), 444);
301 }
302
267 test_setErrorState_noDescriptors() { 303 test_setErrorState_noDescriptors() {
268 CaughtException exception = new CaughtException(null, null); 304 CaughtException exception = new CaughtException(null, null);
269 CacheEntry entry = new CacheEntry(); 305 CacheEntry entry = new CacheEntry();
270 expect(() { 306 expect(() {
271 entry.setErrorState(exception, <ResultDescriptor>[]); 307 entry.setErrorState(exception, <ResultDescriptor>[]);
272 }, throwsArgumentError); 308 }, throwsArgumentError);
273 } 309 }
274 310
275 test_setErrorState_noException() { 311 test_setErrorState_noException() {
276 ResultDescriptor result = new ResultDescriptor('test', null); 312 ResultDescriptor result = new ResultDescriptor('test', null);
277 CacheEntry entry = new CacheEntry(); 313 CacheEntry entry = new CacheEntry();
278 expect(() { 314 expect(() {
279 entry.setErrorState(null, <ResultDescriptor>[result]); 315 entry.setErrorState(null, <ResultDescriptor>[result]);
280 }, throwsArgumentError); 316 }, throwsArgumentError);
281 } 317 }
282 318
283 test_setErrorState_nullDescriptors() { 319 test_setErrorState_nullDescriptors() {
284 CaughtException exception = new CaughtException(null, null); 320 CaughtException exception = new CaughtException(null, null);
285 CacheEntry entry = new CacheEntry(); 321 CacheEntry entry = new CacheEntry();
286 expect(() { 322 expect(() {
287 entry.setErrorState(exception, null); 323 entry.setErrorState(exception, null);
288 }, throwsArgumentError); 324 }, throwsArgumentError);
289 } 325 }
290 326
291 test_setState_error() { 327 test_setState_error() {
292 ResultDescriptor result = new ResultDescriptor('test', null); 328 ResultDescriptor result = new ResultDescriptor('test', null);
293 CacheEntry entry = new CacheEntry(); 329 CacheEntry entry = new CacheEntry();
294 entry.setValue(result, 42); 330 entry.setValue(result, 42, TargetedResult.EMPTY_LIST);
295 // an invalid state change 331 // an invalid state change
296 expect(() { 332 expect(() {
297 entry.setState(result, CacheState.ERROR); 333 entry.setState(result, CacheState.ERROR);
298 }, throwsArgumentError); 334 }, throwsArgumentError);
299 // no changes 335 // no changes
300 expect(entry.getState(result), CacheState.VALID); 336 expect(entry.getState(result), CacheState.VALID);
301 expect(entry.getValue(result), 42); 337 expect(entry.getValue(result), 42);
302 } 338 }
303 339
304 test_setState_flushed() { 340 test_setState_flushed() {
305 ResultDescriptor result = new ResultDescriptor('test', 1); 341 ResultDescriptor result = new ResultDescriptor('test', 1);
306 CacheEntry entry = new CacheEntry(); 342 CacheEntry entry = new CacheEntry();
307 // set VALID 343 // set VALID
308 entry.setValue(result, 10); 344 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
309 expect(entry.getState(result), CacheState.VALID); 345 expect(entry.getState(result), CacheState.VALID);
310 expect(entry.getValue(result), 10); 346 expect(entry.getValue(result), 10);
311 // set FLUSHED 347 // set FLUSHED
312 entry.setState(result, CacheState.FLUSHED); 348 entry.setState(result, CacheState.FLUSHED);
313 expect(entry.getState(result), CacheState.FLUSHED); 349 expect(entry.getState(result), CacheState.FLUSHED);
314 expect(entry.getValue(result), 1); 350 expect(entry.getValue(result), 1);
315 } 351 }
316 352
317 test_setState_inProcess() { 353 test_setState_inProcess() {
318 ResultDescriptor result = new ResultDescriptor('test', 1); 354 ResultDescriptor result = new ResultDescriptor('test', 1);
319 CacheEntry entry = new CacheEntry(); 355 CacheEntry entry = new CacheEntry();
320 // set VALID 356 // set VALID
321 entry.setValue(result, 10); 357 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
322 expect(entry.getState(result), CacheState.VALID); 358 expect(entry.getState(result), CacheState.VALID);
323 expect(entry.getValue(result), 10); 359 expect(entry.getValue(result), 10);
324 // set IN_PROCESS 360 // set IN_PROCESS
325 entry.setState(result, CacheState.IN_PROCESS); 361 entry.setState(result, CacheState.IN_PROCESS);
326 expect(entry.getState(result), CacheState.IN_PROCESS); 362 expect(entry.getState(result), CacheState.IN_PROCESS);
327 expect(entry.getValue(result), 10); 363 expect(entry.getValue(result), 10);
328 } 364 }
329 365
330 test_setState_invalid() { 366 test_setState_invalid() {
331 ResultDescriptor result = new ResultDescriptor('test', 1); 367 ResultDescriptor result = new ResultDescriptor('test', 1);
332 CacheEntry entry = new CacheEntry(); 368 CacheEntry entry = new CacheEntry();
333 // set VALID 369 // set VALID
334 entry.setValue(result, 10); 370 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
335 expect(entry.getState(result), CacheState.VALID); 371 expect(entry.getState(result), CacheState.VALID);
336 expect(entry.getValue(result), 10); 372 expect(entry.getValue(result), 10);
337 // set INVALID 373 // set INVALID
338 entry.setState(result, CacheState.INVALID); 374 entry.setState(result, CacheState.INVALID);
339 expect(entry.getState(result), CacheState.INVALID); 375 expect(entry.getState(result), CacheState.INVALID);
340 expect(entry.getValue(result), 1); 376 expect(entry.getValue(result), 1);
341 } 377 }
342 378
379 test_setState_invalid_invalidateDependent() {
380 AnalysisCache cache = _createCache();
381 AnalysisTarget target = new TestSource();
382 CacheEntry entry = new CacheEntry();
383 cache.put(target, entry);
384 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
385 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
386 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
387 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
388 // set results, all of them are VALID
389 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
390 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
391 entry.setValue(result3, 333, [new TargetedResult(target, result2)]);
392 entry.setValue(result4, 444, []);
393 expect(entry.getState(result1), CacheState.VALID);
394 expect(entry.getState(result2), CacheState.VALID);
395 expect(entry.getState(result3), CacheState.VALID);
396 expect(entry.getState(result4), CacheState.VALID);
397 expect(entry.getValue(result1), 111);
398 expect(entry.getValue(result2), 222);
399 expect(entry.getValue(result3), 333);
400 expect(entry.getValue(result4), 444);
401 // invalidate result1, invalidates result2 and result3, result4 is intact
402 entry.setState(result1, CacheState.INVALID);
403 expect(entry.getState(result1), CacheState.INVALID);
404 expect(entry.getState(result2), CacheState.INVALID);
405 expect(entry.getState(result3), CacheState.INVALID);
406 expect(entry.getState(result4), CacheState.VALID);
407 expect(entry.getValue(result1), -1);
408 expect(entry.getValue(result2), -2);
409 expect(entry.getValue(result3), -3);
410 expect(entry.getValue(result4), 444);
411 }
412
343 test_setState_valid() { 413 test_setState_valid() {
344 ResultDescriptor result = new ResultDescriptor('test', null); 414 ResultDescriptor result = new ResultDescriptor('test', null);
345 CacheEntry entry = new CacheEntry(); 415 CacheEntry entry = new CacheEntry();
346 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); 416 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError);
347 } 417 }
348 418
349 test_setValue() { 419 test_setValue() {
350 String value = 'value'; 420 String value = 'value';
351 ResultDescriptor result = new ResultDescriptor('test', null); 421 ResultDescriptor result = new ResultDescriptor('test', null);
352 CacheEntry entry = new CacheEntry(); 422 CacheEntry entry = new CacheEntry();
353 entry.setValue(result, value); 423 entry.setValue(result, value, TargetedResult.EMPTY_LIST);
354 expect(entry.getState(result), CacheState.VALID); 424 expect(entry.getState(result), CacheState.VALID);
355 expect(entry.getValue(result), value); 425 expect(entry.getValue(result), value);
356 } 426 }
357 427
428 test_setValue_invalidateDependent() {
429 AnalysisCache cache = _createCache();
430 AnalysisTarget target = new TestSource();
431 CacheEntry entry = new CacheEntry();
432 cache.put(target, entry);
433 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
434 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
435 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
436 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
437 // set results, all of them are VALID
438 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
439 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
440 entry.setValue(result3, 333, [new TargetedResult(target, result2)]);
441 entry.setValue(result4, 444, []);
442 expect(entry.getState(result1), CacheState.VALID);
443 expect(entry.getState(result2), CacheState.VALID);
444 expect(entry.getState(result3), CacheState.VALID);
445 expect(entry.getState(result4), CacheState.VALID);
446 expect(entry.getValue(result1), 111);
447 expect(entry.getValue(result2), 222);
448 expect(entry.getValue(result3), 333);
449 expect(entry.getValue(result4), 444);
450 // set result1, invalidates result2 and result3, result4 is intact
451 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST);
452 expect(entry.getState(result1), CacheState.VALID);
453 expect(entry.getState(result2), CacheState.INVALID);
454 expect(entry.getState(result3), CacheState.INVALID);
455 expect(entry.getState(result4), CacheState.VALID);
456 expect(entry.getValue(result1), 1111);
457 expect(entry.getValue(result2), -2);
458 expect(entry.getValue(result3), -3);
459 expect(entry.getValue(result4), 444);
460 }
461
462 test_setValue_invalidateDependent2() {
463 AnalysisCache cache = _createCache();
464 AnalysisTarget target1 = new TestSource('a');
465 AnalysisTarget target2 = new TestSource('b');
466 CacheEntry entry1 = new CacheEntry();
467 CacheEntry entry2 = new CacheEntry();
468 cache.put(target1, entry1);
469 cache.put(target2, entry2);
470 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
471 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
472 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
473 // set results, all of them are VALID
474 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
475 entry1.setValue(result2, 222, [new TargetedResult(target1, result1)]);
476 entry2.setValue(result3, 333, [new TargetedResult(target1, result2)]);
477 expect(entry1.getState(result1), CacheState.VALID);
478 expect(entry1.getState(result2), CacheState.VALID);
479 expect(entry2.getState(result3), CacheState.VALID);
480 expect(entry1.getValue(result1), 111);
481 expect(entry1.getValue(result2), 222);
482 expect(entry2.getValue(result3), 333);
483 // set result1, invalidates result2 and result3
484 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST);
485 expect(entry1.getState(result1), CacheState.VALID);
486 expect(entry1.getState(result2), CacheState.INVALID);
487 expect(entry2.getState(result3), CacheState.INVALID);
488 expect(entry1.getValue(result1), 1111);
489 expect(entry1.getValue(result2), -2);
490 expect(entry2.getValue(result3), -3);
491 }
492
358 test_toString_empty() { 493 test_toString_empty() {
359 CacheEntry entry = new CacheEntry(); 494 CacheEntry entry = new CacheEntry();
360 expect(entry.toString(), isNotNull); 495 expect(entry.toString(), isNotNull);
361 } 496 }
362 497
363 test_toString_nonEmpty() { 498 test_toString_nonEmpty() {
364 String value = 'value'; 499 String value = 'value';
365 ResultDescriptor result = new ResultDescriptor('test', null); 500 ResultDescriptor result = new ResultDescriptor('test', null);
366 CacheEntry entry = new CacheEntry(); 501 CacheEntry entry = new CacheEntry();
367 entry.setValue(result, value); 502 entry.setValue(result, value, TargetedResult.EMPTY_LIST);
368 expect(entry.toString(), isNotNull); 503 expect(entry.toString(), isNotNull);
369 } 504 }
370 } 505 }
371 506
372 abstract class CachePartitionTest extends EngineTestCase { 507 abstract class CachePartitionTest extends EngineTestCase {
373 CachePartition createPartition([CacheRetentionPolicy policy = null]); 508 CachePartition createPartition([CacheRetentionPolicy policy = null]);
374 509
375 void test_creation() { 510 void test_creation() {
376 expect(createPartition(), isNotNull); 511 expect(createPartition(), isNotNull);
377 } 512 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 549
415 void test_setMaxCacheSize() { 550 void test_setMaxCacheSize() {
416 CachePartition partition = 551 CachePartition partition =
417 createPartition(new TestCacheRetentionPolicy(RetentionPriority.LOW)); 552 createPartition(new TestCacheRetentionPolicy(RetentionPriority.LOW));
418 ResultDescriptor result = new ResultDescriptor('result', null); 553 ResultDescriptor result = new ResultDescriptor('result', null);
419 NullLiteral node = new NullLiteral(null); 554 NullLiteral node = new NullLiteral(null);
420 int size = 6; // Must be <= partition.maxCacheSize 555 int size = 6; // Must be <= partition.maxCacheSize
421 for (int i = 0; i < size; i++) { 556 for (int i = 0; i < size; i++) {
422 AnalysisTarget target = new TestSource("/test$i.dart"); 557 AnalysisTarget target = new TestSource("/test$i.dart");
423 CacheEntry entry = new CacheEntry(); 558 CacheEntry entry = new CacheEntry();
424 entry.setValue(result, node); 559 entry.setValue(result, node, TargetedResult.EMPTY_LIST);
425 partition.put(target, entry); 560 partition.put(target, entry);
426 partition.accessedAst(target); 561 partition.accessedAst(target);
427 } 562 }
428 563
429 void assertNonFlushedCount(int expectedCount, CachePartition partition) { 564 void assertNonFlushedCount(int expectedCount, CachePartition partition) {
430 int nonFlushedCount = 0; 565 int nonFlushedCount = 0;
431 Map<AnalysisTarget, CacheEntry> entryMap = partition.map; 566 Map<AnalysisTarget, CacheEntry> entryMap = partition.map;
432 entryMap.values.forEach((CacheEntry entry) { 567 entryMap.values.forEach((CacheEntry entry) {
433 if (entry.getState(result) != CacheState.FLUSHED) { 568 if (entry.getState(result) != CacheState.FLUSHED) {
434 nonFlushedCount++; 569 nonFlushedCount++;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return new UniversalCachePartition(null, 8, policy); 639 return new UniversalCachePartition(null, 8, policy);
505 } 640 }
506 641
507 void test_contains() { 642 void test_contains() {
508 UniversalCachePartition partition = 643 UniversalCachePartition partition =
509 new UniversalCachePartition(null, 8, null); 644 new UniversalCachePartition(null, 8, null);
510 TestSource source = new TestSource(); 645 TestSource source = new TestSource();
511 expect(partition.contains(source), isTrue); 646 expect(partition.contains(source), isTrue);
512 } 647 }
513 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698