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

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

Issue 1135613002: Set CacheEntry.target in the contructor. (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
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/engine.dart' 8 import 'package:analyzer/src/generated/engine.dart'
9 show 9 show
10 AnalysisContext, 10 AnalysisContext,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 void test_getContextFor() { 55 void test_getContextFor() {
56 AnalysisContext context = new TestAnalysisContext(); 56 AnalysisContext context = new TestAnalysisContext();
57 AnalysisCache cache = createCache(context: context); 57 AnalysisCache cache = createCache(context: context);
58 AnalysisTarget target = new TestSource(); 58 AnalysisTarget target = new TestSource();
59 expect(cache.getContextFor(target), context); 59 expect(cache.getContextFor(target), context);
60 } 60 }
61 61
62 void test_iterator() { 62 void test_iterator() {
63 AnalysisCache cache = createCache(); 63 AnalysisCache cache = createCache();
64 AnalysisTarget target = new TestSource(); 64 AnalysisTarget target = new TestSource();
65 CacheEntry entry = new CacheEntry(); 65 CacheEntry entry = new CacheEntry(target);
66 cache.put(target, entry); 66 cache.put(entry);
67 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); 67 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
68 expect(iterator.moveNext(), isTrue); 68 expect(iterator.moveNext(), isTrue);
69 expect(iterator.key, same(target)); 69 expect(iterator.key, same(target));
70 expect(iterator.value, same(entry)); 70 expect(iterator.value, same(entry));
71 expect(iterator.moveNext(), isFalse); 71 expect(iterator.moveNext(), isFalse);
72 } 72 }
73 73
74 void test_put() { 74 void test_put() {
75 AnalysisCache cache = createCache(); 75 AnalysisCache cache = createCache();
76 AnalysisTarget target = new TestSource(); 76 AnalysisTarget target = new TestSource();
77 CacheEntry entry = new CacheEntry(); 77 CacheEntry entry = new CacheEntry(target);
78 expect(cache.get(target), isNull); 78 expect(cache.get(target), isNull);
79 cache.put(target, entry); 79 cache.put(entry);
80 expect(cache.get(target), entry); 80 expect(cache.get(target), entry);
81 } 81 }
82 82
83 void test_remove() { 83 void test_remove() {
84 AnalysisCache cache = createCache(); 84 AnalysisCache cache = createCache();
85 AnalysisTarget target = new TestSource(); 85 AnalysisTarget target = new TestSource();
86 cache.remove(target); 86 cache.remove(target);
87 } 87 }
88 88
89 void test_size() { 89 void test_size() {
90 AnalysisCache cache = createCache(); 90 AnalysisCache cache = createCache();
91 int size = 4; 91 int size = 4;
92 for (int i = 0; i < size; i++) { 92 for (int i = 0; i < size; i++) {
93 AnalysisTarget target = new TestSource("/test$i.dart"); 93 AnalysisTarget target = new TestSource("/test$i.dart");
94 cache.put(target, new CacheEntry()); 94 cache.put(new CacheEntry(target));
95 } 95 }
96 expect(cache.size(), size); 96 expect(cache.size(), size);
97 } 97 }
98 } 98 }
99 99
100 @reflectiveTest 100 @reflectiveTest
101 class CacheEntryTest extends EngineTestCase { 101 class CacheEntryTest extends EngineTestCase {
102 InternalAnalysisContext context; 102 InternalAnalysisContext context;
103 AnalysisCache cache; 103 AnalysisCache cache;
104 104
105 void setUp() { 105 void setUp() {
106 context = new _InternalAnalysisContextMock(); 106 context = new _InternalAnalysisContextMock();
107 when(context.priorityTargets).thenReturn([]); 107 when(context.priorityTargets).thenReturn([]);
108 cache = createCache(context: context); 108 cache = createCache(context: context);
109 when(context.analysisCache).thenReturn(cache); 109 when(context.analysisCache).thenReturn(cache);
110 } 110 }
111 111
112 test_explicitlyAdded() { 112 test_explicitlyAdded() {
113 CacheEntry entry = new CacheEntry(); 113 AnalysisTarget target = new TestSource();
114 CacheEntry entry = new CacheEntry(target);
114 expect(entry.explicitlyAdded, false); 115 expect(entry.explicitlyAdded, false);
115 entry.explicitlyAdded = true; 116 entry.explicitlyAdded = true;
116 expect(entry.explicitlyAdded, true); 117 expect(entry.explicitlyAdded, true);
117 } 118 }
118 119
119 test_fixExceptionState_error_exception() { 120 test_fixExceptionState_error_exception() {
121 AnalysisTarget target = new TestSource();
120 ResultDescriptor result = new ResultDescriptor('test', null); 122 ResultDescriptor result = new ResultDescriptor('test', null);
121 CaughtException exception = new CaughtException(null, null); 123 CaughtException exception = new CaughtException(null, null);
122 CacheEntry entry = new CacheEntry(); 124 CacheEntry entry = new CacheEntry(target);
123 entry.setErrorState(exception, <ResultDescriptor>[result]); 125 entry.setErrorState(exception, <ResultDescriptor>[result]);
124 entry.fixExceptionState(); 126 entry.fixExceptionState();
125 expect(entry.getState(result), CacheState.ERROR); 127 expect(entry.getState(result), CacheState.ERROR);
126 expect(entry.exception, exception); 128 expect(entry.exception, exception);
127 } 129 }
128 130
129 test_fixExceptionState_noError_exception() { 131 test_fixExceptionState_noError_exception() {
132 AnalysisTarget target = new TestSource();
130 ResultDescriptor result = new ResultDescriptor('test', null); 133 ResultDescriptor result = new ResultDescriptor('test', null);
131 CacheEntry entry = new CacheEntry(); 134 CacheEntry entry = new CacheEntry(target);
132 // set one result to ERROR 135 // set one result to ERROR
133 CaughtException exception = new CaughtException(null, null); 136 CaughtException exception = new CaughtException(null, null);
134 entry.setErrorState(exception, <ResultDescriptor>[result]); 137 entry.setErrorState(exception, <ResultDescriptor>[result]);
135 // set the same result to VALID 138 // set the same result to VALID
136 entry.setValue(result, 1, TargetedResult.EMPTY_LIST, null); 139 entry.setValue(result, 1, TargetedResult.EMPTY_LIST, null);
137 // fix the exception state 140 // fix the exception state
138 entry.fixExceptionState(); 141 entry.fixExceptionState();
139 expect(entry.exception, isNull); 142 expect(entry.exception, isNull);
140 } 143 }
141 144
142 test_fixExceptionState_noError_noException() { 145 test_fixExceptionState_noError_noException() {
146 AnalysisTarget target = new TestSource();
143 ResultDescriptor result = new ResultDescriptor('test', null); 147 ResultDescriptor result = new ResultDescriptor('test', null);
144 CacheEntry entry = new CacheEntry(); 148 CacheEntry entry = new CacheEntry(target);
145 entry.fixExceptionState(); 149 entry.fixExceptionState();
146 expect(entry.getState(result), CacheState.INVALID); 150 expect(entry.getState(result), CacheState.INVALID);
147 expect(entry.exception, isNull); 151 expect(entry.exception, isNull);
148 } 152 }
149 153
150 test_getMemento_noResult() { 154 test_getMemento_noResult() {
151 String defaultValue = 'value'; 155 AnalysisTarget target = new TestSource();
152 ResultDescriptor result = new ResultDescriptor('test', defaultValue); 156 ResultDescriptor result = new ResultDescriptor('test', null);
153 CacheEntry entry = new CacheEntry(); 157 CacheEntry entry = new CacheEntry(target);
154 expect(entry.getMemento(result), null); 158 expect(entry.getMemento(result), null);
155 } 159 }
156 160
157 test_getState() { 161 test_getState() {
162 AnalysisTarget target = new TestSource();
158 ResultDescriptor result = new ResultDescriptor('test', null); 163 ResultDescriptor result = new ResultDescriptor('test', null);
159 CacheEntry entry = new CacheEntry(); 164 CacheEntry entry = new CacheEntry(target);
160 expect(entry.getState(result), CacheState.INVALID); 165 expect(entry.getState(result), CacheState.INVALID);
161 } 166 }
162 167
163 test_getValue() { 168 test_getValue_default() {
169 AnalysisTarget target = new TestSource();
164 String defaultValue = 'value'; 170 String defaultValue = 'value';
165 ResultDescriptor result = new ResultDescriptor('test', defaultValue); 171 ResultDescriptor result = new ResultDescriptor('test', defaultValue);
166 CacheEntry entry = new CacheEntry(); 172 CacheEntry entry = new CacheEntry(target);
167 expect(entry.getValue(result), defaultValue); 173 expect(entry.getValue(result), defaultValue);
168 } 174 }
169 175
170 test_getValue_flushResults() { 176 test_getValue_flushResults() {
171 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); 177 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2);
172 ResultDescriptor descriptor1 = 178 ResultDescriptor descriptor1 =
173 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); 179 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy);
174 ResultDescriptor descriptor2 = 180 ResultDescriptor descriptor2 =
175 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); 181 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy);
176 ResultDescriptor descriptor3 = 182 ResultDescriptor descriptor3 =
177 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); 183 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy);
178 AnalysisTarget target = new TestSource(); 184 AnalysisTarget target = new TestSource();
179 CacheEntry entry = new CacheEntry(); 185 CacheEntry entry = new CacheEntry(target);
180 cache.put(target, entry); 186 cache.put(entry);
181 { 187 {
182 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, null); 188 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, null);
183 expect(entry.getState(descriptor1), CacheState.VALID); 189 expect(entry.getState(descriptor1), CacheState.VALID);
184 } 190 }
185 { 191 {
186 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null); 192 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null);
187 expect(entry.getState(descriptor1), CacheState.VALID); 193 expect(entry.getState(descriptor1), CacheState.VALID);
188 expect(entry.getState(descriptor2), CacheState.VALID); 194 expect(entry.getState(descriptor2), CacheState.VALID);
189 } 195 }
190 // get descriptor1, so that descriptor2 will be flushed 196 // get descriptor1, so that descriptor2 will be flushed
191 entry.getValue(descriptor1); 197 entry.getValue(descriptor1);
192 { 198 {
193 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null); 199 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null);
194 expect(entry.getState(descriptor1), CacheState.VALID); 200 expect(entry.getState(descriptor1), CacheState.VALID);
195 expect(entry.getState(descriptor2), CacheState.FLUSHED); 201 expect(entry.getState(descriptor2), CacheState.FLUSHED);
196 expect(entry.getState(descriptor3), CacheState.VALID); 202 expect(entry.getState(descriptor3), CacheState.VALID);
197 } 203 }
198 } 204 }
199 205
200 test_hasErrorState_false() { 206 test_hasErrorState_false() {
201 CacheEntry entry = new CacheEntry(); 207 AnalysisTarget target = new TestSource();
208 CacheEntry entry = new CacheEntry(target);
202 expect(entry.hasErrorState(), false); 209 expect(entry.hasErrorState(), false);
203 } 210 }
204 211
205 test_hasErrorState_true() { 212 test_hasErrorState_true() {
213 AnalysisTarget target = new TestSource();
206 ResultDescriptor result = new ResultDescriptor('test', null); 214 ResultDescriptor result = new ResultDescriptor('test', null);
207 CaughtException exception = new CaughtException(null, null); 215 CaughtException exception = new CaughtException(null, null);
208 CacheEntry entry = new CacheEntry(); 216 CacheEntry entry = new CacheEntry(target);
209 entry.setErrorState(exception, <ResultDescriptor>[result]); 217 entry.setErrorState(exception, <ResultDescriptor>[result]);
210 expect(entry.hasErrorState(), true); 218 expect(entry.hasErrorState(), true);
211 } 219 }
212 220
213 test_invalidateAllInformation() { 221 test_invalidateAllInformation() {
222 AnalysisTarget target = new TestSource();
214 ResultDescriptor result = new ResultDescriptor('test', null); 223 ResultDescriptor result = new ResultDescriptor('test', null);
215 CacheEntry entry = new CacheEntry(); 224 CacheEntry entry = new CacheEntry(target);
216 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST, null); 225 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST, null);
217 entry.invalidateAllInformation(); 226 entry.invalidateAllInformation();
218 expect(entry.getState(result), CacheState.INVALID); 227 expect(entry.getState(result), CacheState.INVALID);
219 expect(entry.getValue(result), isNull); 228 expect(entry.getValue(result), isNull);
220 } 229 }
221 230
222 test_setErrorState() { 231 test_setErrorState() {
232 AnalysisTarget target = new TestSource();
223 ResultDescriptor result1 = new ResultDescriptor('res1', 1); 233 ResultDescriptor result1 = new ResultDescriptor('res1', 1);
224 ResultDescriptor result2 = new ResultDescriptor('res2', 2); 234 ResultDescriptor result2 = new ResultDescriptor('res2', 2);
225 ResultDescriptor result3 = new ResultDescriptor('res3', 3); 235 ResultDescriptor result3 = new ResultDescriptor('res3', 3);
226 // prepare some good state 236 // prepare some good state
227 CacheEntry entry = new CacheEntry(); 237 CacheEntry entry = new CacheEntry(target);
228 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST, null); 238 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST, null);
229 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST, null); 239 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST, null);
230 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST, null); 240 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST, null);
231 // set error state 241 // set error state
232 CaughtException exception = new CaughtException(null, null); 242 CaughtException exception = new CaughtException(null, null);
233 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); 243 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]);
234 // verify 244 // verify
235 expect(entry.exception, exception); 245 expect(entry.exception, exception);
236 expect(entry.getState(result1), CacheState.ERROR); 246 expect(entry.getState(result1), CacheState.ERROR);
237 expect(entry.getState(result2), CacheState.ERROR); 247 expect(entry.getState(result2), CacheState.ERROR);
238 expect(entry.getState(result3), CacheState.VALID); 248 expect(entry.getState(result3), CacheState.VALID);
239 expect(entry.getValue(result1), 1); 249 expect(entry.getValue(result1), 1);
240 expect(entry.getValue(result2), 2); 250 expect(entry.getValue(result2), 2);
241 expect(entry.getValue(result3), 30); 251 expect(entry.getValue(result3), 30);
242 } 252 }
243 253
244 test_setErrorState_invalidateDependent() { 254 test_setErrorState_invalidateDependent() {
245 AnalysisTarget target1 = new TestSource('/a.dart'); 255 AnalysisTarget target1 = new TestSource('/a.dart');
246 AnalysisTarget target2 = new TestSource('/b.dart'); 256 AnalysisTarget target2 = new TestSource('/b.dart');
247 CacheEntry entry1 = new CacheEntry(); 257 CacheEntry entry1 = new CacheEntry(target1);
248 CacheEntry entry2 = new CacheEntry(); 258 CacheEntry entry2 = new CacheEntry(target2);
249 cache.put(target1, entry1); 259 cache.put(entry1);
250 cache.put(target2, entry2); 260 cache.put(entry2);
251 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 261 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
252 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 262 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
253 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 263 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
254 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 264 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
255 // set results, all of them are VALID 265 // set results, all of them are VALID
256 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 266 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null);
257 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)], null); 267 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)], null);
258 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)], null); 268 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)], null);
259 entry2.setValue(result4, 444, [], null); 269 entry2.setValue(result4, 444, [], null);
260 expect(entry1.getState(result1), CacheState.VALID); 270 expect(entry1.getState(result1), CacheState.VALID);
(...skipping 14 matching lines...) Expand all
275 expect(entry2.getState(result4), CacheState.VALID); 285 expect(entry2.getState(result4), CacheState.VALID);
276 expect(entry1.getValue(result1), -1); 286 expect(entry1.getValue(result1), -1);
277 expect(entry2.getValue(result2), -2); 287 expect(entry2.getValue(result2), -2);
278 expect(entry2.getValue(result3), -3); 288 expect(entry2.getValue(result3), -3);
279 expect(entry2.getValue(result4), 444); 289 expect(entry2.getValue(result4), 444);
280 expect(entry1.exception, exception); 290 expect(entry1.exception, exception);
281 expect(entry2.exception, exception); 291 expect(entry2.exception, exception);
282 } 292 }
283 293
284 test_setErrorState_noDescriptors() { 294 test_setErrorState_noDescriptors() {
295 AnalysisTarget target = new TestSource();
285 CaughtException exception = new CaughtException(null, null); 296 CaughtException exception = new CaughtException(null, null);
286 CacheEntry entry = new CacheEntry(); 297 CacheEntry entry = new CacheEntry(target);
287 expect(() { 298 expect(() {
288 entry.setErrorState(exception, <ResultDescriptor>[]); 299 entry.setErrorState(exception, <ResultDescriptor>[]);
289 }, throwsArgumentError); 300 }, throwsArgumentError);
290 } 301 }
291 302
292 test_setErrorState_noException() { 303 test_setErrorState_noException() {
304 AnalysisTarget target = new TestSource();
293 ResultDescriptor result = new ResultDescriptor('test', null); 305 ResultDescriptor result = new ResultDescriptor('test', null);
294 CacheEntry entry = new CacheEntry(); 306 CacheEntry entry = new CacheEntry(target);
295 expect(() { 307 expect(() {
296 entry.setErrorState(null, <ResultDescriptor>[result]); 308 entry.setErrorState(null, <ResultDescriptor>[result]);
297 }, throwsArgumentError); 309 }, throwsArgumentError);
298 } 310 }
299 311
300 test_setErrorState_nullDescriptors() { 312 test_setErrorState_nullDescriptors() {
313 AnalysisTarget target = new TestSource();
301 CaughtException exception = new CaughtException(null, null); 314 CaughtException exception = new CaughtException(null, null);
302 CacheEntry entry = new CacheEntry(); 315 CacheEntry entry = new CacheEntry(target);
303 expect(() { 316 expect(() {
304 entry.setErrorState(exception, null); 317 entry.setErrorState(exception, null);
305 }, throwsArgumentError); 318 }, throwsArgumentError);
306 } 319 }
307 320
308 test_setState_error() { 321 test_setState_error() {
322 AnalysisTarget target = new TestSource();
309 ResultDescriptor result = new ResultDescriptor('test', null); 323 ResultDescriptor result = new ResultDescriptor('test', null);
310 CacheEntry entry = new CacheEntry(); 324 CacheEntry entry = new CacheEntry(target);
311 entry.setValue(result, 42, TargetedResult.EMPTY_LIST, null); 325 entry.setValue(result, 42, TargetedResult.EMPTY_LIST, null);
312 // an invalid state change 326 // an invalid state change
313 expect(() { 327 expect(() {
314 entry.setState(result, CacheState.ERROR); 328 entry.setState(result, CacheState.ERROR);
315 }, throwsArgumentError); 329 }, throwsArgumentError);
316 // no changes 330 // no changes
317 expect(entry.getState(result), CacheState.VALID); 331 expect(entry.getState(result), CacheState.VALID);
318 expect(entry.getValue(result), 42); 332 expect(entry.getValue(result), 42);
319 } 333 }
320 334
321 test_setState_flushed() { 335 test_setState_flushed() {
336 AnalysisTarget target = new TestSource();
322 ResultDescriptor result = new ResultDescriptor('test', 1); 337 ResultDescriptor result = new ResultDescriptor('test', 1);
323 CacheEntry entry = new CacheEntry(); 338 CacheEntry entry = new CacheEntry(target);
324 // set VALID 339 // set VALID
325 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null); 340 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null);
326 expect(entry.getState(result), CacheState.VALID); 341 expect(entry.getState(result), CacheState.VALID);
327 expect(entry.getValue(result), 10); 342 expect(entry.getValue(result), 10);
328 // set FLUSHED 343 // set FLUSHED
329 entry.setState(result, CacheState.FLUSHED); 344 entry.setState(result, CacheState.FLUSHED);
330 expect(entry.getState(result), CacheState.FLUSHED); 345 expect(entry.getState(result), CacheState.FLUSHED);
331 expect(entry.getValue(result), 1); 346 expect(entry.getValue(result), 1);
332 } 347 }
333 348
334 test_setState_inProcess() { 349 test_setState_inProcess() {
350 AnalysisTarget target = new TestSource();
335 ResultDescriptor result = new ResultDescriptor('test', 1); 351 ResultDescriptor result = new ResultDescriptor('test', 1);
336 CacheEntry entry = new CacheEntry(); 352 CacheEntry entry = new CacheEntry(target);
337 // set VALID 353 // set VALID
338 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null); 354 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null);
339 expect(entry.getState(result), CacheState.VALID); 355 expect(entry.getState(result), CacheState.VALID);
340 expect(entry.getValue(result), 10); 356 expect(entry.getValue(result), 10);
341 // set IN_PROCESS 357 // set IN_PROCESS
342 entry.setState(result, CacheState.IN_PROCESS); 358 entry.setState(result, CacheState.IN_PROCESS);
343 expect(entry.getState(result), CacheState.IN_PROCESS); 359 expect(entry.getState(result), CacheState.IN_PROCESS);
344 expect(entry.getValue(result), 10); 360 expect(entry.getValue(result), 10);
345 } 361 }
346 362
347 test_setState_invalid() { 363 test_setState_invalid() {
364 AnalysisTarget target = new TestSource();
348 ResultDescriptor result = new ResultDescriptor('test', 1); 365 ResultDescriptor result = new ResultDescriptor('test', 1);
349 CacheEntry entry = new CacheEntry(); 366 CacheEntry entry = new CacheEntry(target);
350 // set VALID 367 // set VALID
351 String memento = 'main() {}'; 368 String memento = 'main() {}';
352 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, memento); 369 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, memento);
353 expect(entry.getState(result), CacheState.VALID); 370 expect(entry.getState(result), CacheState.VALID);
354 expect(entry.getValue(result), 10); 371 expect(entry.getValue(result), 10);
355 // set INVALID 372 // set INVALID
356 entry.setState(result, CacheState.INVALID); 373 entry.setState(result, CacheState.INVALID);
357 expect(entry.getState(result), CacheState.INVALID); 374 expect(entry.getState(result), CacheState.INVALID);
358 expect(entry.getValue(result), 1); 375 expect(entry.getValue(result), 1);
359 expect(entry.getMemento(result), memento); 376 expect(entry.getMemento(result), memento);
360 } 377 }
361 378
362 test_setState_invalid_invalidateDependent() { 379 test_setState_invalid_invalidateDependent() {
363 AnalysisTarget target = new TestSource(); 380 AnalysisTarget target = new TestSource();
364 CacheEntry entry = new CacheEntry(); 381 CacheEntry entry = new CacheEntry(target);
365 cache.put(target, entry); 382 cache.put(entry);
366 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 383 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
367 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 384 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
368 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 385 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
369 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 386 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
370 // set results, all of them are VALID 387 // set results, all of them are VALID
371 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 388 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null);
372 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null); 389 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null);
373 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null); 390 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null);
374 entry.setValue(result4, 444, [], null); 391 entry.setValue(result4, 444, [], null);
375 expect(entry.getState(result1), CacheState.VALID); 392 expect(entry.getState(result1), CacheState.VALID);
(...skipping 10 matching lines...) Expand all
386 expect(entry.getState(result2), CacheState.INVALID); 403 expect(entry.getState(result2), CacheState.INVALID);
387 expect(entry.getState(result3), CacheState.INVALID); 404 expect(entry.getState(result3), CacheState.INVALID);
388 expect(entry.getState(result4), CacheState.VALID); 405 expect(entry.getState(result4), CacheState.VALID);
389 expect(entry.getValue(result1), -1); 406 expect(entry.getValue(result1), -1);
390 expect(entry.getValue(result2), -2); 407 expect(entry.getValue(result2), -2);
391 expect(entry.getValue(result3), -3); 408 expect(entry.getValue(result3), -3);
392 expect(entry.getValue(result4), 444); 409 expect(entry.getValue(result4), 444);
393 } 410 }
394 411
395 test_setState_valid() { 412 test_setState_valid() {
413 AnalysisTarget target = new TestSource();
396 ResultDescriptor result = new ResultDescriptor('test', null); 414 ResultDescriptor result = new ResultDescriptor('test', null);
397 CacheEntry entry = new CacheEntry(); 415 CacheEntry entry = new CacheEntry(target);
398 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); 416 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError);
399 } 417 }
400 418
401 test_setValue() { 419 test_setValue() {
420 AnalysisTarget target = new TestSource();
402 ResultDescriptor result = new ResultDescriptor('test', null); 421 ResultDescriptor result = new ResultDescriptor('test', null);
403 String value = 'value'; 422 String value = 'value';
404 String memento = 'main() {}'; 423 String memento = 'main() {}';
405 CacheEntry entry = new CacheEntry(); 424 CacheEntry entry = new CacheEntry(target);
406 entry.setValue(result, value, TargetedResult.EMPTY_LIST, memento); 425 entry.setValue(result, value, TargetedResult.EMPTY_LIST, memento);
407 expect(entry.getState(result), CacheState.VALID); 426 expect(entry.getState(result), CacheState.VALID);
408 expect(entry.getValue(result), value); 427 expect(entry.getValue(result), value);
409 expect(entry.getMemento(result), memento); 428 expect(entry.getMemento(result), memento);
410 } 429 }
411 430
412 test_setValue_flushResults() { 431 test_setValue_flushResults() {
413 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); 432 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2);
414 ResultDescriptor descriptor1 = 433 ResultDescriptor descriptor1 =
415 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); 434 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy);
416 ResultDescriptor descriptor2 = 435 ResultDescriptor descriptor2 =
417 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); 436 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy);
418 ResultDescriptor descriptor3 = 437 ResultDescriptor descriptor3 =
419 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); 438 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy);
420 AnalysisTarget target = new TestSource(); 439 AnalysisTarget target = new TestSource();
421 CacheEntry entry = new CacheEntry(); 440 CacheEntry entry = new CacheEntry(target);
422 cache.put(target, entry); 441 cache.put(entry);
423 Object memento1 = 'aaa'; 442 Object memento1 = 'aaa';
424 { 443 {
425 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, memento1); 444 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, memento1);
426 expect(entry.getState(descriptor1), CacheState.VALID); 445 expect(entry.getState(descriptor1), CacheState.VALID);
427 expect(entry.getMemento(descriptor1), memento1); 446 expect(entry.getMemento(descriptor1), memento1);
428 } 447 }
429 { 448 {
430 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null); 449 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null);
431 expect(entry.getState(descriptor1), CacheState.VALID); 450 expect(entry.getState(descriptor1), CacheState.VALID);
432 expect(entry.getState(descriptor2), CacheState.VALID); 451 expect(entry.getState(descriptor2), CacheState.VALID);
433 } 452 }
434 { 453 {
435 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null); 454 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null);
436 expect(entry.getState(descriptor1), CacheState.FLUSHED); 455 expect(entry.getState(descriptor1), CacheState.FLUSHED);
437 expect(entry.getState(descriptor2), CacheState.VALID); 456 expect(entry.getState(descriptor2), CacheState.VALID);
438 expect(entry.getState(descriptor3), CacheState.VALID); 457 expect(entry.getState(descriptor3), CacheState.VALID);
439 expect(entry.getMemento(descriptor1), isNull); 458 expect(entry.getMemento(descriptor1), isNull);
440 } 459 }
441 } 460 }
442 461
443 test_setValue_invalidateDependent() { 462 test_setValue_invalidateDependent() {
444 AnalysisTarget target = new TestSource(); 463 AnalysisTarget target = new TestSource();
445 CacheEntry entry = new CacheEntry(); 464 CacheEntry entry = new CacheEntry(target);
446 cache.put(target, entry); 465 cache.put(entry);
447 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 466 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
448 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 467 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
449 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 468 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
450 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 469 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
451 // set results, all of them are VALID 470 // set results, all of them are VALID
452 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 471 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null);
453 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null); 472 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null);
454 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null); 473 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null);
455 entry.setValue(result4, 444, [], null); 474 entry.setValue(result4, 444, [], null);
456 expect(entry.getState(result1), CacheState.VALID); 475 expect(entry.getState(result1), CacheState.VALID);
(...skipping 12 matching lines...) Expand all
469 expect(entry.getState(result4), CacheState.VALID); 488 expect(entry.getState(result4), CacheState.VALID);
470 expect(entry.getValue(result1), 1111); 489 expect(entry.getValue(result1), 1111);
471 expect(entry.getValue(result2), -2); 490 expect(entry.getValue(result2), -2);
472 expect(entry.getValue(result3), -3); 491 expect(entry.getValue(result3), -3);
473 expect(entry.getValue(result4), 444); 492 expect(entry.getValue(result4), 444);
474 } 493 }
475 494
476 test_setValue_invalidateDependent2() { 495 test_setValue_invalidateDependent2() {
477 AnalysisTarget target1 = new TestSource('a'); 496 AnalysisTarget target1 = new TestSource('a');
478 AnalysisTarget target2 = new TestSource('b'); 497 AnalysisTarget target2 = new TestSource('b');
479 CacheEntry entry1 = new CacheEntry(); 498 CacheEntry entry1 = new CacheEntry(target1);
480 CacheEntry entry2 = new CacheEntry(); 499 CacheEntry entry2 = new CacheEntry(target2);
481 cache.put(target1, entry1); 500 cache.put(entry1);
482 cache.put(target2, entry2); 501 cache.put(entry2);
483 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 502 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
484 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 503 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
485 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 504 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
486 // set results, all of them are VALID 505 // set results, all of them are VALID
487 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 506 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null);
488 entry1.setValue(result2, 222, [new TargetedResult(target1, result1)], null); 507 entry1.setValue(result2, 222, [new TargetedResult(target1, result1)], null);
489 entry2.setValue(result3, 333, [new TargetedResult(target1, result2)], null); 508 entry2.setValue(result3, 333, [new TargetedResult(target1, result2)], null);
490 expect(entry1.getState(result1), CacheState.VALID); 509 expect(entry1.getState(result1), CacheState.VALID);
491 expect(entry1.getState(result2), CacheState.VALID); 510 expect(entry1.getState(result2), CacheState.VALID);
492 expect(entry2.getState(result3), CacheState.VALID); 511 expect(entry2.getState(result3), CacheState.VALID);
493 expect(entry1.getValue(result1), 111); 512 expect(entry1.getValue(result1), 111);
494 expect(entry1.getValue(result2), 222); 513 expect(entry1.getValue(result2), 222);
495 expect(entry2.getValue(result3), 333); 514 expect(entry2.getValue(result3), 333);
496 // set result1, invalidates result2 and result3 515 // set result1, invalidates result2 and result3
497 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST, null); 516 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST, null);
498 expect(entry1.getState(result1), CacheState.VALID); 517 expect(entry1.getState(result1), CacheState.VALID);
499 expect(entry1.getState(result2), CacheState.INVALID); 518 expect(entry1.getState(result2), CacheState.INVALID);
500 expect(entry2.getState(result3), CacheState.INVALID); 519 expect(entry2.getState(result3), CacheState.INVALID);
501 expect(entry1.getValue(result1), 1111); 520 expect(entry1.getValue(result1), 1111);
502 expect(entry1.getValue(result2), -2); 521 expect(entry1.getValue(result2), -2);
503 expect(entry2.getValue(result3), -3); 522 expect(entry2.getValue(result3), -3);
504 } 523 }
505 524
506 test_toString_empty() { 525 test_toString_empty() {
507 CacheEntry entry = new CacheEntry(); 526 AnalysisTarget target = new TestSource();
527 CacheEntry entry = new CacheEntry(target);
508 expect(entry.toString(), isNotNull); 528 expect(entry.toString(), isNotNull);
509 } 529 }
510 530
511 test_toString_nonEmpty() { 531 test_toString_nonEmpty() {
512 String value = 'value'; 532 AnalysisTarget target = new TestSource();
513 ResultDescriptor result = new ResultDescriptor('test', null); 533 ResultDescriptor result = new ResultDescriptor('test', null);
514 CacheEntry entry = new CacheEntry(); 534 CacheEntry entry = new CacheEntry(target);
515 entry.setValue(result, value, TargetedResult.EMPTY_LIST, null); 535 entry.setValue(result, 42, TargetedResult.EMPTY_LIST, null);
516 expect(entry.toString(), isNotNull); 536 expect(entry.toString(), isNotNull);
517 } 537 }
518 } 538 }
519 539
520 @reflectiveTest 540 @reflectiveTest
521 class CacheFlushManagerTest { 541 class CacheFlushManagerTest {
522 CacheFlushManager manager = new CacheFlushManager( 542 CacheFlushManager manager = new CacheFlushManager(
523 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); 543 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false);
524 544
525 test_madeActive() { 545 test_madeActive() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 abstract class CachePartitionTest extends EngineTestCase { 681 abstract class CachePartitionTest extends EngineTestCase {
662 CachePartition createPartition(); 682 CachePartition createPartition();
663 683
664 void test_creation() { 684 void test_creation() {
665 expect(createPartition(), isNotNull); 685 expect(createPartition(), isNotNull);
666 } 686 }
667 687
668 void test_entrySet() { 688 void test_entrySet() {
669 CachePartition partition = createPartition(); 689 CachePartition partition = createPartition();
670 AnalysisTarget target = new TestSource(); 690 AnalysisTarget target = new TestSource();
671 CacheEntry entry = new CacheEntry(); 691 CacheEntry entry = new CacheEntry(target);
672 partition.put(target, entry); 692 partition.put(entry);
673 Map<AnalysisTarget, CacheEntry> entryMap = partition.map; 693 Map<AnalysisTarget, CacheEntry> entryMap = partition.map;
674 expect(entryMap, hasLength(1)); 694 expect(entryMap, hasLength(1));
675 AnalysisTarget entryKey = entryMap.keys.first; 695 AnalysisTarget entryKey = entryMap.keys.first;
676 expect(entryKey, target); 696 expect(entryKey, target);
677 expect(entryMap[entryKey], entry); 697 expect(entryMap[entryKey], entry);
678 } 698 }
679 699
680 void test_get() { 700 void test_get() {
681 CachePartition partition = createPartition(); 701 CachePartition partition = createPartition();
682 AnalysisTarget target = new TestSource(); 702 AnalysisTarget target = new TestSource();
683 expect(partition.get(target), isNull); 703 expect(partition.get(target), isNull);
684 } 704 }
685 705
686 void test_put_alreadyInPartition() { 706 void test_put_alreadyInPartition() {
687 CachePartition partition1 = createPartition(); 707 CachePartition partition1 = createPartition();
688 CachePartition partition2 = createPartition(); 708 CachePartition partition2 = createPartition();
689 AnalysisTarget target = new TestSource(); 709 AnalysisTarget target = new TestSource();
690 CacheEntry entry = new CacheEntry(); 710 CacheEntry entry = new CacheEntry(target);
691 partition1.put(target, entry); 711 partition1.put(entry);
692 expect(() => partition2.put(target, entry), throwsStateError); 712 expect(() => partition2.put(entry), throwsStateError);
693 } 713 }
694 714
695 void test_put_noFlush() { 715 void test_put_noFlush() {
696 CachePartition partition = createPartition(); 716 CachePartition partition = createPartition();
697 AnalysisTarget target = new TestSource(); 717 AnalysisTarget target = new TestSource();
698 CacheEntry entry = new CacheEntry(); 718 CacheEntry entry = new CacheEntry(target);
699 partition.put(target, entry); 719 partition.put(entry);
700 expect(partition.get(target), entry); 720 expect(partition.get(target), entry);
701 } 721 }
702 722
703 void test_remove() { 723 void test_remove() {
704 CachePartition partition = createPartition(); 724 CachePartition partition = createPartition();
705 AnalysisTarget target = new TestSource(); 725 AnalysisTarget target = new TestSource();
706 CacheEntry entry = new CacheEntry(); 726 CacheEntry entry = new CacheEntry(target);
707 partition.put(target, entry); 727 partition.put(entry);
708 expect(partition.get(target), entry); 728 expect(partition.get(target), entry);
709 partition.remove(target); 729 partition.remove(target);
710 expect(partition.get(target), isNull); 730 expect(partition.get(target), isNull);
711 } 731 }
712 } 732 }
713 733
714 @reflectiveTest 734 @reflectiveTest
715 class ResultDataTest extends EngineTestCase { 735 class ResultDataTest extends EngineTestCase {
716 test_creation() { 736 test_creation() {
717 String value = 'value'; 737 String value = 'value';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 UniversalCachePartition partition = new UniversalCachePartition(null); 785 UniversalCachePartition partition = new UniversalCachePartition(null);
766 TestSource source = new TestSource(); 786 TestSource source = new TestSource();
767 expect(partition.isResponsibleFor(source), isTrue); 787 expect(partition.isResponsibleFor(source), isTrue);
768 } 788 }
769 } 789 }
770 790
771 class _InternalAnalysisContextMock extends TypedMock 791 class _InternalAnalysisContextMock extends TypedMock
772 implements InternalAnalysisContext { 792 implements InternalAnalysisContext {
773 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 793 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
774 } 794 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698