| 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:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:isolate'; | 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.immediate(0); | 18 var current = new Future.value(0); |
| 19 final int bytesPerSecond; | 19 final int bytesPerSecond; |
| 20 int finalCount; | 20 int finalCount; |
| 21 | 21 |
| 22 SlowConsumer(int this.bytesPerSecond); | 22 SlowConsumer(int this.bytesPerSecond); |
| 23 | 23 |
| 24 Future consume(Stream stream) { | 24 Future consume(Stream stream) { |
| 25 return addStream(stream).then((_) => close()); | 25 return addStream(stream).then((_) => close()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 Future addStream(Stream stream) { | 28 Future addStream(Stream stream) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 done = true; | 48 done = true; |
| 49 current.then((count) { | 49 current.then((count) { |
| 50 finalCount = count; | 50 finalCount = count; |
| 51 completer.complete(count); | 51 completer.complete(count); |
| 52 }); | 52 }); |
| 53 }); | 53 }); |
| 54 return completer.future; | 54 return completer.future; |
| 55 } | 55 } |
| 56 | 56 |
| 57 Future close() { | 57 Future close() { |
| 58 return new Future.immediate(finalCount); | 58 return new Future.value(finalCount); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 class DataProvider { | 62 class DataProvider { |
| 63 final int chunkSize; | 63 final int chunkSize; |
| 64 final int bytesPerSecond; | 64 final int bytesPerSecond; |
| 65 int sentCount = 0; | 65 int sentCount = 0; |
| 66 int targetCount; | 66 int targetCount; |
| 67 StreamController controller; | 67 StreamController controller; |
| 68 Timer pendingSend; | 68 Timer pendingSend; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // file). If the consumer doesn't pause the data-provider it will run out of | 115 // file). If the consumer doesn't pause the data-provider it will run out of |
| 116 // heap-space. | 116 // heap-space. |
| 117 | 117 |
| 118 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream | 118 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream |
| 119 .pipe(new SlowConsumer(200 * MB)) | 119 .pipe(new SlowConsumer(200 * MB)) |
| 120 .then((count) { | 120 .then((count) { |
| 121 port.close(); | 121 port.close(); |
| 122 Expect.equals(100 * MB, count); | 122 Expect.equals(100 * MB, count); |
| 123 }); | 123 }); |
| 124 } | 124 } |
| OLD | NEW |