| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("MandelIsolateTest"); | 5 #library("MandelIsolateTest"); |
| 6 #import('TestFramework.dart'); | 6 #import('TestFramework.dart'); |
| 7 | 7 |
| 8 final TERMINATION_MESSAGE = -1; | 8 final TERMINATION_MESSAGE = -1; |
| 9 final N = 100; | 9 final N = 100; |
| 10 final ISOLATES = 20; | 10 final ISOLATES = 20; |
| 11 | 11 |
| 12 void test(TestExpectation expect) { | 12 void test(TestExpectation expect) { |
| 13 final state = new MandelbrotState(); | 13 final state = new MandelbrotState(); |
| 14 expect.completes(state._validated).then((result) { | 14 expect.completes(state._validated.future).then((result) { |
| 15 Expect.isTrue(result); | 15 Expect.isTrue(result); |
| 16 expect.succeeded(); | 16 expect.succeeded(); |
| 17 }); | 17 }); |
| 18 for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i); | 18 for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i); |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| 22 class MandelbrotState { | 22 class MandelbrotState { |
| 23 | 23 |
| 24 MandelbrotState() { | 24 MandelbrotState() { |
| 25 _result = new List<List<int>>(N); | 25 _result = new List<List<int>>(N); |
| 26 _lineProcessedBy = new List<LineProcessorClient>(N); | 26 _lineProcessedBy = new List<LineProcessorClient>(N); |
| 27 _sent = 0; | 27 _sent = 0; |
| 28 _missing = N; | 28 _missing = N; |
| 29 _validated = new Promise<bool>(); | 29 _validated = new Completer<bool>(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void startClient(int id) { | 32 void startClient(int id) { |
| 33 assert(_sent < N); | 33 assert(_sent < N); |
| 34 final client = new LineProcessorClient(this, id); | 34 final client = new LineProcessorClient(this, id); |
| 35 client.processLine(_sent++); | 35 client.processLine(_sent++); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) { | 38 void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) { |
| 39 assert(_result[y] === null); | 39 assert(_result[y] === null); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 } | 68 } |
| 69 output.add("\n"); | 69 output.add("\n"); |
| 70 } | 70 } |
| 71 // print(output); | 71 // print(output); |
| 72 } | 72 } |
| 73 | 73 |
| 74 List<List<int>> _result; | 74 List<List<int>> _result; |
| 75 List<LineProcessorClient> _lineProcessedBy; | 75 List<LineProcessorClient> _lineProcessedBy; |
| 76 int _sent; | 76 int _sent; |
| 77 int _missing; | 77 int _missing; |
| 78 Promise<bool> _validated; | 78 Completer<bool> _validated; |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 class LineProcessorClient { | 82 class LineProcessorClient { |
| 83 | 83 |
| 84 LineProcessorClient(MandelbrotState this._state, int this._id) { | 84 LineProcessorClient(MandelbrotState this._state, int this._id) { |
| 85 _out = new LineProcessor().spawn(); | 85 _out = new LineProcessor().spawn(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void processLine(int y) { | 88 void processLine(int y) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 result[x] = i; | 146 result[x] = i; |
| 147 } | 147 } |
| 148 return result; | 148 return result; |
| 149 } | 149 } |
| 150 | 150 |
| 151 } | 151 } |
| 152 | 152 |
| 153 main() { | 153 main() { |
| 154 runTests([test]); | 154 runTests([test]); |
| 155 } | 155 } |
| OLD | NEW |