Skip to content

Commit

Permalink
[Improve][e2e] support @DisabledOnContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
ashulin committed Sep 28, 2022
1 parent c5251de commit 3f614bf
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.seatunnel.e2e.common.TestResource;
import org.apache.seatunnel.e2e.common.TestSuiteBase;
import org.apache.seatunnel.e2e.common.container.TestContainer;
import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer;
import org.apache.seatunnel.format.json.JsonSerializationSchema;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -56,6 +57,7 @@

import scala.Tuple2;

@DisabledOnContainer(value = "spark:2.4.3", disabledReason = "json-format conflicts with the Jackson version of Spark-2.4.3, see:https://github.com/apache/incubator-seatunnel/issues/2929")
@Slf4j
public class RedisIT extends TestSuiteBase implements TestResource {
private static final String IMAGE = "redis:latest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.support.AnnotationSupport;
import org.junit.platform.commons.util.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class ContainerTestingExtension implements BeforeAllCallback, AfterAllCallback {
public static final ExtensionContext.Namespace TEST_RESOURCE_NAMESPACE =
Expand Down Expand Up @@ -57,7 +61,15 @@ public void beforeAll(ExtensionContext context) throws Exception {
TestContainersFactory.class);

checkExactlyOneAnnotatedField(containersFactories, TestContainers.class);
List<TestContainer> testContainers = containersFactories.get(0).create();

// Filters disabled containers
final List<String> disabledContainers = new ArrayList<>();
AnnotationUtils.findAnnotation(context.getRequiredTestInstance().getClass(), DisabledOnContainer.class)
.ifPresent(annotation -> Collections.addAll(disabledContainers, annotation.value()));
List<TestContainer> testContainers = containersFactories.get(0).create()
.stream()
.filter(container -> !disabledContainers.contains(container.identifier()))
.collect(Collectors.toList());
context.getStore(TEST_RESOURCE_NAMESPACE)
.put(TEST_CONTAINERS_STORE_KEY, testContainers);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.seatunnel.e2e.common.junit;

import org.apache.seatunnel.e2e.common.container.TestContainer;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface DisabledOnContainer {

/**
* {@link TestContainer#identifier()}
*/
String[] value();

/**
* Custom reason to provide if the test container is disabled.
*
* <p>If a custom reason is supplied, it will be combined with the default
* reason for this annotation. If a custom reason is not supplied, the default
* reason will be used.
*/
String disabledReason() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
import org.junit.platform.commons.util.AnnotationUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
Expand All @@ -53,8 +57,16 @@ public boolean supportsTestTemplate(ExtensionContext context) {
@SuppressWarnings("unchecked")
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
List<TestContainer> testContainers = (List<TestContainer>) context.getStore(TEST_RESOURCE_NAMESPACE)
.get(TEST_CONTAINERS_STORE_KEY);
final List<String> disabledContainers = new ArrayList<>();
AnnotationUtils.findAnnotation(context.getRequiredTestMethod(), DisabledOnContainer.class)
.ifPresent(annotation -> Collections.addAll(disabledContainers, annotation.value()));

// Filters disabled containers
List<TestContainer> testContainers = ((List<TestContainer>) context.getStore(TEST_RESOURCE_NAMESPACE)
.get(TEST_CONTAINERS_STORE_KEY))
.stream()
.filter(container -> !disabledContainers.contains(container.identifier()))
.collect(Collectors.toList());

ContainerExtendedFactory containerExtendedFactory = (ContainerExtendedFactory) context.getStore(TEST_RESOURCE_NAMESPACE)
.get(TEST_EXTENDED_FACTORY_STORE_KEY);
Expand Down

0 comments on commit 3f614bf

Please sign in to comment.