igalshilman commented on a change in pull request #28: [FLINK-16159] [tests, build] Add verification integration test + integrate with Maven build URL: https://github.com/apache/flink-statefun/pull/28#discussion_r381997568
########## File path: statefun-integration-tests/statefun-sanity-itcase/src/test/java/org/apache/flink/statefun/itcases/sanity/SanityVerificationITCase.java ########## @@ -0,0 +1,287 @@ +/* + * 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.statefun.itcases.sanity; + +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.nio.file.Paths; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.Command; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.FnAddress; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.Modify; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.Noop; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.Send; +import org.apache.flink.statefun.itcases.sanity.generated.VerificationMessages.StateSnapshot; +import org.apache.kafka.clients.consumer.Consumer; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.common.serialization.Deserializer; +import org.apache.kafka.common.serialization.Serializer; +import org.junit.Rule; +import org.junit.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.images.builder.ImageFromDockerfile; + +/** + * Sanity verification integration test based on the {@link SanityVerificationModule} application. + * + * <p>The integration test setups Kafka brokers and the verification application using Docker, sends + * a few commands to Kafka to be consumed by the application, and finally verifies that outputs sent + * to Kafka from the application are correct. + */ +public class SanityVerificationITCase { + + private static final String CONFLUENT_PLATFORM_VERSION = "5.0.3"; + + private static final ImageFromDockerfile verificationAppImage = + new ImageFromDockerfile("statefun-sanity-itcase") + .withFileFromClasspath("Dockerfile", "Dockerfile") + .withFileFromPath(".", Paths.get(System.getProperty("user.dir") + "/target/")); + + @Rule public Network network = Network.newNetwork(); + + @Rule + public KafkaContainer kafka = + new KafkaContainer(CONFLUENT_PLATFORM_VERSION) + .withNetwork(network) + .withNetworkAliases("kafka-broker"); + + @Rule + public GenericContainer verificationAppMaster = + new GenericContainer(verificationAppImage) + .dependsOn(kafka) + .withNetwork(network) + .withNetworkAliases("master") + .withEnv("ROLE", "master") + .withEnv("MASTER_HOST", "master"); + + @Rule + public GenericContainer verificationAppWorker = + new GenericContainer(verificationAppImage) + .dependsOn(kafka, verificationAppMaster) + .withNetwork(network) + .withNetworkAliases("worker") + .withEnv("ROLE", "worker") + .withEnv("MASTER_HOST", "master"); + + @Test + public void run() throws Exception { + final String kafkaAddress = kafka.getBootstrapServers(); + final ExecutorService kafkaIoExecutor = Executors.newCachedThreadPool(); + + kafkaIoExecutor.submit(new ProduceCommands(kafkaAddress)); + Future<List<StateSnapshot>> stateSnapshotOutputs = + kafkaIoExecutor.submit(new ConsumeStateSnapshots(kafkaAddress)); + + assertThat( + stateSnapshotOutputs.get(1, TimeUnit.MINUTES), + hasItems( Review comment: Suggestion: It could be nicer if we had thecommands present at the same level that the verification is present. For example: ``` assertThat( sending( modifiyAction(address1, 100), modifiyAction(address2, 200)) , results( stateSnapshot(address1, 100) stateSnapshot(address2, 200)) ); ``` It is fine the way it is right now, I'm sure will iterate on these kind of tests many times in the future ---------------------------------------------------------------- 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