snuyanzin commented on code in PR #29895: URL: https://github.com/apache/flink/pull/29895#discussion_r4551023355
########## flink-table/flink-table-code-splitter/src/test/java/org/apache/flink/table/codesplit/FlinkTokenStreamRewriterTest.java: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.codesplit; + +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStreamRewriter; +import org.antlr.v4.runtime.misc.Interval; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.function.Supplier; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for {@link FlinkTokenStreamRewriter}. */ +class FlinkTokenStreamRewriterTest { + + private static final String CODE = + "class A { int a = 1; void f(int x) { if (x > 0) { a = x; } else { return; } } }"; + + private static final String[] KINDS = {"insertBefore", "insertAfter", "replace", "delete"}; + + private static final int SEEDS = 100_000; + private static final int CHUNKS = 8; + + @ParameterizedTest + @MethodSource("chunks") + @Execution(ExecutionMode.CONCURRENT) + void sameOutputAsTokenStreamRewriter(int chunk) { + for (long seed = (long) chunk * SEEDS / CHUNKS; + seed < (long) (chunk + 1) * SEEDS / CHUNKS; + seed++) { + Random random = new Random(seed); + CommonTokenStream tokens = + new CommonTokenStream(new JavaLexer(CharStreams.fromString(CODE))); + // fills the token stream, so it goes before tokens.size() + FlinkTokenStreamRewriter actual = new FlinkTokenStreamRewriter(tokens); + TokenStreamRewriter expected = new TokenStreamRewriter(tokens); + int size = tokens.size(); + + List<Runnable> actualOps = new ArrayList<>(); + List<Runnable> expectedOps = new ArrayList<>(); + StringBuilder description = new StringBuilder(); + for (int i = random.nextInt(8); i >= 0; i--) { + int start = random.nextInt(size - 1); + Token a = tokens.get(start); + Token b = tokens.get(Math.min(start + random.nextInt(4), size - 2)); Review Comment: >The 100k seeds I put 100k for CI here, locally I experimented with 720_000_000 (on my machine it was almost 30 min) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
