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

Side by Side Diff: pkg/analysis_server/test/index/store/split_store_test.dart

Issue 351813002: A local file-based Index implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.index.split.store; 5 library test.index.split_store;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/index/store/codec.dart'; 10 import 'package:analysis_server/src/index/store/codec.dart';
11 import 'package:analysis_server/src/index/store/split_store.dart'; 11 import 'package:analysis_server/src/index/store/split_store.dart';
12 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/index.dart'; 14 import 'package:analyzer/src/generated/index.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:typed_mock/typed_mock.dart'; 16 import 'package:typed_mock/typed_mock.dart';
17 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
18 18
19 import '../../reflective_tests.dart'; 19 import '../../reflective_tests.dart';
20 import 'single_source_container.dart';
20 import 'typed_mocks.dart'; 21 import 'typed_mocks.dart';
21 22
22 23
23 main() { 24 main() {
24 groupSep = ' | '; 25 groupSep = ' | ';
25 group('FileNodeManager', () { 26 group('FileNodeManager', () {
26 runReflectiveTests(_FileNodeManagerTest); 27 runReflectiveTests(_FileNodeManagerTest);
27 }); 28 });
28 group('IndexNode', () { 29 group('IndexNode', () {
29 runReflectiveTests(_IndexNodeTest); 30 runReflectiveTests(_IndexNodeTest);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 // equals 535 // equals
535 expect(keyData == this, isFalse); 536 expect(keyData == this, isFalse);
536 expect(keyData == new RelationKeyData.forData(10, 20), isFalse); 537 expect(keyData == new RelationKeyData.forData(10, 20), isFalse);
537 expect(keyData == keyData, isTrue); 538 expect(keyData == keyData, isTrue);
538 expect(keyData == new RelationKeyData.forData(elementId, relationshipId), 539 expect(keyData == new RelationKeyData.forData(elementId, relationshipId),
539 isTrue); 540 isTrue);
540 } 541 }
541 } 542 }
542 543
543 544
544 class _SingleSourceContainer implements SourceContainer {
545 final Source _source;
546 _SingleSourceContainer(this._source);
547 @override
548 bool contains(Source source) => source == _source;
549 }
550 545
551 546
552 @ReflectiveTestCase() 547 @ReflectiveTestCase()
553 class _SplitIndexStoreTest { 548 class _SplitIndexStoreTest {
554 AnalysisContext contextA = new MockAnalysisContext('contextA'); 549 AnalysisContext contextA = new MockAnalysisContext('contextA');
555 550
556 AnalysisContext contextB = new MockAnalysisContext('contextB'); 551 AnalysisContext contextB = new MockAnalysisContext('contextB');
557 552
558 AnalysisContext contextC = new MockAnalysisContext('contextC'); 553 AnalysisContext contextC = new MockAnalysisContext('contextC');
559 554
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 when(unitElementC.library).thenReturn(libraryElement); 623 when(unitElementC.library).thenReturn(libraryElement);
629 when(unitElementD.library).thenReturn(libraryElement); 624 when(unitElementD.library).thenReturn(libraryElement);
630 when(htmlElementA.source).thenReturn(sourceA); 625 when(htmlElementA.source).thenReturn(sourceA);
631 when(htmlElementB.source).thenReturn(sourceB); 626 when(htmlElementB.source).thenReturn(sourceB);
632 // library 627 // library
633 when(libraryUnitElement.library).thenReturn(libraryElement); 628 when(libraryUnitElement.library).thenReturn(libraryElement);
634 when(libraryUnitElement.source).thenReturn(librarySource); 629 when(libraryUnitElement.source).thenReturn(librarySource);
635 when(libraryElement.source).thenReturn(librarySource); 630 when(libraryElement.source).thenReturn(librarySource);
636 when(libraryElement.definingCompilationUnit).thenReturn(libraryUnitElement); 631 when(libraryElement.definingCompilationUnit).thenReturn(libraryUnitElement);
637 } 632 }
633
638 void test_aboutToIndexDart_disposedContext() { 634 void test_aboutToIndexDart_disposedContext() {
639 when(contextA.isDisposed).thenReturn(true); 635 when(contextA.isDisposed).thenReturn(true);
640 expect(store.aboutToIndexDart(contextA, unitElementA), isFalse); 636 expect(store.aboutToIndexDart(contextA, unitElementA), isFalse);
641 } 637 }
638
642 void test_aboutToIndexDart_disposedContext_wrapped() { 639 void test_aboutToIndexDart_disposedContext_wrapped() {
643 when(contextA.isDisposed).thenReturn(true); 640 when(contextA.isDisposed).thenReturn(true);
644 InstrumentedAnalysisContextImpl instrumentedContext = 641 InstrumentedAnalysisContextImpl instrumentedContext =
645 new MockInstrumentedAnalysisContextImpl(); 642 new MockInstrumentedAnalysisContextImpl();
646 when(instrumentedContext.basis).thenReturn(contextA); 643 when(instrumentedContext.basis).thenReturn(contextA);
647 expect(store.aboutToIndexDart(instrumentedContext, unitElementA), isFalse); 644 expect(store.aboutToIndexDart(instrumentedContext, unitElementA), isFalse);
648 } 645 }
649 646
650 void test_aboutToIndexDart_library_first() { 647 void test_aboutToIndexDart_library_first() {
651 when(libraryElement.parts).thenReturn(<CompilationUnitElement>[unitElementA, 648 when(libraryElement.parts).thenReturn(<CompilationUnitElement>[unitElementA,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 store.aboutToIndexDart(contextA, unitElementB); 941 store.aboutToIndexDart(contextA, unitElementB);
945 store.recordRelationship(elementA, relationship, locationB); 942 store.recordRelationship(elementA, relationship, locationB);
946 store.doneIndex(); 943 store.doneIndex();
947 } 944 }
948 // "A" and "B" locations 945 // "A" and "B" locations
949 return store.getRelationshipsAsync(elementA, relationship).then( 946 return store.getRelationshipsAsync(elementA, relationship).then(
950 (List<Location> locations) { 947 (List<Location> locations) {
951 assertLocations(locations, [locationA, locationB]); 948 assertLocations(locations, [locationA, locationB]);
952 }).then((_) { 949 }).then((_) {
953 // remove "librarySource" 950 // remove "librarySource"
954 store.removeSources(contextA, new _SingleSourceContainer(librarySource)); 951 store.removeSources(contextA, new SingleSourceContainer(librarySource));
955 return store.getRelationshipsAsync(elementA, relationship).then( 952 return store.getRelationshipsAsync(elementA, relationship).then(
956 (List<Location> locations) { 953 (List<Location> locations) {
957 assertLocations(locations, []); 954 assertLocations(locations, []);
958 }); 955 });
959 }); 956 });
960 } 957 }
961 958
962 void test_removeSources_nullContext() { 959 void test_removeSources_nullContext() {
963 store.removeSources(null, null); 960 store.removeSources(null, null);
964 } 961 }
(...skipping 16 matching lines...) Expand all
981 store.aboutToIndexDart(contextA, unitElementC); 978 store.aboutToIndexDart(contextA, unitElementC);
982 store.recordRelationship(elementA, relationship, locationC); 979 store.recordRelationship(elementA, relationship, locationC);
983 store.doneIndex(); 980 store.doneIndex();
984 } 981 }
985 // "A", "B" and "C" locations 982 // "A", "B" and "C" locations
986 return store.getRelationshipsAsync(elementA, relationship).then( 983 return store.getRelationshipsAsync(elementA, relationship).then(
987 (List<Location> locations) { 984 (List<Location> locations) {
988 assertLocations(locations, [locationA, locationB, locationC]); 985 assertLocations(locations, [locationA, locationB, locationC]);
989 }).then((_) { 986 }).then((_) {
990 // remove "A" source 987 // remove "A" source
991 store.removeSources(contextA, new _SingleSourceContainer(sourceA)); 988 store.removeSources(contextA, new SingleSourceContainer(sourceA));
992 store.removeSource(contextA, sourceA); 989 store.removeSource(contextA, sourceA);
993 return store.getRelationshipsAsync(elementA, relationship).then( 990 return store.getRelationshipsAsync(elementA, relationship).then(
994 (List<Location> locations) { 991 (List<Location> locations) {
995 assertLocations(locations, [locationB, locationC]); 992 assertLocations(locations, [locationB, locationC]);
996 }); 993 });
997 }); 994 });
998 } 995 }
999 996
1000 test_universe_aboutToIndex() { 997 test_universe_aboutToIndex() {
1001 when(contextA.getElement(elementLocationA)).thenReturn(elementA); 998 when(contextA.getElement(elementLocationA)).thenReturn(elementA);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 }).then((_) { 1049 }).then((_) {
1053 // remove "contextA" 1050 // remove "contextA"
1054 store.removeContext(contextA); 1051 store.removeContext(contextA);
1055 return store.getRelationshipsAsync(UniverseElement.INSTANCE, 1052 return store.getRelationshipsAsync(UniverseElement.INSTANCE,
1056 relationship).then((List<Location> locations) { 1053 relationship).then((List<Location> locations) {
1057 assertLocations(locations, [locationB]); 1054 assertLocations(locations, [locationB]);
1058 }); 1055 });
1059 }); 1056 });
1060 } 1057 }
1061 1058
1059 test_universe_removeSource() {
1060 when(contextA.getElement(elementLocationA)).thenReturn(elementA);
1061 when(contextB.getElement(elementLocationB)).thenReturn(elementB);
1062 Location locationA = mockLocation(elementA);
1063 Location locationB = mockLocation(elementB);
1064 {
1065 store.aboutToIndexDart(contextA, unitElementA);
1066 store.recordRelationship(UniverseElement.INSTANCE, relationship,
1067 locationA);
1068 store.doneIndex();
1069 }
1070 {
1071 store.aboutToIndexDart(contextA, unitElementB);
1072 store.recordRelationship(UniverseElement.INSTANCE, relationship,
1073 locationB);
1074 store.doneIndex();
1075 }
1076 return store.getRelationshipsAsync(UniverseElement.INSTANCE,
1077 relationship).then((List<Location> locations) {
1078 assertLocations(locations, [locationA, locationB]);
1079 }).then((_) {
1080 // remove "sourceA"
1081 store.removeSource(contextA, sourceA);
1082 return store.getRelationshipsAsync(UniverseElement.INSTANCE,
1083 relationship).then((List<Location> locations) {
1084 assertLocations(locations, [locationB]);
1085 });
1086 });
1087 }
1088
1089 test_universe_clear() {
1090 when(contextA.getElement(elementLocationA)).thenReturn(elementA);
1091 when(contextB.getElement(elementLocationB)).thenReturn(elementB);
1092 Location locationA = mockLocation(elementA);
1093 Location locationB = mockLocation(elementB);
1094 {
1095 store.aboutToIndexDart(contextA, unitElementA);
1096 store.recordRelationship(UniverseElement.INSTANCE, relationship,
1097 locationA);
1098 store.doneIndex();
1099 }
1100 {
1101 store.aboutToIndexDart(contextA, unitElementB);
1102 store.recordRelationship(UniverseElement.INSTANCE, relationship,
1103 locationB);
1104 store.doneIndex();
1105 }
1106 return store.getRelationshipsAsync(UniverseElement.INSTANCE,
1107 relationship).then((List<Location> locations) {
1108 assertLocations(locations, [locationA, locationB]);
1109 }).then((_) {
1110 // clear
1111 store.clear();
1112 return store.getRelationshipsAsync(UniverseElement.INSTANCE,
1113 relationship).then((List<Location> locations) {
1114 expect(locations, isEmpty);
1115 });
1116 });
1117 }
1118
1062 /** 1119 /**
1063 * Asserts that the [actual] locations have all the [expected] locations and 1120 * Asserts that the [actual] locations have all the [expected] locations and
1064 * only them. 1121 * only them.
1065 */ 1122 */
1066 static void assertLocations(List<Location> actual, List<Location> expected) { 1123 static void assertLocations(List<Location> actual, List<Location> expected) {
1067 List<_LocationEqualsWrapper> actualWrappers = wrapLocations(actual); 1124 List<_LocationEqualsWrapper> actualWrappers = wrapLocations(actual);
1068 List<_LocationEqualsWrapper> expectedWrappers = wrapLocations(expected); 1125 List<_LocationEqualsWrapper> expectedWrappers = wrapLocations(expected);
1069 expect(actualWrappers, unorderedEquals(expectedWrappers)); 1126 expect(actualWrappers, unorderedEquals(expectedWrappers));
1070 } 1127 }
1071 1128
(...skipping 12 matching lines...) Expand all
1084 * Wraps the given locations into [LocationEqualsWrapper]. 1141 * Wraps the given locations into [LocationEqualsWrapper].
1085 */ 1142 */
1086 static List<_LocationEqualsWrapper> wrapLocations(List<Location> locations) { 1143 static List<_LocationEqualsWrapper> wrapLocations(List<Location> locations) {
1087 List<_LocationEqualsWrapper> wrappers = <_LocationEqualsWrapper>[]; 1144 List<_LocationEqualsWrapper> wrappers = <_LocationEqualsWrapper>[];
1088 for (Location location in locations) { 1145 for (Location location in locations) {
1089 wrappers.add(new _LocationEqualsWrapper(location)); 1146 wrappers.add(new _LocationEqualsWrapper(location));
1090 } 1147 }
1091 return wrappers; 1148 return wrappers;
1092 } 1149 }
1093 } 1150 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/index/store/single_source_container.dart ('k') | pkg/analysis_server/test/index/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698