| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // VMOptions=--old_gen_heap_size=64 | 5 // VMOptions=--old_gen_heap_size=64 |
| 6 | 6 |
| 7 library slow_consumer_test; | 7 library slow_consumer_test; |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; |
| 9 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 10 import 'dart:async'; | 11 import 'dart:async'; |
| 11 import 'dart:isolate'; | |
| 12 | 12 |
| 13 const int KB = 1024; | 13 const int KB = 1024; |
| 14 const int MB = KB * KB; | 14 const int MB = KB * KB; |
| 15 const int GB = KB * KB * KB; | 15 const int GB = KB * KB * KB; |
| 16 | 16 |
| 17 class SlowConsumer extends StreamConsumer { | 17 class SlowConsumer extends StreamConsumer { |
| 18 var current = new Future.value(0); | 18 var current = new Future.value(0); |
| 19 final int bytesPerSecond; | 19 final int bytesPerSecond; |
| 20 int finalCount; | 20 int finalCount; |
| 21 | 21 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 onPauseStateChange() { | 104 onPauseStateChange() { |
| 105 // We don't care if we just unpaused or paused. In either case we just | 105 // We don't care if we just unpaused or paused. In either case we just |
| 106 // call send which will test it for us. | 106 // call send which will test it for us. |
| 107 send(); | 107 send(); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 main() { | 111 main() { |
| 112 var port = new ReceivePort(); | 112 asyncStart(); |
| 113 // The data provider can deliver 800MB/s of data. It sends 100MB of data to | 113 // The data provider can deliver 800MB/s of data. It sends 100MB of data to |
| 114 // the slower consumer who can only read 200MB/s. The data is sent in 1MB | 114 // the slower consumer who can only read 200MB/s. The data is sent in 1MB |
| 115 // chunks. | 115 // chunks. |
| 116 // | 116 // |
| 117 // This test is limited to 64MB of heap-space (see VMOptions on top of the | 117 // This test is limited to 64MB of heap-space (see VMOptions on top of the |
| 118 // file). If the consumer doesn't pause the data-provider it will run out of | 118 // file). If the consumer doesn't pause the data-provider it will run out of |
| 119 // heap-space. | 119 // heap-space. |
| 120 | 120 |
| 121 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream | 121 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream |
| 122 .pipe(new SlowConsumer(200 * MB)) | 122 .pipe(new SlowConsumer(200 * MB)) |
| 123 .then((count) { | 123 .then((count) { |
| 124 port.close(); | |
| 125 Expect.equals(100 * MB, count); | 124 Expect.equals(100 * MB, count); |
| 125 asyncEnd(); |
| 126 }); | 126 }); |
| 127 } | 127 } |
| OLD | NEW |