GJL commented on a change in pull request #7986: [FLINK-10517][rest] Add stability test URL: https://github.com/apache/flink/pull/7986#discussion_r267058692
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/rest/compatibility/CompatibilityRoutine.java ########## @@ -0,0 +1,114 @@ +/* + * 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.runtime.rest.compatibility; + +import org.apache.flink.runtime.rest.messages.MessageHeaders; + +import org.junit.Assert; + +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static org.apache.flink.runtime.rest.compatibility.Compatibility.COMPATIBLE; +import static org.apache.flink.runtime.rest.compatibility.Compatibility.IDENTICAL; +import static org.apache.flink.runtime.rest.compatibility.Compatibility.INCOMPATIBLE; + +/** + * Routine for checking the compatibility of a {@link MessageHeaders} pair. + * + * <p>The 'extractor' {@link Function} generates a 'container', a jackson-compatible object containing the data that + * the routine bases it's compatibility-evaluation on. + * The 'assertion' {@link BiConsumer} accepts a pair of containers and asserts the compatibility. Incompatibilities are + * signaled by throwing an {@link AssertionError}. This implies that the method body will typically contain jUnit + * assertions. + */ +final class CompatibilityRoutine<C> { + + private final String key; + private final Class<C> containerClass; + private final Function<MessageHeaders<?, ?, ?>, C> extractor; + private final BiConsumer<C, C> assertion; + + CompatibilityRoutine( + final String key, + final Class<C> containerClass, + final Function<MessageHeaders<?, ?, ?>, C> extractor, + final BiConsumer<C, C> assertion) { + this.key = key; + this.containerClass = containerClass; + this.extractor = extractor; + this.assertion = assertion; + } + + String getKey() { + return key; + } + + Class<C> getContainerClass() { + return containerClass; + } + + C getContainer(final MessageHeaders<?, ?, ?> header) { + final C container = extractor.apply(header); + Assert.assertNotNull("Implementation error: Extractor returned null.", container); + return container; + } + + public CompatibilityCheckResult checkCompatibility(final Optional<C> old, final Optional<C> cur) { Review comment: Maybe use default visibility for consistency. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services