-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#4981] Improvement(test): Add integration tests for Hive catalog with S3 location. #4982
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7f571c
Add S3 related configuration to support Hive S3 schema/table.
yuqi1129 78ec1b7
Add Hive catalog with S3 location integration tests.
yuqi1129 01ac774
Fix test error.
yuqi1129 dec7e08
Merge branch 'main' into issue_4981
yuqi1129 771d6a3
Remove some unused code.
yuqi1129 e9aca8a
Merge remote-tracking branch 'me/issue_4981' into issue_4981
yuqi1129 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 115 additions & 91 deletions
206
...-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
171 changes: 171 additions & 0 deletions
171
...ive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHiveS3IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* 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.gravitino.catalog.hive.integration.test; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.gravitino.integration.test.container.GravitinoLocalStackContainer; | ||
import org.apache.gravitino.integration.test.container.HiveContainer; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.Container; | ||
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; | ||
import org.testcontainers.shaded.org.awaitility.Awaitility; | ||
|
||
public class CatalogHiveS3IT extends CatalogHiveIT { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogHiveS3IT.class); | ||
|
||
private static final String S3_BUCKET_NAME = "my-test-bucket"; | ||
private GravitinoLocalStackContainer gravitinoLocalStackContainer; | ||
|
||
private static final String S3_ACCESS_KEY = "S3_ACCESS_KEY"; | ||
private static final String S3_SECRET_KEY = "S3_SECRET_KEY"; | ||
private static final String S3_ENDPOINT = "S3_ENDPOINT"; | ||
|
||
private String getS3Endpoint; | ||
private String accessKey; | ||
private String secretKey; | ||
|
||
@Override | ||
protected void startNecessaryContainer() { | ||
containerSuite.startLocalStackContainer(); | ||
gravitinoLocalStackContainer = containerSuite.getLocalStackContainer(); | ||
|
||
Awaitility.await() | ||
.atMost(60, TimeUnit.SECONDS) | ||
.pollInterval(1, TimeUnit.SECONDS) | ||
.until( | ||
() -> { | ||
try { | ||
Container.ExecResult result = | ||
gravitinoLocalStackContainer.executeInContainer( | ||
"awslocal", "iam", "create-user", "--user-name", "anonymous"); | ||
return result.getExitCode() == 0; | ||
} catch (Exception e) { | ||
LOGGER.info("LocalStack is not ready yet for: ", e); | ||
return false; | ||
} | ||
}); | ||
|
||
gravitinoLocalStackContainer.executeInContainer( | ||
"awslocal", "s3", "mb", "s3://" + S3_BUCKET_NAME); | ||
|
||
Container.ExecResult result = | ||
gravitinoLocalStackContainer.executeInContainer( | ||
"awslocal", "iam", "create-access-key", "--user-name", "anonymous"); | ||
|
||
// Get access key and secret key from result | ||
String[] lines = result.getStdout().split("\n"); | ||
accessKey = lines[3].split(":")[1].trim().substring(1, 21); | ||
secretKey = lines[5].split(":")[1].trim().substring(1, 41); | ||
|
||
LOGGER.info("Access key: " + accessKey); | ||
LOGGER.info("Secret key: " + secretKey); | ||
|
||
getS3Endpoint = | ||
String.format("http://%s:%d", gravitinoLocalStackContainer.getContainerIpAddress(), 4566); | ||
|
||
gravitinoLocalStackContainer.executeInContainer( | ||
"awslocal", | ||
"s3api", | ||
"put-bucket-acl", | ||
"--bucket", | ||
"my-test-bucket", | ||
"--acl", | ||
"public-read-write"); | ||
|
||
Map<String, String> hiveContainerEnv = | ||
ImmutableMap.of( | ||
S3_ACCESS_KEY, | ||
accessKey, | ||
S3_SECRET_KEY, | ||
secretKey, | ||
S3_ENDPOINT, | ||
getS3Endpoint, | ||
HiveContainer.HIVE_RUNTIME_VERSION, | ||
HiveContainer.HIVE3); | ||
|
||
containerSuite.startHiveContainerWithS3(hiveContainerEnv); | ||
|
||
HIVE_METASTORE_URIS = | ||
String.format( | ||
"thrift://%s:%d", | ||
containerSuite.getHiveContainerWithS3().getContainerIpAddress(), | ||
HiveContainer.HIVE_METASTORE_PORT); | ||
} | ||
|
||
@Override | ||
protected void initFileSystem() throws IOException { | ||
// Use S3a file system | ||
Configuration conf = new Configuration(); | ||
conf.set("fs.s3a.access.key", accessKey); | ||
conf.set("fs.s3a.secret.key", secretKey); | ||
conf.set("fs.s3a.endpoint", getS3Endpoint); | ||
conf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"); | ||
conf.set( | ||
"fs.s3a.aws.credentials.provider", "org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"); | ||
conf.set("fs.s3a.path.style.access", "true"); | ||
conf.set("fs.s3a.connection.ssl.enabled", "false"); | ||
fileSystem = FileSystem.get(URI.create("s3a://" + S3_BUCKET_NAME), conf); | ||
} | ||
|
||
@Override | ||
protected void initSparkSession() { | ||
sparkSession = | ||
SparkSession.builder() | ||
.master("local[1]") | ||
.appName("Hive Catalog integration test") | ||
.config("hive.metastore.uris", HIVE_METASTORE_URIS) | ||
.config( | ||
"spark.sql.warehouse.dir", | ||
String.format( | ||
"hdfs://%s:%d/user/hive/warehouse", | ||
containerSuite.getHiveContainerWithS3().getContainerIpAddress(), | ||
HiveContainer.HDFS_DEFAULTFS_PORT)) | ||
.config("spark.hadoop.fs.s3a.access.key", accessKey) | ||
.config("spark.hadoop.fs.s3a.secret.key", secretKey) | ||
.config("spark.hadoop.fs.s3a.endpoint", getS3Endpoint) | ||
.config("spark.hadoop.fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem") | ||
.config("spark.hadoop.fs.s3a.path.style.access", "true") | ||
.config("spark.hadoop.fs.s3a.connection.ssl.enabled", "false") | ||
.config( | ||
"spark.hadoop.fs.s3a.aws.credentials.provider", | ||
"org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider") | ||
.config("spark.sql.storeAssignmentPolicy", "LEGACY") | ||
.config("mapreduce.input.fileinputformat.input.dir.recursive", "true") | ||
.enableHiveSupport() | ||
.getOrCreate(); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> createSchemaProperties() { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("key1", "val1"); | ||
properties.put("key2", "val2"); | ||
properties.put("location", "s3a://" + S3_BUCKET_NAME + "/test-" + System.currentTimeMillis()); | ||
return properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...st/java/org/apache/gravitino/integration/test/container/GravitinoLocalStackContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.gravitino.integration.test.container; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.testcontainers.containers.Network; | ||
|
||
public class GravitinoLocalStackContainer extends BaseContainer { | ||
|
||
public static final String DEFAULT_IMAGE = System.getenv("GRAVITINO_CI_LOCALSTACK_DOCKER_IMAGE"); | ||
public static final String HOST_NAME = "gravitino-ci-localstack"; | ||
public static final int PORT = 4566; | ||
|
||
public GravitinoLocalStackContainer( | ||
String image, | ||
String hostName, | ||
Set<Integer> ports, | ||
Map<String, String> extraHosts, | ||
Map<String, String> filesToMount, | ||
Map<String, String> envVars, | ||
Optional<Network> network) { | ||
super(image, hostName, ports, extraHosts, filesToMount, envVars, network); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Override | ||
protected boolean checkContainerStatus(int retryLimit) { | ||
return true; | ||
} | ||
|
||
public static class Builder | ||
extends BaseContainer.Builder< | ||
GravitinoLocalStackContainer.Builder, GravitinoLocalStackContainer> { | ||
public Builder() { | ||
super(); | ||
this.image = DEFAULT_IMAGE; | ||
this.hostName = HOST_NAME; | ||
this.exposePorts = ImmutableSet.of(PORT); | ||
} | ||
|
||
@Override | ||
public GravitinoLocalStackContainer build() { | ||
return new GravitinoLocalStackContainer( | ||
image, hostName, exposePorts, extraHosts, filesToMount, envVars, network); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot share the container even if we uniform the hive version to hive3 for the following reasons.
CatalogHiveS3IT
was the first one to execute.