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

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

Issue 1129033003: When a target is removed, invalidate all dependent results. (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,
11 CacheState, 11 CacheState,
12 InternalAnalysisContext, 12 InternalAnalysisContext,
13 RetentionPriority; 13 RetentionPriority;
14 import 'package:analyzer/src/generated/java_engine.dart'; 14 import 'package:analyzer/src/generated/java_engine.dart';
15 import 'package:analyzer/src/generated/sdk_io.dart'; 15 import 'package:analyzer/src/generated/sdk_io.dart';
16 import 'package:analyzer/src/generated/source.dart'; 16 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/generated/utilities_collection.dart'; 17 import 'package:analyzer/src/generated/utilities_collection.dart';
18 import 'package:analyzer/src/task/model.dart'; 18 import 'package:analyzer/src/task/model.dart';
19 import 'package:analyzer/task/model.dart'; 19 import 'package:analyzer/task/model.dart';
20 import 'package:typed_mock/typed_mock.dart'; 20 import 'package:typed_mock/typed_mock.dart';
21 import 'package:unittest/unittest.dart'; 21 import 'package:unittest/unittest.dart';
22 22
23 import '../../generated/engine_test.dart';
24 import '../../generated/test_support.dart'; 23 import '../../generated/test_support.dart';
25 import '../../reflective_tests.dart'; 24 import '../../reflective_tests.dart';
26 25
27 main() { 26 main() {
28 groupSep = ' | '; 27 groupSep = ' | ';
29 runReflectiveTests(AnalysisCacheTest); 28 runReflectiveTests(AnalysisCacheTest);
30 runReflectiveTests(CacheEntryTest); 29 runReflectiveTests(CacheEntryTest);
31 runReflectiveTests(CacheFlushManagerTest); 30 runReflectiveTests(CacheFlushManagerTest);
32 runReflectiveTests(SdkCachePartitionTest); 31 runReflectiveTests(SdkCachePartitionTest);
33 runReflectiveTests(UniversalCachePartitionTest); 32 runReflectiveTests(UniversalCachePartitionTest);
34 runReflectiveTests(ResultDataTest); 33 runReflectiveTests(ResultDataTest);
35 } 34 }
36 35
37 AnalysisCache createCache({AnalysisContext context, 36 AnalysisCache createCache({AnalysisContext context,
38 RetentionPriority policy: RetentionPriority.LOW}) { 37 RetentionPriority policy: RetentionPriority.LOW}) {
39 CachePartition partition = new UniversalCachePartition(context); 38 CachePartition partition = new UniversalCachePartition(context);
40 return new AnalysisCache(<CachePartition>[partition]); 39 return new AnalysisCache(<CachePartition>[partition]);
41 } 40 }
42 41
42 class AbstractCacheTest {
43 InternalAnalysisContext context;
44 AnalysisCache cache;
45
46 void setUp() {
47 context = new _InternalAnalysisContextMock();
48 when(context.priorityTargets).thenReturn([]);
49 cache = createCache(context: context);
50 when(context.analysisCache).thenReturn(cache);
51 }
52 }
53
43 @reflectiveTest 54 @reflectiveTest
44 class AnalysisCacheTest extends EngineTestCase { 55 class AnalysisCacheTest extends AbstractCacheTest {
45 void test_creation() { 56 void test_creation() {
46 expect(createCache(), isNotNull); 57 expect(cache, isNotNull);
47 } 58 }
48 59
49 void test_get() { 60 void test_get() {
50 AnalysisCache cache = createCache();
51 AnalysisTarget target = new TestSource(); 61 AnalysisTarget target = new TestSource();
52 expect(cache.get(target), isNull); 62 expect(cache.get(target), isNull);
53 } 63 }
54 64
55 void test_getContextFor() { 65 void test_getContextFor() {
56 AnalysisContext context = new TestAnalysisContext();
57 AnalysisCache cache = createCache(context: context);
58 AnalysisTarget target = new TestSource(); 66 AnalysisTarget target = new TestSource();
59 expect(cache.getContextFor(target), context); 67 expect(cache.getContextFor(target), context);
60 } 68 }
61 69
62 void test_iterator() { 70 void test_iterator() {
63 AnalysisCache cache = createCache();
64 AnalysisTarget target = new TestSource(); 71 AnalysisTarget target = new TestSource();
65 CacheEntry entry = new CacheEntry(target); 72 CacheEntry entry = new CacheEntry(target);
66 cache.put(entry); 73 cache.put(entry);
67 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); 74 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
68 expect(iterator.moveNext(), isTrue); 75 expect(iterator.moveNext(), isTrue);
69 expect(iterator.key, same(target)); 76 expect(iterator.key, same(target));
70 expect(iterator.value, same(entry)); 77 expect(iterator.value, same(entry));
71 expect(iterator.moveNext(), isFalse); 78 expect(iterator.moveNext(), isFalse);
72 } 79 }
73 80
74 void test_put() { 81 void test_put() {
75 AnalysisCache cache = createCache();
76 AnalysisTarget target = new TestSource(); 82 AnalysisTarget target = new TestSource();
77 CacheEntry entry = new CacheEntry(target); 83 CacheEntry entry = new CacheEntry(target);
78 expect(cache.get(target), isNull); 84 expect(cache.get(target), isNull);
79 cache.put(entry); 85 cache.put(entry);
80 expect(cache.get(target), entry); 86 expect(cache.get(target), entry);
81 } 87 }
82 88
83 void test_remove() { 89 void test_remove() {
84 AnalysisCache cache = createCache(); 90 AnalysisTarget target1 = new TestSource('/a.dart');
85 AnalysisTarget target = new TestSource(); 91 AnalysisTarget target2 = new TestSource('/b.dart');
86 cache.remove(target); 92 AnalysisTarget target3 = new TestSource('/c.dart');
93 CacheEntry entry1 = new CacheEntry(target1);
94 CacheEntry entry2 = new CacheEntry(target2);
95 CacheEntry entry3 = new CacheEntry(target3);
96 cache.put(entry1);
97 cache.put(entry2);
98 cache.put(entry3);
99 ResultDescriptor result1 = new ResultDescriptor('result1', -1);
100 ResultDescriptor result2 = new ResultDescriptor('result2', -2);
101 ResultDescriptor result3 = new ResultDescriptor('result3', -3);
102 // set results, all of them are VALID
103 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST);
104 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]);
105 entry3.setValue(result3, 333, []);
106 expect(entry1.getState(result1), CacheState.VALID);
107 expect(entry2.getState(result2), CacheState.VALID);
108 expect(entry3.getState(result3), CacheState.VALID);
109 expect(entry1.getValue(result1), 111);
110 expect(entry2.getValue(result2), 222);
111 expect(entry3.getValue(result3), 333);
112 // remove entry1, invalidate result2 and remove empty entry2
113 cache.remove(target1);
114 expect(cache.get(target1), isNull);
115 expect(cache.get(target2), isNull);
116 expect(cache.get(target3), entry3);
117 expect(entry3.getState(result3), CacheState.VALID);
87 } 118 }
88 119
89 void test_size() { 120 void test_size() {
90 AnalysisCache cache = createCache();
91 int size = 4; 121 int size = 4;
92 for (int i = 0; i < size; i++) { 122 for (int i = 0; i < size; i++) {
93 AnalysisTarget target = new TestSource("/test$i.dart"); 123 AnalysisTarget target = new TestSource("/test$i.dart");
94 cache.put(new CacheEntry(target)); 124 cache.put(new CacheEntry(target));
95 } 125 }
96 expect(cache.size(), size); 126 expect(cache.size(), size);
97 } 127 }
98 } 128 }
99 129
100 @reflectiveTest 130 @reflectiveTest
101 class CacheEntryTest extends EngineTestCase { 131 class CacheEntryTest extends AbstractCacheTest {
102 InternalAnalysisContext context;
103 AnalysisCache cache;
104
105 void setUp() {
106 context = new _InternalAnalysisContextMock();
107 when(context.priorityTargets).thenReturn([]);
108 cache = createCache(context: context);
109 when(context.analysisCache).thenReturn(cache);
110 }
111
112 test_explicitlyAdded() { 132 test_explicitlyAdded() {
113 AnalysisTarget target = new TestSource(); 133 AnalysisTarget target = new TestSource();
114 CacheEntry entry = new CacheEntry(target); 134 CacheEntry entry = new CacheEntry(target);
115 expect(entry.explicitlyAdded, false); 135 expect(entry.explicitlyAdded, false);
116 entry.explicitlyAdded = true; 136 entry.explicitlyAdded = true;
117 expect(entry.explicitlyAdded, true); 137 expect(entry.explicitlyAdded, true);
118 } 138 }
119 139
120 test_fixExceptionState_error_exception() { 140 test_fixExceptionState_error_exception() {
121 AnalysisTarget target = new TestSource(); 141 AnalysisTarget target = new TestSource();
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 UniversalCachePartition partition = new UniversalCachePartition(null); 841 UniversalCachePartition partition = new UniversalCachePartition(null);
822 TestSource source = new TestSource(); 842 TestSource source = new TestSource();
823 expect(partition.isResponsibleFor(source), isTrue); 843 expect(partition.isResponsibleFor(source), isTrue);
824 } 844 }
825 } 845 }
826 846
827 class _InternalAnalysisContextMock extends TypedMock 847 class _InternalAnalysisContextMock extends TypedMock
828 implements InternalAnalysisContext { 848 implements InternalAnalysisContext {
829 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 849 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
830 } 850 }
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