This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 0778b5d Migrates camel-hbase to the new test infra (#4700) 0778b5d is described below commit 0778b5da220d1502e2e46f84e6cce0d773dc49da Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Sun Nov 29 16:46:58 2020 +0100 Migrates camel-hbase to the new test infra (#4700) --- components/camel-hbase/pom.xml | 50 +++++-------- .../component/hbase/CamelHBaseTestSupport.java | 35 ++------- .../idempotent/HBaseIdempotentRepositoryTest.java | 2 +- test-infra/camel-test-infra-hbase/pom.xml | 85 ++++++++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../test/infra/hbase/common/HBaseProperties.java | 25 +++++++ .../test/infra/hbase/services}/HBaseContainer.java | 2 +- .../hbase/services/HBaseLocalContainerService.java | 61 ++++++++++++++++ .../test/infra/hbase/services/HBaseService.java | 41 +++++++++++ .../infra/hbase/services/HBaseServiceFactory.java | 39 ++++++++++ test-infra/pom.xml | 1 + 11 files changed, 279 insertions(+), 62 deletions(-) diff --git a/components/camel-hbase/pom.xml b/components/camel-hbase/pom.xml index fe09ec3..09831f9 100644 --- a/components/camel-hbase/pom.xml +++ b/components/camel-hbase/pom.xml @@ -58,45 +58,29 @@ <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-testcontainers-junit5</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - </exclusions> </dependency> + + <!-- test infra --> <dependency> - <groupId>org.apache.hbase</groupId> - <artifactId>hbase-testing-util</artifactId> - <version>${hbase-version}</version> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <!-- has SNAPSHOT in its pom.xml that causes maven problems --> - <exclusion> - <groupId>org.glassfish</groupId> - <artifactId>javax.el</artifactId> - </exclusion> - </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-hbase</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + + <!-- logging --> <dependency> <groupId>org.apache.logging.log4j</groupId> diff --git a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java index 2154349..1dd954f 100644 --- a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java +++ b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/CamelHBaseTestSupport.java @@ -17,11 +17,11 @@ package org.apache.camel.component.hbase; import java.io.IOException; -import java.util.concurrent.TimeUnit; -import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport; +import org.apache.camel.test.infra.hbase.services.HBaseService; +import org.apache.camel.test.infra.hbase.services.HBaseServiceFactory; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.camel.util.IOHelper; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotFoundException; @@ -34,9 +34,11 @@ import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.testcontainers.containers.GenericContainer; +import org.junit.jupiter.api.extension.RegisterExtension; -public abstract class CamelHBaseTestSupport extends ContainerAwareTestSupport { +public abstract class CamelHBaseTestSupport extends CamelTestSupport { + @RegisterExtension + public static HBaseService service = HBaseServiceFactory.createService(); protected static final String PERSON_TABLE = "person"; protected static final String INFO_FAMILY = "info"; @@ -61,9 +63,6 @@ public abstract class CamelHBaseTestSupport extends ContainerAwareTestSupport { family[1].getBytes(), family[2].getBytes() }; - // init container once for a class - private GenericContainer cont; - @Override @BeforeEach public void setUp() throws Exception { @@ -86,20 +85,6 @@ public abstract class CamelHBaseTestSupport extends ContainerAwareTestSupport { super.tearDown(); } - @Override - protected GenericContainer<?> createContainer() { - if (cont == null) { - cont = new HBaseContainer(); - } - return cont; - } - - @Override - protected long containersStartupTimeout() { - // on my laptop it takes around 30-60 seconds to start the cluster. - return TimeUnit.MINUTES.toSeconds(5); - } - protected void putMultipleRows() throws IOException { Table table = connectHBase().getTable(TableName.valueOf(PERSON_TABLE.getBytes())); for (int r = 0; r < key.length; r++) { @@ -110,12 +95,8 @@ public abstract class CamelHBaseTestSupport extends ContainerAwareTestSupport { IOHelper.close(table); } - protected Configuration getHBaseConfig() { - return HBaseContainer.defaultConf(); - } - protected Connection connectHBase() throws IOException { - Connection connection = ConnectionFactory.createConnection(getHBaseConfig()); + Connection connection = ConnectionFactory.createConnection(service.getConfiguration()); return connection; } diff --git a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java index e8e3304..799091c 100644 --- a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java +++ b/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/processor/idempotent/HBaseIdempotentRepositoryTest.java @@ -38,7 +38,7 @@ public class HBaseIdempotentRepositoryTest extends CamelHBaseTestSupport { @Override @BeforeEach public void setUp() throws Exception { - this.repository = new HBaseIdempotentRepository(getHBaseConfig(), PERSON_TABLE, INFO_FAMILY, "mycolumn"); + this.repository = new HBaseIdempotentRepository(service.getConfiguration(), PERSON_TABLE, INFO_FAMILY, "mycolumn"); super.setUp(); try { createTable(PERSON_TABLE, INFO_FAMILY); diff --git a/test-infra/camel-test-infra-hbase/pom.xml b/test-infra/camel-test-infra-hbase/pom.xml new file mode 100644 index 0000000..76bbb40 --- /dev/null +++ b/test-infra/camel-test-infra-hbase/pom.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>camel-test-infra-parent</artifactId> + <groupId>org.apache.camel</groupId> + <relativePath>../camel-test-infra-parent/pom.xml</relativePath> + <version>3.7.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-test-infra-hbase</artifactId> + <name>Camel :: Test Infra :: HBase</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-testing-util</artifactId> + <version>${hbase-version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <!-- has SNAPSHOT in its pom.xml that causes maven problems --> + <exclusion> + <groupId>org.glassfish</groupId> + <artifactId>javax.el</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file diff --git a/test-infra/camel-test-infra-hbase/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-hbase/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/common/HBaseProperties.java b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/common/HBaseProperties.java new file mode 100644 index 0000000..93a0440 --- /dev/null +++ b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/common/HBaseProperties.java @@ -0,0 +1,25 @@ +/* + * 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.camel.test.infra.hbase.common; + +public final class HBaseProperties { + + private HBaseProperties() { + + } +} diff --git a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseContainer.java b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseContainer.java similarity index 97% rename from components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseContainer.java rename to test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseContainer.java index c567773..934c22f 100644 --- a/components/camel-hbase/src/test/java/org/apache/camel/component/hbase/HBaseContainer.java +++ b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseContainer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.hbase; +package org.apache.camel.test.infra.hbase.services; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; diff --git a/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseLocalContainerService.java b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseLocalContainerService.java new file mode 100644 index 0000000..42e1454 --- /dev/null +++ b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseLocalContainerService.java @@ -0,0 +1,61 @@ +/* + * 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.camel.test.infra.hbase.services; + +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.hadoop.conf.Configuration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HBaseLocalContainerService implements HBaseService, ContainerService<HBaseContainer> { + private static final Logger LOG = LoggerFactory.getLogger(HBaseLocalContainerService.class); + + private HBaseContainer container; + + public HBaseLocalContainerService() { + container = new HBaseContainer(); + } + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + LOG.info("Trying to start the HBase container"); + container.start(); + + registerProperties(); + } + + @Override + public void shutdown() { + LOG.info("Stopping the HBase container"); + container.stop(); + } + + @Override + public HBaseContainer getContainer() { + return container; + } + + @Override + public Configuration getConfiguration() { + return HBaseContainer.defaultConf(); + } +} diff --git a/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseService.java b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseService.java new file mode 100644 index 0000000..858efb1 --- /dev/null +++ b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseService.java @@ -0,0 +1,41 @@ +/* + * 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.camel.test.infra.hbase.services; + +import org.apache.camel.test.infra.common.services.TestService; +import org.apache.hadoop.conf.Configuration; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * Test infra service for HBase + */ +public interface HBaseService extends BeforeAllCallback, AfterAllCallback, TestService { + + Configuration getConfiguration(); + + @Override + default void beforeAll(ExtensionContext extensionContext) throws Exception { + initialize(); + } + + @Override + default void afterAll(ExtensionContext extensionContext) throws Exception { + shutdown(); + } +} diff --git a/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseServiceFactory.java b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseServiceFactory.java new file mode 100644 index 0000000..954140c --- /dev/null +++ b/test-infra/camel-test-infra-hbase/src/test/java/org/apache/camel/test/infra/hbase/services/HBaseServiceFactory.java @@ -0,0 +1,39 @@ +/* + * 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.camel.test.infra.hbase.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class HBaseServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(HBaseServiceFactory.class); + + private HBaseServiceFactory() { + + } + + public static HBaseService createService() { + String instanceType = System.getProperty("hbase.instance.type"); + + if (instanceType == null || instanceType.equals("local-hbase-container")) { + return new HBaseLocalContainerService(); + } + + LOG.error("HBase instance must be one of 'local-hbase-container' or 'remote"); + throw new UnsupportedOperationException("Invalid HBase instance type"); + } +} diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 919b88d..7a88e8f 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -56,5 +56,6 @@ <module>camel-test-infra-consul</module> <module>camel-test-infra-google-pubsub</module> <module>camel-test-infra-etcd</module> + <module>camel-test-infra-hbase</module> </modules> </project>