pnowojski commented on a change in pull request #7570: [FLINK-11422] Prefer testing class to mock StreamTask in AbstractStre… URL: https://github.com/apache/flink/pull/7570#discussion_r251803166
########## File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/MockStreamTaskBuilder.java ########## @@ -0,0 +1,127 @@ +/* + * 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.api.common.ExecutionConfig; +import org.apache.flink.api.common.accumulators.Accumulator; +import org.apache.flink.core.fs.CloseableRegistry; +import org.apache.flink.runtime.execution.Environment; +import org.apache.flink.runtime.state.CheckpointStorage; +import org.apache.flink.streaming.api.graph.StreamConfig; +import org.apache.flink.streaming.api.operators.StreamTaskStateInitializer; +import org.apache.flink.streaming.runtime.streamstatus.StreamStatusMaintainer; +import org.apache.flink.streaming.runtime.tasks.ProcessingTimeService; + +import java.util.Collections; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * A builder of {@link MockStreamTask}. + */ +public class MockStreamTaskBuilder { + private Environment environment; Review comment: You have to make sure that all of the values are initialised somehow before calling the `build()` method. Otherwise one might forget to call them and would get null pointer exceptions (the same issue as with mockito's mocks). 1. please add default values for all of the fields that have a sensible default, like `name`, `checkpointLock = new Object()`, `config = new StreamConfig()`, `closeableRegistry = new CloseableRegistry();` etc... 2. if default value is sometimes overwritten add a setter, if it's not, do not add setter 3. if parameter does not have good default value (like `environment`) make it an obligatory parameter that is passed in the constructor of `MockStreamTaskBuilder`, mark it as final and do not add setter for it. Having good default values would also simplify construction of the builder. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
