| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.context.cache_test; | 5 library analyzer.test.src.context.cache_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 import 'package:analyzer/src/generated/java_engine.dart'; | 9 import 'package:analyzer/src/generated/java_engine.dart'; |
| 10 import 'package:analyzer/src/generated/sdk_io.dart'; | 10 import 'package:analyzer/src/generated/sdk_io.dart'; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 expect(entry.explicitlyAdded, false); | 259 expect(entry.explicitlyAdded, false); |
| 260 entry.explicitlyAdded = true; | 260 entry.explicitlyAdded = true; |
| 261 expect(entry.explicitlyAdded, true); | 261 expect(entry.explicitlyAdded, true); |
| 262 } | 262 } |
| 263 | 263 |
| 264 test_fixExceptionState_error_exception() { | 264 test_fixExceptionState_error_exception() { |
| 265 AnalysisTarget target = new TestSource(); | 265 AnalysisTarget target = new TestSource(); |
| 266 ResultDescriptor result = new ResultDescriptor('test', null); | 266 ResultDescriptor result = new ResultDescriptor('test', null); |
| 267 CaughtException exception = new CaughtException(null, null); | 267 CaughtException exception = new CaughtException(null, null); |
| 268 CacheEntry entry = new CacheEntry(target); | 268 CacheEntry entry = new CacheEntry(target); |
| 269 cache.put(entry); |
| 269 entry.setErrorState(exception, <ResultDescriptor>[result]); | 270 entry.setErrorState(exception, <ResultDescriptor>[result]); |
| 270 entry.fixExceptionState(); | 271 entry.fixExceptionState(); |
| 271 expect(entry.getState(result), CacheState.ERROR); | 272 expect(entry.getState(result), CacheState.ERROR); |
| 272 expect(entry.exception, exception); | 273 expect(entry.exception, exception); |
| 273 } | 274 } |
| 274 | 275 |
| 275 test_fixExceptionState_noError_exception() { | 276 test_fixExceptionState_noError_exception() { |
| 276 AnalysisTarget target = new TestSource(); | 277 AnalysisTarget target = new TestSource(); |
| 277 ResultDescriptor result = new ResultDescriptor('test', null); | 278 ResultDescriptor result = new ResultDescriptor('test', null); |
| 278 CacheEntry entry = new CacheEntry(target); | 279 CacheEntry entry = new CacheEntry(target); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 AnalysisTarget target = new TestSource(); | 346 AnalysisTarget target = new TestSource(); |
| 346 CacheEntry entry = new CacheEntry(target); | 347 CacheEntry entry = new CacheEntry(target); |
| 347 expect(entry.hasErrorState(), false); | 348 expect(entry.hasErrorState(), false); |
| 348 } | 349 } |
| 349 | 350 |
| 350 test_hasErrorState_true() { | 351 test_hasErrorState_true() { |
| 351 AnalysisTarget target = new TestSource(); | 352 AnalysisTarget target = new TestSource(); |
| 352 ResultDescriptor result = new ResultDescriptor('test', null); | 353 ResultDescriptor result = new ResultDescriptor('test', null); |
| 353 CaughtException exception = new CaughtException(null, null); | 354 CaughtException exception = new CaughtException(null, null); |
| 354 CacheEntry entry = new CacheEntry(target); | 355 CacheEntry entry = new CacheEntry(target); |
| 356 cache.put(entry); |
| 355 entry.setErrorState(exception, <ResultDescriptor>[result]); | 357 entry.setErrorState(exception, <ResultDescriptor>[result]); |
| 356 expect(entry.hasErrorState(), true); | 358 expect(entry.hasErrorState(), true); |
| 357 } | 359 } |
| 358 | 360 |
| 359 test_invalidateAllInformation() { | 361 test_invalidateAllInformation() { |
| 360 AnalysisTarget target = new TestSource(); | 362 AnalysisTarget target = new TestSource(); |
| 361 ResultDescriptor result = new ResultDescriptor('test', null); | 363 ResultDescriptor result = new ResultDescriptor('test', null); |
| 362 CacheEntry entry = new CacheEntry(target); | 364 CacheEntry entry = new CacheEntry(target); |
| 365 cache.put(entry); |
| 363 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); | 366 entry.setValue(result, 'value', TargetedResult.EMPTY_LIST); |
| 364 entry.invalidateAllInformation(); | 367 entry.invalidateAllInformation(); |
| 365 expect(entry.getState(result), CacheState.INVALID); | 368 expect(entry.getState(result), CacheState.INVALID); |
| 366 expect(entry.getValue(result), isNull); | 369 expect(entry.getValue(result), isNull); |
| 367 } | 370 } |
| 368 | 371 |
| 369 test_setErrorState() { | 372 test_setErrorState() { |
| 370 AnalysisTarget target = new TestSource(); | 373 AnalysisTarget target = new TestSource(); |
| 371 ResultDescriptor result1 = new ResultDescriptor('res1', 1); | 374 ResultDescriptor result1 = new ResultDescriptor('res1', 1); |
| 372 ResultDescriptor result2 = new ResultDescriptor('res2', 2); | 375 ResultDescriptor result2 = new ResultDescriptor('res2', 2); |
| 373 ResultDescriptor result3 = new ResultDescriptor('res3', 3); | 376 ResultDescriptor result3 = new ResultDescriptor('res3', 3); |
| 374 // prepare some good state | 377 // prepare some good state |
| 375 CacheEntry entry = new CacheEntry(target); | 378 CacheEntry entry = new CacheEntry(target); |
| 379 cache.put(entry); |
| 376 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); | 380 entry.setValue(result1, 10, TargetedResult.EMPTY_LIST); |
| 377 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); | 381 entry.setValue(result2, 20, TargetedResult.EMPTY_LIST); |
| 378 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); | 382 entry.setValue(result3, 30, TargetedResult.EMPTY_LIST); |
| 379 // set error state | 383 // set error state |
| 380 CaughtException exception = new CaughtException(null, null); | 384 CaughtException exception = new CaughtException(null, null); |
| 381 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); | 385 entry.setErrorState(exception, <ResultDescriptor>[result1, result2]); |
| 382 // verify | 386 // verify |
| 383 expect(entry.exception, exception); | 387 expect(entry.exception, exception); |
| 384 expect(entry.getState(result1), CacheState.ERROR); | 388 expect(entry.getState(result1), CacheState.ERROR); |
| 385 expect(entry.getState(result2), CacheState.ERROR); | 389 expect(entry.getState(result2), CacheState.ERROR); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 CacheEntry entry = new CacheEntry(target); | 457 CacheEntry entry = new CacheEntry(target); |
| 454 expect(() { | 458 expect(() { |
| 455 entry.setErrorState(exception, null); | 459 entry.setErrorState(exception, null); |
| 456 }, throwsArgumentError); | 460 }, throwsArgumentError); |
| 457 } | 461 } |
| 458 | 462 |
| 459 test_setState_error() { | 463 test_setState_error() { |
| 460 AnalysisTarget target = new TestSource(); | 464 AnalysisTarget target = new TestSource(); |
| 461 ResultDescriptor result = new ResultDescriptor('test', null); | 465 ResultDescriptor result = new ResultDescriptor('test', null); |
| 462 CacheEntry entry = new CacheEntry(target); | 466 CacheEntry entry = new CacheEntry(target); |
| 467 cache.put(entry); |
| 463 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 468 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
| 464 // an invalid state change | 469 // an invalid state change |
| 465 expect(() { | 470 expect(() { |
| 466 entry.setState(result, CacheState.ERROR); | 471 entry.setState(result, CacheState.ERROR); |
| 467 }, throwsArgumentError); | 472 }, throwsArgumentError); |
| 468 // no changes | 473 // no changes |
| 469 expect(entry.getState(result), CacheState.VALID); | 474 expect(entry.getState(result), CacheState.VALID); |
| 470 expect(entry.getValue(result), 42); | 475 expect(entry.getValue(result), 42); |
| 471 } | 476 } |
| 472 | 477 |
| 473 test_setState_flushed() { | 478 test_setState_flushed() { |
| 474 AnalysisTarget target = new TestSource(); | 479 AnalysisTarget target = new TestSource(); |
| 475 ResultDescriptor result = new ResultDescriptor('test', 1); | 480 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 476 CacheEntry entry = new CacheEntry(target); | 481 CacheEntry entry = new CacheEntry(target); |
| 482 cache.put(entry); |
| 477 // set VALID | 483 // set VALID |
| 478 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 484 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 479 expect(entry.getState(result), CacheState.VALID); | 485 expect(entry.getState(result), CacheState.VALID); |
| 480 expect(entry.getValue(result), 10); | 486 expect(entry.getValue(result), 10); |
| 481 // set FLUSHED | 487 // set FLUSHED |
| 482 entry.setState(result, CacheState.FLUSHED); | 488 entry.setState(result, CacheState.FLUSHED); |
| 483 expect(entry.getState(result), CacheState.FLUSHED); | 489 expect(entry.getState(result), CacheState.FLUSHED); |
| 484 expect(entry.getValue(result), 1); | 490 expect(entry.getValue(result), 1); |
| 485 } | 491 } |
| 486 | 492 |
| 487 test_setState_inProcess() { | 493 test_setState_inProcess() { |
| 488 AnalysisTarget target = new TestSource(); | 494 AnalysisTarget target = new TestSource(); |
| 489 ResultDescriptor result = new ResultDescriptor('test', 1); | 495 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 490 CacheEntry entry = new CacheEntry(target); | 496 CacheEntry entry = new CacheEntry(target); |
| 497 cache.put(entry); |
| 491 // set VALID | 498 // set VALID |
| 492 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 499 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 493 expect(entry.getState(result), CacheState.VALID); | 500 expect(entry.getState(result), CacheState.VALID); |
| 494 expect(entry.getValue(result), 10); | 501 expect(entry.getValue(result), 10); |
| 495 // set IN_PROCESS | 502 // set IN_PROCESS |
| 496 entry.setState(result, CacheState.IN_PROCESS); | 503 entry.setState(result, CacheState.IN_PROCESS); |
| 497 expect(entry.getState(result), CacheState.IN_PROCESS); | 504 expect(entry.getState(result), CacheState.IN_PROCESS); |
| 498 expect(entry.getValue(result), 10); | 505 expect(entry.getValue(result), 10); |
| 499 } | 506 } |
| 500 | 507 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 ResultDescriptor result = new ResultDescriptor('test', null); | 674 ResultDescriptor result = new ResultDescriptor('test', null); |
| 668 CacheEntry entry = new CacheEntry(target); | 675 CacheEntry entry = new CacheEntry(target); |
| 669 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 676 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
| 670 } | 677 } |
| 671 | 678 |
| 672 test_setValue() { | 679 test_setValue() { |
| 673 AnalysisTarget target = new TestSource(); | 680 AnalysisTarget target = new TestSource(); |
| 674 ResultDescriptor result = new ResultDescriptor('test', null); | 681 ResultDescriptor result = new ResultDescriptor('test', null); |
| 675 String value = 'value'; | 682 String value = 'value'; |
| 676 CacheEntry entry = new CacheEntry(target); | 683 CacheEntry entry = new CacheEntry(target); |
| 684 cache.put(entry); |
| 677 entry.setValue(result, value, TargetedResult.EMPTY_LIST); | 685 entry.setValue(result, value, TargetedResult.EMPTY_LIST); |
| 678 expect(entry.getState(result), CacheState.VALID); | 686 expect(entry.getState(result), CacheState.VALID); |
| 679 expect(entry.getValue(result), value); | 687 expect(entry.getValue(result), value); |
| 680 } | 688 } |
| 681 | 689 |
| 682 test_setValue_flushResults() { | 690 test_setValue_flushResults() { |
| 683 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); | 691 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2); |
| 684 ResultDescriptor descriptor1 = | 692 ResultDescriptor descriptor1 = |
| 685 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); | 693 new ResultDescriptor('result1', null, cachingPolicy: cachingPolicy); |
| 686 ResultDescriptor descriptor2 = | 694 ResultDescriptor descriptor2 = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 test_toString_empty() { | 770 test_toString_empty() { |
| 763 AnalysisTarget target = new TestSource(); | 771 AnalysisTarget target = new TestSource(); |
| 764 CacheEntry entry = new CacheEntry(target); | 772 CacheEntry entry = new CacheEntry(target); |
| 765 expect(entry.toString(), isNotNull); | 773 expect(entry.toString(), isNotNull); |
| 766 } | 774 } |
| 767 | 775 |
| 768 test_toString_nonEmpty() { | 776 test_toString_nonEmpty() { |
| 769 AnalysisTarget target = new TestSource(); | 777 AnalysisTarget target = new TestSource(); |
| 770 ResultDescriptor result = new ResultDescriptor('test', null); | 778 ResultDescriptor result = new ResultDescriptor('test', null); |
| 771 CacheEntry entry = new CacheEntry(target); | 779 CacheEntry entry = new CacheEntry(target); |
| 780 cache.put(entry); |
| 772 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); | 781 entry.setValue(result, 42, TargetedResult.EMPTY_LIST); |
| 773 expect(entry.toString(), isNotNull); | 782 expect(entry.toString(), isNotNull); |
| 774 } | 783 } |
| 775 } | 784 } |
| 776 | 785 |
| 777 @reflectiveTest | 786 @reflectiveTest |
| 778 class CacheFlushManagerTest { | 787 class CacheFlushManagerTest { |
| 779 CacheFlushManager manager = new CacheFlushManager( | 788 CacheFlushManager manager = new CacheFlushManager( |
| 780 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); | 789 new SimpleResultCachingPolicy(15, 3), (AnalysisTarget target) => false); |
| 781 | 790 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 return DeltaResult.KEEP_CONTINUE; | 1141 return DeltaResult.KEEP_CONTINUE; |
| 1133 } | 1142 } |
| 1134 return DeltaResult.INVALIDATE; | 1143 return DeltaResult.INVALIDATE; |
| 1135 } | 1144 } |
| 1136 } | 1145 } |
| 1137 | 1146 |
| 1138 class _TestAnalysisTarget implements AnalysisTarget { | 1147 class _TestAnalysisTarget implements AnalysisTarget { |
| 1139 @override | 1148 @override |
| 1140 Source get source => null; | 1149 Source get source => null; |
| 1141 } | 1150 } |
| OLD | NEW |