Skip to content

Commit 048eac8

Browse files
authored
test: add FileIO s3 test (#220)
* add file io s3 test * add license * fixed version & rm port scanner
1 parent 61e6444 commit 048eac8

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

crates/iceberg/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ urlencoding = { workspace = true }
6262
uuid = { workspace = true }
6363

6464
[dev-dependencies]
65+
iceberg_test_utils = { path = "../test_utils", features = ["tests"] }
6566
pretty_assertions = { workspace = true }
6667
tempfile = { workspace = true }
6768
tera = { workspace = true }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
version: '3'
19+
services:
20+
minio:
21+
image: minio/minio:RELEASE.2024-02-26T09-33-48Z
22+
ports:
23+
- 9000
24+
- 9001
25+
environment:
26+
MINIO_ROOT_USER: 'admin'
27+
MINIO_ROOT_PASSWORD: 'password'
28+
MINIO_ADDRESS: ':9000'
29+
MINIO_CONSOLE_ADDRESS: ':9001'
30+
entrypoint: sh
31+
command: -c 'mkdir -p /data/bucket1 && /usr/bin/minio server /data'
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Integration tests for FileIO S3.
19+
20+
use futures::{AsyncReadExt, AsyncWriteExt};
21+
use iceberg::io::{
22+
FileIO, FileIOBuilder, S3_ACCESS_KEY_ID, S3_ENDPOINT, S3_REGION, S3_SECRET_ACCESS_KEY,
23+
};
24+
use iceberg_test_utils::docker::DockerCompose;
25+
26+
struct MinIOFixture {
27+
_docker_compose: DockerCompose,
28+
file_io: FileIO,
29+
}
30+
impl MinIOFixture {
31+
async fn new(project_name: impl ToString) -> Self {
32+
// Start the Docker container for the test fixture
33+
let docker = DockerCompose::new(
34+
project_name.to_string(),
35+
format!("{}/testdata/file_io_s3", env!("CARGO_MANIFEST_DIR")),
36+
);
37+
docker.run();
38+
let container_ip = docker.get_container_ip("minio");
39+
let read_port = format!("{}:{}", container_ip, 9000);
40+
41+
MinIOFixture {
42+
_docker_compose: docker,
43+
file_io: FileIOBuilder::new("s3")
44+
.with_props(vec![
45+
(S3_ENDPOINT, format!("http://{}", read_port)),
46+
(S3_ACCESS_KEY_ID, "admin".to_string()),
47+
(S3_SECRET_ACCESS_KEY, "password".to_string()),
48+
(S3_REGION, "us-east-1".to_string()),
49+
])
50+
.build()
51+
.unwrap(),
52+
}
53+
}
54+
}
55+
56+
#[tokio::test]
57+
async fn test_file_io_s3_is_exist() {
58+
let fixture = MinIOFixture::new("test_file_io_s3_is_exist").await;
59+
assert!(!fixture.file_io.is_exist("s3://bucket2/any").await.unwrap());
60+
assert!(fixture.file_io.is_exist("s3://bucket1/").await.unwrap());
61+
}
62+
63+
#[tokio::test]
64+
async fn test_file_io_s3_output() {
65+
// Start the Docker container for the test fixture
66+
let fixture = MinIOFixture::new("test_file_io_s3_output").await;
67+
assert!(!fixture
68+
.file_io
69+
.is_exist("s3://bucket1/test_output")
70+
.await
71+
.unwrap());
72+
let output_file = fixture
73+
.file_io
74+
.new_output("s3://bucket1/test_output")
75+
.unwrap();
76+
{
77+
let mut writer = output_file.writer().await.unwrap();
78+
writer.write_all("123".as_bytes()).await.unwrap();
79+
writer.close().await.unwrap();
80+
}
81+
assert!(fixture
82+
.file_io
83+
.is_exist("s3://bucket1/test_output")
84+
.await
85+
.unwrap());
86+
}
87+
88+
#[tokio::test]
89+
async fn test_file_io_s3_input() {
90+
let fixture = MinIOFixture::new("test_file_io_s3_input").await;
91+
let output_file = fixture
92+
.file_io
93+
.new_output("s3://bucket1/test_input")
94+
.unwrap();
95+
{
96+
let mut writer = output_file.writer().await.unwrap();
97+
writer.write_all("test_input".as_bytes()).await.unwrap();
98+
writer.close().await.unwrap();
99+
}
100+
let input_file = fixture
101+
.file_io
102+
.new_input("s3://bucket1/test_input")
103+
.unwrap();
104+
{
105+
let mut reader = input_file.reader().await.unwrap();
106+
let mut buffer = vec![];
107+
reader.read_to_end(&mut buffer).await.unwrap();
108+
assert_eq!(buffer, "test_input".as_bytes());
109+
}
110+
}

0 commit comments

Comments
 (0)