| 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 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 169 entry1.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 170 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); | 170 entry2.setValue(result2, 222, [new TargetedResult(target1, result1)]); |
| 171 entry3.setValue(result3, 333, []); | 171 entry3.setValue(result3, 333, []); |
| 172 expect(entry1.getState(result1), CacheState.VALID); | 172 expect(entry1.getState(result1), CacheState.VALID); |
| 173 expect(entry2.getState(result2), CacheState.VALID); | 173 expect(entry2.getState(result2), CacheState.VALID); |
| 174 expect(entry3.getState(result3), CacheState.VALID); | 174 expect(entry3.getState(result3), CacheState.VALID); |
| 175 expect(entry1.getValue(result1), 111); | 175 expect(entry1.getValue(result1), 111); |
| 176 expect(entry2.getValue(result2), 222); | 176 expect(entry2.getValue(result2), 222); |
| 177 expect(entry3.getValue(result3), 333); | 177 expect(entry3.getValue(result3), 333); |
| 178 // remove entry1, invalidate result2 and remove empty entry2 | 178 // remove entry1, invalidate result2 and remove empty entry2 |
| 179 cache.remove(target1); | 179 expect(cache.remove(target1), entry1); |
| 180 expect(cache.get(target1), isNull); | 180 expect(cache.get(target1), isNull); |
| 181 expect(cache.get(target2), isNull); | 181 expect(cache.get(target2), isNull); |
| 182 expect(cache.get(target3), entry3); | 182 expect(cache.get(target3), entry3); |
| 183 expect(entry3.getState(result3), CacheState.VALID); | 183 expect(entry3.getState(result3), CacheState.VALID); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void test_remove_invalidateResults_sameTarget() { | 186 void test_remove_invalidateResults_sameTarget() { |
| 187 AnalysisTarget target = new TestSource('/a.dart'); | 187 AnalysisTarget target = new TestSource('/a.dart'); |
| 188 CacheEntry entry = new CacheEntry(target); | 188 CacheEntry entry = new CacheEntry(target); |
| 189 cache.put(entry); | 189 cache.put(entry); |
| 190 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 190 ResultDescriptor result1 = new ResultDescriptor('result1', -1); |
| 191 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 191 ResultDescriptor result2 = new ResultDescriptor('result2', -2); |
| 192 // set results, all of them are VALID | 192 // set results, all of them are VALID |
| 193 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); | 193 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 194 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); | 194 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 195 expect(entry.getState(result1), CacheState.VALID); | 195 expect(entry.getState(result1), CacheState.VALID); |
| 196 expect(entry.getState(result2), CacheState.VALID); | 196 expect(entry.getState(result2), CacheState.VALID); |
| 197 expect(entry.getValue(result1), 111); | 197 expect(entry.getValue(result1), 111); |
| 198 expect(entry.getValue(result2), 222); | 198 expect(entry.getValue(result2), 222); |
| 199 // remove target, invalidate result2 | 199 // remove target, invalidate result2 |
| 200 cache.remove(target); | 200 expect(cache.remove(target), entry); |
| 201 expect(cache.get(target), isNull); | 201 expect(cache.get(target), isNull); |
| 202 expect(entry.getState(result2), CacheState.INVALID); | 202 expect(entry.getState(result2), CacheState.INVALID); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void test_size() { | 205 void test_size() { |
| 206 int size = 4; | 206 int size = 4; |
| 207 for (int i = 0; i < size; i++) { | 207 for (int i = 0; i < size; i++) { |
| 208 AnalysisTarget target = new TestSource("/test$i.dart"); | 208 AnalysisTarget target = new TestSource("/test$i.dart"); |
| 209 cache.put(new CacheEntry(target)); | 209 cache.put(new CacheEntry(target)); |
| 210 } | 210 } |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 } | 938 } |
| 939 | 939 |
| 940 void test_put_noFlush() { | 940 void test_put_noFlush() { |
| 941 CachePartition partition = createPartition(); | 941 CachePartition partition = createPartition(); |
| 942 AnalysisTarget target = new TestSource(); | 942 AnalysisTarget target = new TestSource(); |
| 943 CacheEntry entry = new CacheEntry(target); | 943 CacheEntry entry = new CacheEntry(target); |
| 944 partition.put(entry); | 944 partition.put(entry); |
| 945 expect(partition.get(target), entry); | 945 expect(partition.get(target), entry); |
| 946 } | 946 } |
| 947 | 947 |
| 948 void test_remove() { | 948 void test_remove_absent() { |
| 949 CachePartition partition = createPartition(); |
| 950 AnalysisTarget target = new TestSource(); |
| 951 expect(partition.get(target), isNull); |
| 952 expect(partition.remove(target), isNull); |
| 953 expect(partition.get(target), isNull); |
| 954 } |
| 955 |
| 956 void test_remove_present() { |
| 949 CachePartition partition = createPartition(); | 957 CachePartition partition = createPartition(); |
| 950 AnalysisTarget target = new TestSource(); | 958 AnalysisTarget target = new TestSource(); |
| 951 CacheEntry entry = new CacheEntry(target); | 959 CacheEntry entry = new CacheEntry(target); |
| 952 partition.put(entry); | 960 partition.put(entry); |
| 953 expect(partition.get(target), entry); | 961 expect(partition.get(target), entry); |
| 954 partition.remove(target); | 962 expect(partition.remove(target), entry); |
| 955 expect(partition.get(target), isNull); | 963 expect(partition.get(target), isNull); |
| 956 } | 964 } |
| 957 } | 965 } |
| 958 | 966 |
| 959 @reflectiveTest | 967 @reflectiveTest |
| 960 class ResultDataTest extends EngineTestCase { | 968 class ResultDataTest extends EngineTestCase { |
| 961 test_creation() { | 969 test_creation() { |
| 962 String value = 'value'; | 970 String value = 'value'; |
| 963 ResultData data = new ResultData(new ResultDescriptor('test', value)); | 971 ResultData data = new ResultData(new ResultDescriptor('test', value)); |
| 964 expect(data, isNotNull); | 972 expect(data, isNotNull); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 expect(partition.isResponsibleFor(target), isTrue); | 1005 expect(partition.isResponsibleFor(target), isTrue); |
| 998 } | 1006 } |
| 999 } | 1007 } |
| 1000 | 1008 |
| 1001 @reflectiveTest | 1009 @reflectiveTest |
| 1002 class UniversalCachePartitionTest extends CachePartitionTest { | 1010 class UniversalCachePartitionTest extends CachePartitionTest { |
| 1003 CachePartition createPartition() { | 1011 CachePartition createPartition() { |
| 1004 return new UniversalCachePartition(null); | 1012 return new UniversalCachePartition(null); |
| 1005 } | 1013 } |
| 1006 | 1014 |
| 1015 void test_contains() { |
| 1016 UniversalCachePartition partition = new UniversalCachePartition(null); |
| 1017 TestSource source = new TestSource(); |
| 1018 expect(partition.isResponsibleFor(source), isTrue); |
| 1019 } |
| 1020 |
| 1007 test_dispose() { | 1021 test_dispose() { |
| 1008 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 1022 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| 1009 CachePartition partition1 = new UniversalCachePartition(context); | 1023 CachePartition partition1 = new UniversalCachePartition(context); |
| 1010 CachePartition partition2 = new UniversalCachePartition(context); | 1024 CachePartition partition2 = new UniversalCachePartition(context); |
| 1011 AnalysisCache cache = new AnalysisCache([partition1, partition2]); | 1025 AnalysisCache cache = new AnalysisCache([partition1, partition2]); |
| 1012 when(context.analysisCache).thenReturn(cache); | 1026 when(context.analysisCache).thenReturn(cache); |
| 1013 // configure | 1027 // configure |
| 1014 // prepare entries | 1028 // prepare entries |
| 1015 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); | 1029 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); |
| 1016 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); | 1030 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1027 // target2 is listed as dependent in target1 | 1041 // target2 is listed as dependent in target1 |
| 1028 expect( | 1042 expect( |
| 1029 entry1.getResultData(descriptor1).dependentResults, contains(result2)); | 1043 entry1.getResultData(descriptor1).dependentResults, contains(result2)); |
| 1030 // dispose | 1044 // dispose |
| 1031 partition2.dispose(); | 1045 partition2.dispose(); |
| 1032 expect(partition1.get(target1), same(entry1)); | 1046 expect(partition1.get(target1), same(entry1)); |
| 1033 expect(partition2.get(target2), isNull); | 1047 expect(partition2.get(target2), isNull); |
| 1034 // result2 is removed from result1 | 1048 // result2 is removed from result1 |
| 1035 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); | 1049 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); |
| 1036 } | 1050 } |
| 1037 | |
| 1038 void test_contains() { | |
| 1039 UniversalCachePartition partition = new UniversalCachePartition(null); | |
| 1040 TestSource source = new TestSource(); | |
| 1041 expect(partition.isResponsibleFor(source), isTrue); | |
| 1042 } | |
| 1043 } | 1051 } |
| 1044 | 1052 |
| 1045 class _InternalAnalysisContextMock extends TypedMock | 1053 class _InternalAnalysisContextMock extends TypedMock |
| 1046 implements InternalAnalysisContext { | 1054 implements InternalAnalysisContext { |
| 1047 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1055 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1048 } | 1056 } |
| 1049 | 1057 |
| 1050 class _TestAnalysisTarget implements AnalysisTarget { | 1058 class _TestAnalysisTarget implements AnalysisTarget { |
| 1051 @override | 1059 @override |
| 1052 Source get source => null; | 1060 Source get source => null; |
| 1053 } | 1061 } |
| OLD | NEW |