|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.beam.runners.dataflow; |
| 19 | + |
| 20 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertFalse; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | + |
| 25 | +import org.apache.beam.sdk.testing.PAssert; |
| 26 | +import org.apache.beam.sdk.testing.TestPipeline; |
| 27 | +import org.apache.beam.sdk.testing.ValidatesRunner; |
| 28 | +import org.apache.beam.sdk.transforms.Create; |
| 29 | +import org.apache.beam.sdk.transforms.GroupByKey; |
| 30 | +import org.apache.beam.sdk.values.KV; |
| 31 | +import org.apache.beam.sdk.values.PCollection; |
| 32 | +import org.hamcrest.Matchers; |
| 33 | +import org.junit.Rule; |
| 34 | +import org.junit.Test; |
| 35 | +import org.junit.experimental.categories.Category; |
| 36 | +import org.junit.runner.RunWith; |
| 37 | +import org.junit.runners.JUnit4; |
| 38 | + |
| 39 | +@RunWith(JUnit4.class) |
| 40 | +public class LargeCommitTest { |
| 41 | + |
| 42 | + @Rule public transient TestPipeline p = TestPipeline.create(); |
| 43 | + |
| 44 | + @Test |
| 45 | + @Category({ValidatesRunner.class}) |
| 46 | + public void testLargeCommit() { |
| 47 | + // 5 50MB values shuffling to a single key |
| 48 | + String value = bigString('a', 50 << 20); |
| 49 | + KV<String, String> kv = KV.of("a", value); |
| 50 | + PCollection<KV<String, Iterable<String>>> result = |
| 51 | + p.apply(Create.of(kv, kv, kv, kv, kv)).apply(GroupByKey.create()); |
| 52 | + |
| 53 | + PAssert.that(result) |
| 54 | + .satisfies( |
| 55 | + kvs -> { |
| 56 | + assertTrue(kvs.iterator().hasNext()); |
| 57 | + KV<String, Iterable<String>> outputKV = kvs.iterator().next(); |
| 58 | + assertFalse(kvs.iterator().hasNext()); |
| 59 | + assertEquals("a", outputKV.getKey()); |
| 60 | + assertThat(outputKV.getValue(), Matchers.contains(value, value, value, value, value)); |
| 61 | + return null; |
| 62 | + }); |
| 63 | + p.run(); |
| 64 | + } |
| 65 | + |
| 66 | + private static String bigString(char c, int size) { |
| 67 | + char[] buf = new char[size]; |
| 68 | + for (int i = 0; i < size; i++) { |
| 69 | + buf[i] = c; |
| 70 | + } |
| 71 | + return new String(buf); |
| 72 | + } |
| 73 | +} |
0 commit comments