| 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=32 | 5 // VMOptions=--old_gen_heap_size=32 |
| 6 | 6 |
| 7 library slow_consumer3_test; | 7 library slow_consumer3_test; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 }, | 46 }, |
| 47 onDone: () { result.complete(receivedCount); }); | 47 onDone: () { result.complete(receivedCount); }); |
| 48 return result.future; | 48 return result.future; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 Stream<List> dataGenerator(int bytesTotal, int chunkSize) { | 52 Stream<List> dataGenerator(int bytesTotal, int chunkSize) { |
| 53 int chunks = bytesTotal ~/ chunkSize; | 53 int chunks = bytesTotal ~/ chunkSize; |
| 54 return new Stream.fromIterable(new Iterable.generate(chunks, (_) { | 54 return new Stream.fromIterable(new Iterable.generate(chunks, (_) { |
| 55 // This assumes one byte per entry. In practice it will be more. | 55 // This assumes one byte per entry. In practice it will be more. |
| 56 return new List<int>.fixedLength(chunkSize); | 56 return new List<int>(chunkSize); |
| 57 })); | 57 })); |
| 58 } | 58 } |
| 59 | 59 |
| 60 main() { | 60 main() { |
| 61 var port = new ReceivePort(); | 61 var port = new ReceivePort(); |
| 62 // The data provider can deliver 800MBs of data as fast as it is | 62 // The data provider can deliver 800MBs of data as fast as it is |
| 63 // requested. The data is sent in 0.5MB chunks. The consumer has a buffer of | 63 // requested. The data is sent in 0.5MB chunks. The consumer has a buffer of |
| 64 // 3MB. That is, it can accept a few packages without pausing its input. | 64 // 3MB. That is, it can accept a few packages without pausing its input. |
| 65 // | 65 // |
| 66 // Notice that we aren't really counting bytes, but words, since we use normal | 66 // Notice that we aren't really counting bytes, but words, since we use normal |
| 67 // lists where each entry takes up a full word. In 64-bit VMs this will be | 67 // lists where each entry takes up a full word. In 64-bit VMs this will be |
| 68 // 8 bytes per entry, so the 3*MB buffer is picked to stay below 32 actual | 68 // 8 bytes per entry, so the 3*MB buffer is picked to stay below 32 actual |
| 69 // MiB. | 69 // MiB. |
| 70 // | 70 // |
| 71 // This test is limited to 32MB of heap-space (see VMOptions on top of the | 71 // This test is limited to 32MB of heap-space (see VMOptions on top of the |
| 72 // file). If the consumer doesn't pause the data-provider it will run out of | 72 // file). If the consumer doesn't pause the data-provider it will run out of |
| 73 // heap-space. | 73 // heap-space. |
| 74 | 74 |
| 75 dataGenerator(100 * MB, 512 * KB) | 75 dataGenerator(100 * MB, 512 * KB) |
| 76 .pipe(new SlowConsumer(200 * MB, 3 * MB)) | 76 .pipe(new SlowConsumer(200 * MB, 3 * MB)) |
| 77 .then((count) { | 77 .then((count) { |
| 78 port.close(); | 78 port.close(); |
| 79 Expect.equals(100 * MB, count); | 79 Expect.equals(100 * MB, count); |
| 80 }); | 80 }); |
| 81 } | 81 } |
| OLD | NEW |