dawidwys commented on a change in pull request #15313: URL: https://github.com/apache/flink/pull/15313#discussion_r603291457
########## File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/TestCheckpointedInputGateBuilder.java ########## @@ -0,0 +1,135 @@ +/* + * 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.streaming.util; + +import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter; +import org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter; +import org.apache.flink.runtime.io.network.buffer.NetworkBufferPool; +import org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder; +import org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel; +import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate; +import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder; +import org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel; +import org.apache.flink.streaming.api.operators.MailboxExecutor; +import org.apache.flink.streaming.api.operators.SyncMailboxExecutor; +import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointBarrierHandler; +import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate; +import org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor; +import org.apache.flink.util.function.SupplierWithException; + +import java.io.IOException; +import java.util.function.BiFunction; + +/** A builder for creating instances of {@link CheckpointedInputGate} for tests. */ +public class TestCheckpointedInputGateBuilder { + private final int numChannels; + private final BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler> + barrierHandlerFactory; + + private ChannelStateWriter channelStateWriter = new RecordingChannelStateWriter(); + private SupplierWithException<SingleInputGate, IOException> gateBuilder = this::buildTestGate; + private MailboxExecutor mailboxExecutor; + + private TestCheckpointedInputGateBuilder( + int numChannels, + BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler> + barrierHandler) { + this.numChannels = numChannels; + this.barrierHandlerFactory = barrierHandler; + + this.mailboxExecutor = new SyncMailboxExecutor(); + } + + public static TestCheckpointedInputGateBuilder builder( + int numChannels, + BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler> + barrierHandlerFactory) { + return new TestCheckpointedInputGateBuilder(numChannels, barrierHandlerFactory); + } + + /** + * Uses {@link RemoteInputChannel RemoteInputChannels} and enables {@link + * #withMailboxExecutor()} by default. + */ + public TestCheckpointedInputGateBuilder withRemoteChannels() { + this.gateBuilder = this::buildRemoteGate; + return withMailboxExecutor(); Review comment: I did it because it was always that combination: remote channels -> mailbox executor, test channels -> sync executor, but you are right it does not need to be like this. I'll change it. -- 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. For queries about this service, please contact Infrastructure at: [email protected]
