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

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

Issue 1133833002: Automatically remove empty entries from the cache. (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/cache.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 entry.setErrorState(exception, <ResultDescriptor>[result]); 125 entry.setErrorState(exception, <ResultDescriptor>[result]);
126 entry.fixExceptionState(); 126 entry.fixExceptionState();
127 expect(entry.getState(result), CacheState.ERROR); 127 expect(entry.getState(result), CacheState.ERROR);
128 expect(entry.exception, exception); 128 expect(entry.exception, exception);
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 cache.put(entry);
135 // set one result to ERROR 136 // set one result to ERROR
136 CaughtException exception = new CaughtException(null, null); 137 CaughtException exception = new CaughtException(null, null);
137 entry.setErrorState(exception, <ResultDescriptor>[result]); 138 entry.setErrorState(exception, <ResultDescriptor>[result]);
138 // set the same result to VALID 139 // set the same result to VALID
139 entry.setValue(result, 1, TargetedResult.EMPTY_LIST); 140 entry.setValue(result, 1, TargetedResult.EMPTY_LIST);
140 // fix the exception state 141 // fix the exception state
141 entry.fixExceptionState(); 142 entry.fixExceptionState();
142 expect(entry.exception, isNull); 143 expect(entry.exception, isNull);
143 } 144 }
144 145
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // set IN_PROCESS 351 // set IN_PROCESS
351 entry.setState(result, CacheState.IN_PROCESS); 352 entry.setState(result, CacheState.IN_PROCESS);
352 expect(entry.getState(result), CacheState.IN_PROCESS); 353 expect(entry.getState(result), CacheState.IN_PROCESS);
353 expect(entry.getValue(result), 10); 354 expect(entry.getValue(result), 10);
354 } 355 }
355 356
356 test_setState_invalid() { 357 test_setState_invalid() {
357 AnalysisTarget target = new TestSource(); 358 AnalysisTarget target = new TestSource();
358 ResultDescriptor result = new ResultDescriptor('test', 1); 359 ResultDescriptor result = new ResultDescriptor('test', 1);
359 CacheEntry entry = new CacheEntry(target); 360 CacheEntry entry = new CacheEntry(target);
361 cache.put(entry);
360 // set VALID 362 // set VALID
361 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); 363 entry.setValue(result, 10, TargetedResult.EMPTY_LIST);
362 expect(entry.getState(result), CacheState.VALID); 364 expect(entry.getState(result), CacheState.VALID);
363 expect(entry.getValue(result), 10); 365 expect(entry.getValue(result), 10);
364 // set INVALID 366 // set INVALID
365 entry.setState(result, CacheState.INVALID); 367 entry.setState(result, CacheState.INVALID);
366 expect(entry.getState(result), CacheState.INVALID); 368 expect(entry.getState(result), CacheState.INVALID);
367 expect(entry.getValue(result), 1); 369 expect(entry.getValue(result), 1);
368 } 370 }
369 371
(...skipping 21 matching lines...) Expand all
391 // invalidate result1, invalidates result2 and result3, result4 is intact 393 // invalidate result1, invalidates result2 and result3, result4 is intact
392 entry.setState(result1, CacheState.INVALID); 394 entry.setState(result1, CacheState.INVALID);
393 expect(entry.getState(result1), CacheState.INVALID); 395 expect(entry.getState(result1), CacheState.INVALID);
394 expect(entry.getState(result2), CacheState.INVALID); 396 expect(entry.getState(result2), CacheState.INVALID);
395 expect(entry.getState(result3), CacheState.INVALID); 397 expect(entry.getState(result3), CacheState.INVALID);
396 expect(entry.getState(result4), CacheState.VALID); 398 expect(entry.getState(result4), CacheState.VALID);
397 expect(entry.getValue(result1), -1); 399 expect(entry.getValue(result1), -1);
398 expect(entry.getValue(result2), -2); 400 expect(entry.getValue(result2), -2);
399 expect(entry.getValue(result3), -3); 401 expect(entry.getValue(result3), -3);
400 expect(entry.getValue(result4), 444); 402 expect(entry.getValue(result4), 444);
403 // result4 is still valid, so the entry is still in the cache
404 expect(cache.get(target), entry);
405 }
406
407 test_setState_invalid_removeEmptyEntry() {
408 AnalysisTarget target1 = new TestSource('/a.dart');
409 AnalysisTarget target2 = new TestSource('/b.dart');
410 CacheEntry entry1 = new CacheEntry(target1);
411 CacheEntry entry2 = new CacheEntry(target2);
412 cache.put(entry1);
413 cache.put(entry2);
414 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
415 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
416 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
417 // set results, all of them are VALID
418 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
419 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]);
420 entry2.setValue(result3, 333, [new TargetedResult(target2, result2)]);
421 expect(entry1.getState(result1), CacheState.VALID);
422 expect(entry2.getState(result2), CacheState.VALID);
423 expect(entry2.getState(result3), CacheState.VALID);
424 expect(entry1.getValue(result1), 111);
425 expect(entry2.getValue(result2), 222);
426 expect(entry2.getValue(result3), 333);
427 // invalidate result1, remove entry1 & entry2
428 entry1.setState(result1, CacheState.INVALID);
429 expect(cache.get(target1), isNull);
430 expect(cache.get(target2), isNull);
401 } 431 }
402 432
403 test_setState_valid() { 433 test_setState_valid() {
404 AnalysisTarget target = new TestSource(); 434 AnalysisTarget target = new TestSource();
405 ResultDescriptor result = new ResultDescriptor('test', null); 435 ResultDescriptor result = new ResultDescriptor('test', null);
406 CacheEntry entry = new CacheEntry(target); 436 CacheEntry entry = new CacheEntry(target);
407 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); 437 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError);
408 } 438 }
409 439
410 test_setValue() { 440 test_setValue() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // set result1, invalidates result2 and result3 531 // set result1, invalidates result2 and result3
502 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST); 532 entry1.setValue(result1, 1111, TargetedResult.EMPTY_LIST);
503 expect(entry1.getState(result1), CacheState.VALID); 533 expect(entry1.getState(result1), CacheState.VALID);
504 expect(entry1.getState(result2), CacheState.INVALID); 534 expect(entry1.getState(result2), CacheState.INVALID);
505 expect(entry2.getState(result3), CacheState.INVALID); 535 expect(entry2.getState(result3), CacheState.INVALID);
506 expect(entry1.getValue(result1), 1111); 536 expect(entry1.getValue(result1), 1111);
507 expect(entry1.getValue(result2), -2); 537 expect(entry1.getValue(result2), -2);
508 expect(entry2.getValue(result3), -3); 538 expect(entry2.getValue(result3), -3);
509 } 539 }
510 540
541 test_setValue_keepEntry() {
542 AnalysisTarget target1 = new TestSource('/a.dart');
543 AnalysisTarget target2 = new TestSource('/b.dart');
544 CacheEntry entry1 = new CacheEntry(target1);
545 CacheEntry entry2 = new CacheEntry(target2);
546 cache.put(entry1);
547 cache.put(entry2);
548 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
549 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
550 // set results, all of them are VALID
551 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
552 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]);
553 expect(entry1.getState(result1), CacheState.VALID);
554 expect(entry2.getState(result2), CacheState.VALID);
555 expect(entry1.getValue(result1), 111);
556 expect(entry2.getValue(result2), 222);
557 // set result2, entry2 is still in the cache
558 entry2.setValue(result2, 2222, []);
559 expect(cache.get(target1), entry1);
560 expect(cache.get(target2), entry2);
561 }
562
511 test_toString_empty() { 563 test_toString_empty() {
512 AnalysisTarget target = new TestSource(); 564 AnalysisTarget target = new TestSource();
513 CacheEntry entry = new CacheEntry(target); 565 CacheEntry entry = new CacheEntry(target);
514 expect(entry.toString(), isNotNull); 566 expect(entry.toString(), isNotNull);
515 } 567 }
516 568
517 test_toString_nonEmpty() { 569 test_toString_nonEmpty() {
518 AnalysisTarget target = new TestSource(); 570 AnalysisTarget target = new TestSource();
519 ResultDescriptor result = new ResultDescriptor('test', null); 571 ResultDescriptor result = new ResultDescriptor('test', null);
520 CacheEntry entry = new CacheEntry(target); 572 CacheEntry entry = new CacheEntry(target);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 UniversalCachePartition partition = new UniversalCachePartition(null); 821 UniversalCachePartition partition = new UniversalCachePartition(null);
770 TestSource source = new TestSource(); 822 TestSource source = new TestSource();
771 expect(partition.isResponsibleFor(source), isTrue); 823 expect(partition.isResponsibleFor(source), isTrue);
772 } 824 }
773 } 825 }
774 826
775 class _InternalAnalysisContextMock extends TypedMock 827 class _InternalAnalysisContextMock extends TypedMock
776 implements InternalAnalysisContext { 828 implements InternalAnalysisContext {
777 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 829 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
778 } 830 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698