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

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

Issue 2289283003: An AnalysisTarget is a priority one if its Source is in prioritySources. (Closed)
Patch Set: Created 4 years, 3 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
« 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 analyzer.test.src.context.cache_test; 5 library analyzer.test.src.context.cache_test;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart'; 8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/file_system/physical_file_system.dart'; 9 import 'package:analyzer/file_system/physical_file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
(...skipping 26 matching lines...) Expand all
37 CachePartition partition = new UniversalCachePartition(context); 37 CachePartition partition = new UniversalCachePartition(context);
38 return new AnalysisCache(<CachePartition>[partition]); 38 return new AnalysisCache(<CachePartition>[partition]);
39 } 39 }
40 40
41 class AbstractCacheTest { 41 class AbstractCacheTest {
42 InternalAnalysisContext context; 42 InternalAnalysisContext context;
43 AnalysisCache cache; 43 AnalysisCache cache;
44 44
45 void setUp() { 45 void setUp() {
46 context = new _InternalAnalysisContextMock(); 46 context = new _InternalAnalysisContextMock();
47 when(context.priorityTargets).thenReturn([]); 47 when(context.prioritySources).thenReturn([]);
48 cache = createCache(context: context); 48 cache = createCache(context: context);
49 when(context.analysisCache).thenReturn(cache); 49 when(context.analysisCache).thenReturn(cache);
50 } 50 }
51 } 51 }
52 52
53 @reflectiveTest 53 @reflectiveTest
54 class AnalysisCacheTest extends AbstractCacheTest { 54 class AnalysisCacheTest extends AbstractCacheTest {
55 void test_creation() { 55 void test_creation() {
56 expect(cache, isNotNull); 56 expect(cache, isNotNull);
57 } 57 }
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 expect(entry.getState(descriptor2), CacheState.VALID); 764 expect(entry.getState(descriptor2), CacheState.VALID);
765 } 765 }
766 { 766 {
767 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST); 767 entry.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST);
768 expect(entry.getState(descriptor1), CacheState.FLUSHED); 768 expect(entry.getState(descriptor1), CacheState.FLUSHED);
769 expect(entry.getState(descriptor2), CacheState.VALID); 769 expect(entry.getState(descriptor2), CacheState.VALID);
770 expect(entry.getState(descriptor3), CacheState.VALID); 770 expect(entry.getState(descriptor3), CacheState.VALID);
771 } 771 }
772 } 772 }
773 773
774 test_setValue_flushResults_keepForPrioritySources() {
775 ResultCachingPolicy cachingPolicy = new SimpleResultCachingPolicy(2, 2);
776 ResultDescriptor newResult(String name) =>
777 new ResultDescriptor(name, null, cachingPolicy: cachingPolicy);
778 ResultDescriptor descriptor1 = newResult('result1');
779 ResultDescriptor descriptor2 = newResult('result2');
780 ResultDescriptor descriptor3 = newResult('result3');
781 TestSource source1 = new TestSource('/a.dart');
782 TestSource source2 = new TestSource('/b.dart');
783 TestSource source3 = new TestSource('/c.dart');
784 AnalysisTarget target1 =
785 new _TestAnalysisTarget(librarySource: source1, source: source1);
786 AnalysisTarget target2 =
787 new _TestAnalysisTarget(librarySource: source2, source: source2);
788 AnalysisTarget target3 =
789 new _TestAnalysisTarget(librarySource: source3, source: source3);
790 CacheEntry entry1 = new CacheEntry(target1);
791 CacheEntry entry2 = new CacheEntry(target2);
792 CacheEntry entry3 = new CacheEntry(target3);
793 cache.put(entry1);
794 cache.put(entry2);
795 cache.put(entry3);
796
797 // Set two results.
798 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST);
799 entry2.setValue(descriptor2, 2, TargetedResult.EMPTY_LIST);
800 expect(entry1.getState(descriptor1), CacheState.VALID);
801 expect(entry2.getState(descriptor2), CacheState.VALID);
802
803 // Make source1 priority, so result2 is flushed instead.
804 when(context.prioritySources).thenReturn([source1]);
805 entry3.setValue(descriptor3, 3, TargetedResult.EMPTY_LIST);
806 expect(entry1.getState(descriptor1), CacheState.VALID);
807 expect(entry2.getState(descriptor2), CacheState.FLUSHED);
808 expect(entry3.getState(descriptor3), CacheState.VALID);
809 }
810
774 test_setValue_keepDependent() { 811 test_setValue_keepDependent() {
775 AnalysisTarget target = new TestSource(); 812 AnalysisTarget target = new TestSource();
776 CacheEntry entry = new CacheEntry(target); 813 CacheEntry entry = new CacheEntry(target);
777 cache.put(entry); 814 cache.put(entry);
778 ResultDescriptor result1 = new ResultDescriptor('result1', -1); 815 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
779 ResultDescriptor result2 = new ResultDescriptor('result2', -2); 816 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
780 // set results, all of them are VALID 817 // set results, all of them are VALID
781 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); 818 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST);
782 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); 819 entry.setValue(result2, 222, [new TargetedResult(target, result1)]);
783 expect(entry.getState(result1), CacheState.VALID); 820 expect(entry.getState(result1), CacheState.VALID);
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, 1296 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target,
1260 ResultDescriptor descriptor, Object value) { 1297 ResultDescriptor descriptor, Object value) {
1261 if (descriptor == keepDescriptor) { 1298 if (descriptor == keepDescriptor) {
1262 return DeltaResult.KEEP_CONTINUE; 1299 return DeltaResult.KEEP_CONTINUE;
1263 } 1300 }
1264 return DeltaResult.INVALIDATE; 1301 return DeltaResult.INVALIDATE;
1265 } 1302 }
1266 } 1303 }
1267 1304
1268 class _TestAnalysisTarget implements AnalysisTarget { 1305 class _TestAnalysisTarget implements AnalysisTarget {
1269 @override 1306 final Source librarySource;
1270 Source get librarySource => null; 1307 final Source source;
1271 1308 _TestAnalysisTarget({this.librarySource, this.source});
1272 @override
1273 Source get source => null;
1274 } 1309 }
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