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

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

Issue 1132103002: Remove memento. (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/task/model.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 test_fixExceptionState_noError_exception() { 131 test_fixExceptionState_noError_exception() {
132 AnalysisTarget target = new TestSource(); 132 AnalysisTarget target = new TestSource();
133 ResultDescriptor result = new ResultDescriptor('test', null); 133 ResultDescriptor result = new ResultDescriptor('test', null);
134 CacheEntry entry = new CacheEntry(target); 134 CacheEntry entry = new CacheEntry(target);
135 // set one result to ERROR 135 // set one result to ERROR
136 CaughtException exception = new CaughtException(null, null); 136 CaughtException exception = new CaughtException(null, null);
137 entry.setErrorState(exception, <ResultDescriptor>[result]); 137 entry.setErrorState(exception, <ResultDescriptor>[result]);
138 // set the same result to VALID 138 // set the same result to VALID
139 entry.setValue(result, 1, TargetedResult.EMPTY_LIST, null); 139 entry.setValue(result, 1, TargetedResult.EMPTY_LIST);
140 // fix the exception state 140 // fix the exception state
141 entry.fixExceptionState(); 141 entry.fixExceptionState();
142 expect(entry.exception, isNull); 142 expect(entry.exception, isNull);
143 } 143 }
144 144
145 test_fixExceptionState_noError_noException() { 145 test_fixExceptionState_noError_noException() {
146 AnalysisTarget target = new TestSource(); 146 AnalysisTarget target = new TestSource();
147 ResultDescriptor result = new ResultDescriptor('test', null); 147 ResultDescriptor result = new ResultDescriptor('test', null);
148 CacheEntry entry = new CacheEntry(target); 148 CacheEntry entry = new CacheEntry(target);
149 entry.fixExceptionState(); 149 entry.fixExceptionState();
150 expect(entry.getState(result), CacheState.INVALID); 150 expect(entry.getState(result), CacheState.INVALID);
151 expect(entry.exception, isNull); 151 expect(entry.exception, isNull);
152 } 152 }
153 153
154 test_getMemento_noResult() {
155 AnalysisTarget target = new TestSource();
156 ResultDescriptor result = new ResultDescriptor('test', null);
157 CacheEntry entry = new CacheEntry(target);
158 expect(entry.getMemento(result), null);
159 }
160
161 test_getState() { 154 test_getState() {
162 AnalysisTarget target = new TestSource(); 155 AnalysisTarget target = new TestSource();
163 ResultDescriptor result = new ResultDescriptor('test', null); 156 ResultDescriptor result = new ResultDescriptor('test', null);
164 CacheEntry entry = new CacheEntry(target); 157 CacheEntry entry = new CacheEntry(target);
165 expect(entry.getState(result), CacheState.INVALID); 158 expect(entry.getState(result), CacheState.INVALID);
166 } 159 }
167 160
168 test_getValue_default() { 161 test_getValue_default() {
169 AnalysisTarget target = new TestSource(); 162 AnalysisTarget target = new TestSource();
170 String defaultValue = 'value'; 163 String defaultValue = 'value';
171 ResultDescriptor result = new ResultDescriptor('test', defaultValue); 164 ResultDescriptor result = new ResultDescriptor('test', defaultValue);
172 CacheEntry entry = new CacheEntry(target); 165 CacheEntry entry = new CacheEntry(target);
173 expect(entry.getValue(result), defaultValue); 166 expect(entry.getValue(result), defaultValue);
174 } 167 }
175 168
176 test_getValue_flushResults() { 169 test_getValue_flushResults() {
177 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); 170 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2);
178 ResultDescriptor descriptor1 = 171 ResultDescriptor descriptor1 =
179 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); 172 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy);
180 ResultDescriptor descriptor2 = 173 ResultDescriptor descriptor2 =
181 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); 174 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy);
182 ResultDescriptor descriptor3 = 175 ResultDescriptor descriptor3 =
183 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); 176 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy);
184 AnalysisTarget target = new TestSource(); 177 AnalysisTarget target = new TestSource();
185 CacheEntry entry = new CacheEntry(target); 178 CacheEntry entry = new CacheEntry(target);
186 cache.put(entry); 179 cache.put(entry);
187 { 180 {
188 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, null); 181 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST);
189 expect(entry.getState(descriptor1), CacheState.VALID); 182 expect(entry.getState(descriptor1), CacheState.VALID);
190 } 183 }
191 { 184 {
192 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null); 185 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST);
193 expect(entry.getState(descriptor1), CacheState.VALID); 186 expect(entry.getState(descriptor1), CacheState.VALID);
194 expect(entry.getState(descriptor2), CacheState.VALID); 187 expect(entry.getState(descriptor2), CacheState.VALID);
195 } 188 }
196 // get descriptor1, so that descriptor2 will be flushed 189 // get descriptor1, so that descriptor2 will be flushed
197 entry.getValue(descriptor1); 190 entry.getValue(descriptor1);
198 { 191 {
199 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null); 192 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST);
200 expect(entry.getState(descriptor1), CacheState.VALID); 193 expect(entry.getState(descriptor1), CacheState.VALID);
201 expect(entry.getState(descriptor2), CacheState.FLUSHED); 194 expect(entry.getState(descriptor2), CacheState.FLUSHED);
202 expect(entry.getState(descriptor3), CacheState.VALID); 195 expect(entry.getState(descriptor3), CacheState.VALID);
203 } 196 }
204 } 197 }
205 198
206 test_hasErrorState_false() { 199 test_hasErrorState_false() {
207 AnalysisTarget target = new TestSource(); 200 AnalysisTarget target = new TestSource();
208 CacheEntry entry = new CacheEntry(target); 201 CacheEntry entry = new CacheEntry(target);
209 expect(entry.hasErrorState(), false); 202 expect(entry.hasErrorState(), false);
210 } 203 }
211 204
212 test_hasErrorState_true() { 205 test_hasErrorState_true() {
213 AnalysisTarget target = new TestSource(); 206 AnalysisTarget target = new TestSource();
214 ResultDescriptor result = new ResultDescriptor('test', null); 207 ResultDescriptor result = new ResultDescriptor('test', null);
215 CaughtException exception = new CaughtException(null, null); 208 CaughtException exception = new CaughtException(null, null);
216 CacheEntry entry = new CacheEntry(target); 209 CacheEntry entry = new CacheEntry(target);
217 entry.setErrorState(exception, <ResultDescriptor>[result]); 210 entry.setErrorState(exception, <ResultDescriptor>[result]);
218 expect(entry.hasErrorState(), true); 211 expect(entry.hasErrorState(), true);
219 } 212 }
220 213
221 test_invalidateAllInformation() { 214 test_invalidateAllInformation() {
222 AnalysisTarget target = new TestSource(); 215 AnalysisTarget target = new TestSource();
223 ResultDescriptor result = new ResultDescriptor('test', null); 216 ResultDescriptor result = new ResultDescriptor('test', null);
224 CacheEntry entry = new CacheEntry(target); 217 CacheEntry entry = new CacheEntry(target);
225 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST, null); 218 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST);
226 entry.invalidateAllInformation(); 219 entry.invalidateAllInformation();
227 expect(entry.getState(result), CacheState.INVALID); 220 expect(entry.getState(result), CacheState.INVALID);
228 expect(entry.getValue(result), isNull); 221 expect(entry.getValue(result), isNull);
229 } 222 }
230 223
231 test_setErrorState() { 224 test_setErrorState() {
232 AnalysisTarget target = new TestSource(); 225 AnalysisTarget target = new TestSource();
233 ResultDescriptor result1 = new ResultDescriptor('res1', 1); 226 ResultDescriptor result1 = new ResultDescriptor('res1', 1);
234 ResultDescriptor result2 = new ResultDescriptor('res2', 2); 227 ResultDescriptor result2 = new ResultDescriptor('res2', 2);
235 ResultDescriptor result3 = new ResultDescriptor('res3', 3); 228 ResultDescriptor result3 = new ResultDescriptor('res3', 3);
236 // prepare some good state 229 // prepare some good state
237 CacheEntry entry = new CacheEntry(target); 230 CacheEntry entry = new CacheEntry(target);
238 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST, null); 231 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST);
239 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST, null); 232 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST);
240 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST, null); 233 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST);
241 // set error state 234 // set error state
242 CaughtException exception = new CaughtException(null, null); 235 CaughtException exception = new CaughtException(null, null);
243 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); 236 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]);
244 // verify 237 // verify
245 expect(entry.exception, exception); 238 expect(entry.exception, exception);
246 expect(entry.getState(result1), CacheState.ERROR); 239 expect(entry.getState(result1), CacheState.ERROR);
247 expect(entry.getState(result2), CacheState.ERROR); 240 expect(entry.getState(result2), CacheState.ERROR);
248 expect(entry.getState(result3), CacheState.VALID); 241 expect(entry.getState(result3), CacheState.VALID);
249 expect(entry.getValue(result1), 1); 242 expect(entry.getValue(result1), 1);
250 expect(entry.getValue(result2), 2); 243 expect(entry.getValue(result2), 2);
251 expect(entry.getValue(result3), 30); 244 expect(entry.getValue(result3), 30);
252 } 245 }
253 246
254 test_setErrorState_invalidateDependent() { 247 test_setErrorState_invalidateDependent() {
255 AnalysisTarget target1 = new TestSource('/a.dart'); 248 AnalysisTarget target1 = new TestSource('/a.dart');
256 AnalysisTarget target2 = new TestSource('/b.dart'); 249 AnalysisTarget target2 = new TestSource('/b.dart');
257 CacheEntry entry1 = new CacheEntry(target1); 250 CacheEntry entry1 = new CacheEntry(target1);
258 CacheEntry entry2 = new CacheEntry(target2); 251 CacheEntry entry2 = new CacheEntry(target2);
259 cache.put(entry1); 252 cache.put(entry1);
260 cache.put(entry2); 253 cache.put(entry2);
261 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 254 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
262 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 255 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
263 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 256 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
264 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 257 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
265 // set results, all of them are VALID 258 // set results, all of them are VALID
266 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 259 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
267 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)], null); 260 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]);
268 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)], null); 261 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]);
269 entry2.setValue(result4, 444, [], null); 262 entry2.setValue(result4, 444, []);
270 expect(entry1.getState(result1), CacheState.VALID); 263 expect(entry1.getState(result1), CacheState.VALID);
271 expect(entry2.getState(result2), CacheState.VALID); 264 expect(entry2.getState(result2), CacheState.VALID);
272 expect(entry2.getState(result3), CacheState.VALID); 265 expect(entry2.getState(result3), CacheState.VALID);
273 expect(entry2.getState(result4), CacheState.VALID); 266 expect(entry2.getState(result4), CacheState.VALID);
274 expect(entry1.getValue(result1), 111); 267 expect(entry1.getValue(result1), 111);
275 expect(entry2.getValue(result2), 222); 268 expect(entry2.getValue(result2), 222);
276 expect(entry2.getValue(result3), 333); 269 expect(entry2.getValue(result3), 333);
277 expect(entry2.getValue(result4), 444); 270 expect(entry2.getValue(result4), 444);
278 // set error state 271 // set error state
279 CaughtException exception = new CaughtException(null, null); 272 CaughtException exception = new CaughtException(null, null);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 CacheEntry entry = new CacheEntry(target); 308 CacheEntry entry = new CacheEntry(target);
316 expect(() { 309 expect(() {
317 entry.setErrorState(exception, null); 310 entry.setErrorState(exception, null);
318 }, throwsArgumentError); 311 }, throwsArgumentError);
319 } 312 }
320 313
321 test_setState_error() { 314 test_setState_error() {
322 AnalysisTarget target = new TestSource(); 315 AnalysisTarget target = new TestSource();
323 ResultDescriptor result = new ResultDescriptor('test', null); 316 ResultDescriptor result = new ResultDescriptor('test', null);
324 CacheEntry entry = new CacheEntry(target); 317 CacheEntry entry = new CacheEntry(target);
325 entry.setValue(result, 42, TargetedResult.EMPTY_LIST, null); 318 entry.setValue(result, 42, TargetedResult.EMPTY_LIST);
326 // an invalid state change 319 // an invalid state change
327 expect(() { 320 expect(() {
328 entry.setState(result, CacheState.ERROR); 321 entry.setState(result, CacheState.ERROR);
329 }, throwsArgumentError); 322 }, throwsArgumentError);
330 // no changes 323 // no changes
331 expect(entry.getState(result), CacheState.VALID); 324 expect(entry.getState(result), CacheState.VALID);
332 expect(entry.getValue(result), 42); 325 expect(entry.getValue(result), 42);
333 } 326 }
334 327
335 test_setState_flushed() { 328 test_setState_flushed() {
336 AnalysisTarget target = new TestSource(); 329 AnalysisTarget target = new TestSource();
337 ResultDescriptor result = new ResultDescriptor('test', 1); 330 ResultDescriptor result = new ResultDescriptor('test', 1);
338 CacheEntry entry = new CacheEntry(target); 331 CacheEntry entry = new CacheEntry(target);
339 // set VALID 332 // set VALID
340 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null); 333 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
341 expect(entry.getState(result), CacheState.VALID); 334 expect(entry.getState(result), CacheState.VALID);
342 expect(entry.getValue(result), 10); 335 expect(entry.getValue(result), 10);
343 // set FLUSHED 336 // set FLUSHED
344 entry.setState(result, CacheState.FLUSHED); 337 entry.setState(result, CacheState.FLUSHED);
345 expect(entry.getState(result), CacheState.FLUSHED); 338 expect(entry.getState(result), CacheState.FLUSHED);
346 expect(entry.getValue(result), 1); 339 expect(entry.getValue(result), 1);
347 } 340 }
348 341
349 test_setState_inProcess() { 342 test_setState_inProcess() {
350 AnalysisTarget target = new TestSource(); 343 AnalysisTarget target = new TestSource();
351 ResultDescriptor result = new ResultDescriptor('test', 1); 344 ResultDescriptor result = new ResultDescriptor('test', 1);
352 CacheEntry entry = new CacheEntry(target); 345 CacheEntry entry = new CacheEntry(target);
353 // set VALID 346 // set VALID
354 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, null); 347 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
355 expect(entry.getState(result), CacheState.VALID); 348 expect(entry.getState(result), CacheState.VALID);
356 expect(entry.getValue(result), 10); 349 expect(entry.getValue(result), 10);
357 // set IN_PROCESS 350 // set IN_PROCESS
358 entry.setState(result, CacheState.IN_PROCESS); 351 entry.setState(result, CacheState.IN_PROCESS);
359 expect(entry.getState(result), CacheState.IN_PROCESS); 352 expect(entry.getState(result), CacheState.IN_PROCESS);
360 expect(entry.getValue(result), 10); 353 expect(entry.getValue(result), 10);
361 } 354 }
362 355
363 test_setState_invalid() { 356 test_setState_invalid() {
364 AnalysisTarget target = new TestSource(); 357 AnalysisTarget target = new TestSource();
365 ResultDescriptor result = new ResultDescriptor('test', 1); 358 ResultDescriptor result = new ResultDescriptor('test', 1);
366 CacheEntry entry = new CacheEntry(target); 359 CacheEntry entry = new CacheEntry(target);
367 // set VALID 360 // set VALID
368 String memento = 'main() {}'; 361 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
369 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, memento);
370 expect(entry.getState(result), CacheState.VALID); 362 expect(entry.getState(result), CacheState.VALID);
371 expect(entry.getValue(result), 10); 363 expect(entry.getValue(result), 10);
372 // set INVALID 364 // set INVALID
373 entry.setState(result, CacheState.INVALID); 365 entry.setState(result, CacheState.INVALID);
374 expect(entry.getState(result), CacheState.INVALID); 366 expect(entry.getState(result), CacheState.INVALID);
375 expect(entry.getValue(result), 1); 367 expect(entry.getValue(result), 1);
376 expect(entry.getMemento(result), memento);
377 } 368 }
378 369
379 test_setState_invalid_invalidateDependent() { 370 test_setState_invalid_invalidateDependent() {
380 AnalysisTarget target = new TestSource(); 371 AnalysisTarget target = new TestSource();
381 CacheEntry entry = new CacheEntry(target); 372 CacheEntry entry = new CacheEntry(target);
382 cache.put(entry); 373 cache.put(entry);
383 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 374 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
384 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 375 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
385 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 376 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
386 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 377 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
387 // set results, all of them are VALID 378 // set results, all of them are VALID
388 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 379 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
389 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null); 380 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
390 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null); 381 entry.setValue(result3, 333, [new TargetedResult(target, result2)]);
391 entry.setValue(result4, 444, [], null); 382 entry.setValue(result4, 444, []);
392 expect(entry.getState(result1), CacheState.VALID); 383 expect(entry.getState(result1), CacheState.VALID);
393 expect(entry.getState(result2), CacheState.VALID); 384 expect(entry.getState(result2), CacheState.VALID);
394 expect(entry.getState(result3), CacheState.VALID); 385 expect(entry.getState(result3), CacheState.VALID);
395 expect(entry.getState(result4), CacheState.VALID); 386 expect(entry.getState(result4), CacheState.VALID);
396 expect(entry.getValue(result1), 111); 387 expect(entry.getValue(result1), 111);
397 expect(entry.getValue(result2), 222); 388 expect(entry.getValue(result2), 222);
398 expect(entry.getValue(result3), 333); 389 expect(entry.getValue(result3), 333);
399 expect(entry.getValue(result4), 444); 390 expect(entry.getValue(result4), 444);
400 // invalidate result1, invalidates result2 and result3, result4 is intact 391 // invalidate result1, invalidates result2 and result3, result4 is intact
401 entry.setState(result1, CacheState.INVALID); 392 entry.setState(result1, CacheState.INVALID);
(...skipping 11 matching lines...) Expand all
413 AnalysisTarget target = new TestSource(); 404 AnalysisTarget target = new TestSource();
414 ResultDescriptor result = new ResultDescriptor('test', null); 405 ResultDescriptor result = new ResultDescriptor('test', null);
415 CacheEntry entry = new CacheEntry(target); 406 CacheEntry entry = new CacheEntry(target);
416 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); 407 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError);
417 } 408 }
418 409
419 test_setValue() { 410 test_setValue() {
420 AnalysisTarget target = new TestSource(); 411 AnalysisTarget target = new TestSource();
421 ResultDescriptor result = new ResultDescriptor('test', null); 412 ResultDescriptor result = new ResultDescriptor('test', null);
422 String value = 'value'; 413 String value = 'value';
423 String memento = 'main() {}';
424 CacheEntry entry = new CacheEntry(target); 414 CacheEntry entry = new CacheEntry(target);
425 entry.setValue(result, value, TargetedResult.EMPTY_LIST, memento); 415 entry.setValue(result, value, TargetedResult.EMPTY_LIST);
426 expect(entry.getState(result), CacheState.VALID); 416 expect(entry.getState(result), CacheState.VALID);
427 expect(entry.getValue(result), value); 417 expect(entry.getValue(result), value);
428 expect(entry.getMemento(result), memento);
429 } 418 }
430 419
431 test_setValue_flushResults() { 420 test_setValue_flushResults() {
432 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); 421 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2);
433 ResultDescriptor descriptor1 = 422 ResultDescriptor descriptor1 =
434 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); 423 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy);
435 ResultDescriptor descriptor2 = 424 ResultDescriptor descriptor2 =
436 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy); 425 new ResultDescriptor('result2', null, cachingPolicy: cachingPolicy);
437 ResultDescriptor descriptor3 = 426 ResultDescriptor descriptor3 =
438 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy); 427 new ResultDescriptor('result3', null, cachingPolicy: cachingPolicy);
439 AnalysisTarget target = new TestSource(); 428 AnalysisTarget target = new TestSource();
440 CacheEntry entry = new CacheEntry(target); 429 CacheEntry entry = new CacheEntry(target);
441 cache.put(entry); 430 cache.put(entry);
442 Object memento1 = 'aaa';
443 { 431 {
444 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST, memento1); 432 entry.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST);
445 expect(entry.getState(descriptor1), CacheState.VALID); 433 expect(entry.getState(descriptor1), CacheState.VALID);
446 expect(entry.getMemento(descriptor1), memento1);
447 } 434 }
448 { 435 {
449 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST, null); 436 entry.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST);
450 expect(entry.getState(descriptor1), CacheState.VALID); 437 expect(entry.getState(descriptor1), CacheState.VALID);
451 expect(entry.getState(descriptor2), CacheState.VALID); 438 expect(entry.getState(descriptor2), CacheState.VALID);
452 } 439 }
453 { 440 {
454 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST, null); 441 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST);
455 expect(entry.getState(descriptor1), CacheState.FLUSHED); 442 expect(entry.getState(descriptor1), CacheState.FLUSHED);
456 expect(entry.getState(descriptor2), CacheState.VALID); 443 expect(entry.getState(descriptor2), CacheState.VALID);
457 expect(entry.getState(descriptor3), CacheState.VALID); 444 expect(entry.getState(descriptor3), CacheState.VALID);
458 expect(entry.getMemento(descriptor1), isNull);
459 } 445 }
460 } 446 }
461 447
462 test_setValue_invalidateDependent() { 448 test_setValue_invalidateDependent() {
463 AnalysisTarget target = new TestSource(); 449 AnalysisTarget target = new TestSource();
464 CacheEntry entry = new CacheEntry(target); 450 CacheEntry entry = new CacheEntry(target);
465 cache.put(entry); 451 cache.put(entry);
466 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 452 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
467 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 453 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
468 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 454 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
469 ResultDescriptor result4 = new ResultDescriptor('result4', -4); 455 ResultDescriptor result4 = new ResultDescriptor('result4', -4);
470 // set results, all of them are VALID 456 // set results, all of them are VALID
471 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 457 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
472 entry.setValue(result2, 222, [new TargetedResult(target, result1)], null); 458 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
473 entry.setValue(result3, 333, [new TargetedResult(target, result2)], null); 459 entry.setValue(result3, 333, [new TargetedResult(target, result2)]);
474 entry.setValue(result4, 444, [], null); 460 entry.setValue(result4, 444, []);
475 expect(entry.getState(result1), CacheState.VALID); 461 expect(entry.getState(result1), CacheState.VALID);
476 expect(entry.getState(result2), CacheState.VALID); 462 expect(entry.getState(result2), CacheState.VALID);
477 expect(entry.getState(result3), CacheState.VALID); 463 expect(entry.getState(result3), CacheState.VALID);
478 expect(entry.getState(result4), CacheState.VALID); 464 expect(entry.getState(result4), CacheState.VALID);
479 expect(entry.getValue(result1), 111); 465 expect(entry.getValue(result1), 111);
480 expect(entry.getValue(result2), 222); 466 expect(entry.getValue(result2), 222);
481 expect(entry.getValue(result3), 333); 467 expect(entry.getValue(result3), 333);
482 expect(entry.getValue(result4), 444); 468 expect(entry.getValue(result4), 444);
483 // set result1, invalidates result2 and result3, result4 is intact 469 // set result1, invalidates result2 and result3, result4 is intact
484 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST, null); 470 entry.setValue(result1, 1111, TargetedResult.EMPTY_LIST);
485 expect(entry.getState(result1), CacheState.VALID); 471 expect(entry.getState(result1), CacheState.VALID);
486 expect(entry.getState(result2), CacheState.INVALID); 472 expect(entry.getState(result2), CacheState.INVALID);
487 expect(entry.getState(result3), CacheState.INVALID); 473 expect(entry.getState(result3), CacheState.INVALID);
488 expect(entry.getState(result4), CacheState.VALID); 474 expect(entry.getState(result4), CacheState.VALID);
489 expect(entry.getValue(result1), 1111); 475 expect(entry.getValue(result1), 1111);
490 expect(entry.getValue(result2), -2); 476 expect(entry.getValue(result2), -2);
491 expect(entry.getValue(result3), -3); 477 expect(entry.getValue(result3), -3);
492 expect(entry.getValue(result4), 444); 478 expect(entry.getValue(result4), 444);
493 } 479 }
494 480
495 test_setValue_invalidateDependent2() { 481 test_setValue_invalidateDependent2() {
496 AnalysisTarget target1 = new TestSource('a'); 482 AnalysisTarget target1 = new TestSource('a');
497 AnalysisTarget target2 = new TestSource('b'); 483 AnalysisTarget target2 = new TestSource('b');
498 CacheEntry entry1 = new CacheEntry(target1); 484 CacheEntry entry1 = new CacheEntry(target1);
499 CacheEntry entry2 = new CacheEntry(target2); 485 CacheEntry entry2 = new CacheEntry(target2);
500 cache.put(entry1); 486 cache.put(entry1);
501 cache.put(entry2); 487 cache.put(entry2);
502 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 488 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
503 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 489 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
504 ResultDescriptor result3 = new ResultDescriptor('result3', -3); 490 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
505 // set results, all of them are VALID 491 // set results, all of them are VALID
506 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST, null); 492 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
507 entry1.setValue(result2, 222, [new TargetedResult(target1, result1)], null); 493 entry1.setValue(result2, 222, [new TargetedResult(target1, result1)]);
508 entry2.setValue(result3, 333, [new TargetedResult(target1, result2)], null); 494 entry2.setValue(result3, 333, [new TargetedResult(target1, result2)]);
509 expect(entry1.getState(result1), CacheState.VALID); 495 expect(entry1.getState(result1), CacheState.VALID);
510 expect(entry1.getState(result2), CacheState.VALID); 496 expect(entry1.getState(result2), CacheState.VALID);
511 expect(entry2.getState(result3), CacheState.VALID); 497 expect(entry2.getState(result3), CacheState.VALID);
512 expect(entry1.getValue(result1), 111); 498 expect(entry1.getValue(result1), 111);
513 expect(entry1.getValue(result2), 222); 499 expect(entry1.getValue(result2), 222);
514 expect(entry2.getValue(result3), 333); 500 expect(entry2.getValue(result3), 333);
515 // set result1, invalidates result2 and result3 501 // set result1, invalidates result2 and result3
516 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST, null); 502 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST);
517 expect(entry1.getState(result1), CacheState.VALID); 503 expect(entry1.getState(result1), CacheState.VALID);
518 expect(entry1.getState(result2), CacheState.INVALID); 504 expect(entry1.getState(result2), CacheState.INVALID);
519 expect(entry2.getState(result3), CacheState.INVALID); 505 expect(entry2.getState(result3), CacheState.INVALID);
520 expect(entry1.getValue(result1), 1111); 506 expect(entry1.getValue(result1), 1111);
521 expect(entry1.getValue(result2), -2); 507 expect(entry1.getValue(result2), -2);
522 expect(entry2.getValue(result3), -3); 508 expect(entry2.getValue(result3), -3);
523 } 509 }
524 510
525 test_toString_empty() { 511 test_toString_empty() {
526 AnalysisTarget target = new TestSource(); 512 AnalysisTarget target = new TestSource();
527 CacheEntry entry = new CacheEntry(target); 513 CacheEntry entry = new CacheEntry(target);
528 expect(entry.toString(), isNotNull); 514 expect(entry.toString(), isNotNull);
529 } 515 }
530 516
531 test_toString_nonEmpty() { 517 test_toString_nonEmpty() {
532 AnalysisTarget target = new TestSource(); 518 AnalysisTarget target = new TestSource();
533 ResultDescriptor result = new ResultDescriptor('test', null); 519 ResultDescriptor result = new ResultDescriptor('test', null);
534 CacheEntry entry = new CacheEntry(target); 520 CacheEntry entry = new CacheEntry(target);
535 entry.setValue(result, 42, TargetedResult.EMPTY_LIST, null); 521 entry.setValue(result, 42, TargetedResult.EMPTY_LIST);
536 expect(entry.toString(), isNotNull); 522 expect(entry.toString(), isNotNull);
537 } 523 }
538 } 524 }
539 525
540 @reflectiveTest 526 @reflectiveTest
541 class CacheFlushManagerTest { 527 class CacheFlushManagerTest {
542 CacheFlushManager manager = new CacheFlushManager( 528 CacheFlushManager manager = new CacheFlushManager(
543 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); 529 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false);
544 530
545 test_madeActive() { 531 test_madeActive() {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 expect(data, isNotNull); 725 expect(data, isNotNull);
740 expect(data.state, CacheState.INVALID); 726 expect(data.state, CacheState.INVALID);
741 expect(data.value, value); 727 expect(data.value, value);
742 } 728 }
743 729
744 test_flush() { 730 test_flush() {
745 ResultDescriptor result = new ResultDescriptor('test', -1); 731 ResultDescriptor result = new ResultDescriptor('test', -1);
746 ResultData data = new ResultData(result); 732 ResultData data = new ResultData(result);
747 data.state = CacheState.VALID; 733 data.state = CacheState.VALID;
748 data.value = 123; 734 data.value = 123;
749 data.memento = 'abc';
750 data.flush(); 735 data.flush();
751 expect(data.state, CacheState.FLUSHED); 736 expect(data.state, CacheState.FLUSHED);
752 expect(data.value, -1); 737 expect(data.value, -1);
753 expect(data.memento, isNull);
754 } 738 }
755 } 739 }
756 740
757 @reflectiveTest 741 @reflectiveTest
758 class SdkCachePartitionTest extends CachePartitionTest { 742 class SdkCachePartitionTest extends CachePartitionTest {
759 CachePartition createPartition() { 743 CachePartition createPartition() {
760 return new SdkCachePartition(null); 744 return new SdkCachePartition(null);
761 } 745 }
762 746
763 void test_contains_false() { 747 void test_contains_false() {
(...skipping 21 matching lines...) Expand all
785 UniversalCachePartition partition = new UniversalCachePartition(null); 769 UniversalCachePartition partition = new UniversalCachePartition(null);
786 TestSource source = new TestSource(); 770 TestSource source = new TestSource();
787 expect(partition.isResponsibleFor(source), isTrue); 771 expect(partition.isResponsibleFor(source), isTrue);
788 } 772 }
789 } 773 }
790 774
791 class _InternalAnalysisContextMock extends TypedMock 775 class _InternalAnalysisContextMock extends TypedMock
792 implements InternalAnalysisContext { 776 implements InternalAnalysisContext {
793 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 777 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
794 } 778 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/task/model.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698