| 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_consumer3_test; | 7 library slow_consumer3_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 int receivedCount = 0; | 18 int receivedCount = 0; |
| 19 final int bytesPerSecond; | 19 final int bytesPerSecond; |
| 20 final int bufferSize; | 20 final int bufferSize; |
| 21 final List bufferedData = []; | 21 final List bufferedData = []; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 Stream<List> dataGenerator(int bytesTotal, int chunkSize) { | 65 Stream<List> dataGenerator(int bytesTotal, int chunkSize) { |
| 66 int chunks = bytesTotal ~/ chunkSize; | 66 int chunks = bytesTotal ~/ chunkSize; |
| 67 return new Stream.fromIterable(new Iterable.generate(chunks, (_) { | 67 return new Stream.fromIterable(new Iterable.generate(chunks, (_) { |
| 68 // This assumes one byte per entry. In practice it will be more. | 68 // This assumes one byte per entry. In practice it will be more. |
| 69 return new List<int>(chunkSize); | 69 return new List<int>(chunkSize); |
| 70 })); | 70 })); |
| 71 } | 71 } |
| 72 | 72 |
| 73 main() { | 73 main() { |
| 74 var port = new ReceivePort(); | 74 asyncStart(); |
| 75 // The data provider can deliver 800MBs of data as fast as it is | 75 // The data provider can deliver 800MBs of data as fast as it is |
| 76 // requested. The data is sent in 0.5MB chunks. The consumer has a buffer of | 76 // requested. The data is sent in 0.5MB chunks. The consumer has a buffer of |
| 77 // 3MB. That is, it can accept a few packages without pausing its input. | 77 // 3MB. That is, it can accept a few packages without pausing its input. |
| 78 // | 78 // |
| 79 // Notice that we aren't really counting bytes, but words, since we use normal | 79 // Notice that we aren't really counting bytes, but words, since we use normal |
| 80 // lists where each entry takes up a full word. In 64-bit VMs this will be | 80 // lists where each entry takes up a full word. In 64-bit VMs this will be |
| 81 // 8 bytes per entry, so the 3*MB buffer is picked to stay below 32 actual | 81 // 8 bytes per entry, so the 3*MB buffer is picked to stay below 32 actual |
| 82 // MiB. | 82 // MiB. |
| 83 // | 83 // |
| 84 // This test is limited to 32MB of heap-space (see VMOptions on top of the | 84 // This test is limited to 32MB of heap-space (see VMOptions on top of the |
| 85 // file). If the consumer doesn't pause the data-provider it will run out of | 85 // file). If the consumer doesn't pause the data-provider it will run out of |
| 86 // heap-space. | 86 // heap-space. |
| 87 | 87 |
| 88 dataGenerator(100 * MB, 512 * KB) | 88 dataGenerator(100 * MB, 512 * KB) |
| 89 .pipe(new SlowConsumer(200 * MB, 3 * MB)) | 89 .pipe(new SlowConsumer(200 * MB, 3 * MB)) |
| 90 .then((count) { | 90 .then((count) { |
| 91 port.close(); | |
| 92 Expect.equals(100 * MB, count); | 91 Expect.equals(100 * MB, count); |
| 92 asyncEnd(); |
| 93 }); | 93 }); |
| 94 } | 94 } |
| OLD | NEW |