OLD | NEW |
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.socket.server; | 5 library test.socket.server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
12 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 12 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
13 import 'package:analysis_server/src/socket_server.dart'; | 13 import 'package:analysis_server/src/socket_server.dart'; |
14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/src/generated/sdk.dart'; |
15 import 'package:analyzer/src/generated/sdk_io.dart'; | 16 import 'package:analyzer/src/generated/sdk_io.dart'; |
16 import 'package:plugin/manager.dart'; | 17 import 'package:plugin/manager.dart'; |
17 import 'package:unittest/unittest.dart'; | 18 import 'package:unittest/unittest.dart'; |
18 | 19 |
19 import 'mocks.dart'; | 20 import 'mocks.dart'; |
20 import 'utils.dart'; | 21 import 'utils.dart'; |
21 | 22 |
22 main() { | 23 main() { |
23 initializeTestEnvironment(); | 24 initializeTestEnvironment(); |
24 group('SocketServer', () { | 25 group('SocketServer', () { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 expect(response.error, isNull); | 105 expect(response.error, isNull); |
105 channel.expectMsgCount(responseCount: 1, notificationCount: 2); | 106 channel.expectMsgCount(responseCount: 1, notificationCount: 2); |
106 expect(channel.notificationsReceived[1].event, SERVER_ERROR); | 107 expect(channel.notificationsReceived[1].event, SERVER_ERROR); |
107 }); | 108 }); |
108 } | 109 } |
109 | 110 |
110 static SocketServer _createSocketServer() { | 111 static SocketServer _createSocketServer() { |
111 ServerPlugin serverPlugin = new ServerPlugin(); | 112 ServerPlugin serverPlugin = new ServerPlugin(); |
112 ExtensionManager manager = new ExtensionManager(); | 113 ExtensionManager manager = new ExtensionManager(); |
113 manager.processPlugins([serverPlugin]); | 114 manager.processPlugins([serverPlugin]); |
| 115 SdkCreator sdkCreator = () => |
| 116 new DirectoryBasedDartSdk(DirectoryBasedDartSdk.defaultSdkDirectory); |
114 return new SocketServer( | 117 return new SocketServer( |
115 new AnalysisServerOptions(), | 118 new AnalysisServerOptions(), |
116 DirectoryBasedDartSdk.defaultSdk, | 119 sdkCreator, |
| 120 sdkCreator(), |
117 InstrumentationService.NULL_SERVICE, | 121 InstrumentationService.NULL_SERVICE, |
118 serverPlugin, | 122 serverPlugin, |
119 null, | 123 null, |
120 null); | 124 null); |
121 } | 125 } |
122 } | 126 } |
123 | 127 |
124 class _MockRequestHandler implements RequestHandler { | 128 class _MockRequestHandler implements RequestHandler { |
125 final bool futureException; | 129 final bool futureException; |
126 | 130 |
127 _MockRequestHandler(this.futureException); | 131 _MockRequestHandler(this.futureException); |
128 | 132 |
129 @override | 133 @override |
130 Response handleRequest(Request request) { | 134 Response handleRequest(Request request) { |
131 if (futureException) { | 135 if (futureException) { |
132 new Future(throwException); | 136 new Future(throwException); |
133 return new Response(request.id); | 137 return new Response(request.id); |
134 } | 138 } |
135 throw 'mock request exception'; | 139 throw 'mock request exception'; |
136 } | 140 } |
137 | 141 |
138 void throwException() { | 142 void throwException() { |
139 throw 'mock future exception'; | 143 throw 'mock future exception'; |
140 } | 144 } |
141 } | 145 } |
OLD | NEW |