Skip to content

Commit

Permalink
[Feature][Connector-V2-e2e][LocalFile] Optimize test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TyrantLucifer committed Oct 29, 2022
1 parent 253e7d9 commit 409fdf7
Show file tree
Hide file tree
Showing 14 changed files with 651 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,61 @@
package org.apache.seatunnel.e2e.connector.file.local;

import org.apache.seatunnel.e2e.common.TestSuiteBase;
import org.apache.seatunnel.e2e.common.container.ContainerExtendedFactory;
import org.apache.seatunnel.e2e.common.container.TestContainer;
import org.apache.seatunnel.e2e.common.junit.TestContainerExtension;
import org.apache.seatunnel.e2e.common.util.ContainerUtil;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestTemplate;
import org.testcontainers.containers.Container;
import org.testcontainers.utility.MountableFile;

import java.io.IOException;
import java.nio.file.Path;

public class LocalFileIT extends TestSuiteBase {

/**
* Copy data files to container
*/
@TestContainerExtension
private final ContainerExtendedFactory extendedFactory = container -> {
Path jsonPath = ContainerUtil.getResourcesFile("/json/e2e.json").toPath();
Path orcPath = ContainerUtil.getResourcesFile("/orc/e2e.orc").toPath();
Path parquetPath = ContainerUtil.getResourcesFile("/parquet/e2e.parquet").toPath();
Path textPath = ContainerUtil.getResourcesFile("/text/e2e.txt").toPath();
container.copyFileToContainer(MountableFile.forHostPath(jsonPath), "/seatunnel/read/json/name=tyrantlucifer/hobby=coding/e2e.json");
container.copyFileToContainer(MountableFile.forHostPath(orcPath), "/seatunnel/read/orc/name=tyrantlucifer/hobby=coding/e2e.orc");
container.copyFileToContainer(MountableFile.forHostPath(parquetPath), "/seatunnel/read/parquet/name=tyrantlucifer/hobby=coding/e2e.parquet");
container.copyFileToContainer(MountableFile.forHostPath(textPath), "/seatunnel/read/text/name=tyrantlucifer/hobby=coding/e2e.txt");
};

@TestTemplate
public void testLocalFileWrite(TestContainer container) throws IOException, InterruptedException {
Container.ExecResult textResult = container.executeJob("/text/fake_to_local_file_text.conf");
Assertions.assertEquals(0, textResult.getExitCode());
Container.ExecResult jsonResult = container.executeJob("/json/fake_to_local_file_json.conf");
Assertions.assertEquals(0, jsonResult.getExitCode());
Container.ExecResult orcResult = container.executeJob("/orc/fake_to_local_file_orc.conf");
Assertions.assertEquals(0, orcResult.getExitCode());
Container.ExecResult parquetResult = container.executeJob("/parquet/fake_to_local_file_parquet.conf");
Assertions.assertEquals(0, parquetResult.getExitCode());
public void testLocalFileReadAndWrite(TestContainer container) throws IOException, InterruptedException {
// test write local text file
Container.ExecResult textWriteResult = container.executeJob("/text/fake_to_local_file_text.conf");
Assertions.assertEquals(0, textWriteResult.getExitCode());
// test read local text file
Container.ExecResult textReadResult = container.executeJob("/text/local_file_text_to_assert.conf");
Assertions.assertEquals(0, textReadResult.getExitCode());
// test write local json file
Container.ExecResult jsonWriteResult = container.executeJob("/json/fake_to_local_file_json.conf");
Assertions.assertEquals(0, jsonWriteResult.getExitCode());
// test read local json file
Container.ExecResult jsonReadResult = container.executeJob("/json/local_file_json_to_assert.conf");
Assertions.assertEquals(0, jsonReadResult.getExitCode());
// test write local orc file
Container.ExecResult orcWriteResult = container.executeJob("/orc/fake_to_local_file_orc.conf");
Assertions.assertEquals(0, orcWriteResult.getExitCode());
// test read local orc file
Container.ExecResult orcReadResult = container.executeJob("/orc/local_file_orc_to_assert.conf");
Assertions.assertEquals(0, orcReadResult.getExitCode());
// test write local parquet file
Container.ExecResult parquetWriteResult = container.executeJob("/parquet/fake_to_local_file_parquet.conf");
Assertions.assertEquals(0, parquetWriteResult.getExitCode());
// test read local parquet file
Container.ExecResult parquetReadResult = container.executeJob("/parquet/local_file_parquet_to_assert.conf");
Assertions.assertEquals(0, parquetReadResult.getExitCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"c_map":{"ccQcS":"PrhhP","ypJZu":"MsOdX","YFBJW":"iPXGR","ipjwT":"kcgPQ","EpKKR":"jgRfX"},"c_array":[887776100,1633238485,1009033208,600614572,1487972145],"c_string":"WArEB","c_boolean":false,"c_tinyint":-90,"c_smallint":15920,"c_int":1127427935,"c_bigint":4712806879122100224,"c_float":1.620476E38,"c_double":2.750908810407852E307,"c_bytes":"Q3NrVnQ=","c_date":"2022-04-27","c_decimal":88574263949141714798.835853182708550244,"c_timestamp":"2022-01-26T17:39:00","c_row":{"C_MAP":{"IVaKD":"bydeV","CnKBd":"kcZdt","RGlmG":"XuMyE","krSIr":"FPeal","IfhvE":"ReKxo"},"C_ARRAY":[86555282,967939739,1162972923,1662468723,546056811],"C_STRING":"bYjyZ","C_BOOLEAN":false,"C_TINYINT":-121,"C_SMALLINT":29252,"C_INT":977226449,"C_BIGINT":5047232039582494720,"C_FLOAT":2.5345643E38,"C_DOUBLE":1.5883424829997996E308,"C_BYTES":"TEVLTHU=","C_DATE":"2022-04-25","C_DECIMAL":55295207715324162970.316560703127334413,"C_TIMESTAMP":"2022-06-14T23:03:00"}}
{"c_map":{"AKiQx":"wIIdk","zgunZ":"qvHRy","ohVQL":"WfBPo","EzUcN":"yPhVF","qusBc":"FWbcI"},"c_array":[1837821269,980724530,2085935679,386596035,1433416218],"c_string":"LGMAw","c_boolean":false,"c_tinyint":-65,"c_smallint":25802,"c_int":1312064317,"c_bigint":4434124023629949952,"c_float":1.0186125E38,"c_double":3.0746920457833206E307,"c_bytes":"V2pjem4=","c_date":"2022-04-21","c_decimal":1943815605574160687.499688237951975681,"c_timestamp":"2022-08-09T09:32:00","c_row":{"C_MAP":{"qMdUz":"ylcLM","bcwFI":"qgkJT","lrPiD":"JRdjf","zmRix":"uqOKy","NEHDJ":"tzJbU"},"C_ARRAY":[951883741,2012849301,1709478035,1095210330,94263648],"C_STRING":"VAdKg","C_BOOLEAN":true,"C_TINYINT":-121,"C_SMALLINT":24543,"C_INT":1853224936,"C_BIGINT":6511613165105889280,"C_FLOAT":2.4886748E38,"C_DOUBLE":1.675530128024138E308,"C_BYTES":"UnNlRXo=","C_DATE":"2022-01-26","C_DECIMAL":50854841532374241314.109746688054104586,"C_TIMESTAMP":"2022-02-18T22:33:00"}}
{"c_map":{"VLlqs":"OwUpp","MWXek":"KDEYD","RAZII":"zGJSJ","wjBNl":"IPTvu","YkGPS":"ORquf"},"c_array":[1530393427,2055877022,1389865473,926021483,402841214],"c_string":"TNcNF","c_boolean":false,"c_tinyint":-93,"c_smallint":26429,"c_int":1890712921,"c_bigint":78884499049828080,"c_float":7.816842E37,"c_double":7.852574522011583E307,"c_bytes":"cHhzZVA=","c_date":"2022-06-05","c_decimal":32486229951636021942.906126821535443395,"c_timestamp":"2022-04-09T16:03:00","c_row":{"C_MAP":{"yIfRN":"gTBEL","oUnIJ":"GtmSz","IGuwP":"TyCOu","BwTUT":"HgnUn","MFrOg":"csTeq"},"C_ARRAY":[306983370,1604264996,2038631670,265692923,717846839],"C_STRING":"wavDf","C_BOOLEAN":true,"C_TINYINT":-48,"C_SMALLINT":29740,"C_INT":1691565731,"C_BIGINT":6162480816264462336,"C_FLOAT":3.3218342E38,"C_DOUBLE":9.993666902591773E307,"C_BYTES":"RnVoR0Q=","C_DATE":"2022-04-09","C_DECIMAL":81349181592680914623.14214231545254843,"C_TIMESTAMP":"2022-11-06T02:58:00"}}
{"c_map":{"OSHIu":"FlSum","MaSwp":"KYQkK","iXmjf":"zlkgq","jOBeN":"RDfwI","mNmag":"QyxeW"},"c_array":[1632475346,1988402914,1222138765,1952120146,1223582179],"c_string":"fUmcz","c_boolean":false,"c_tinyint":86,"c_smallint":2122,"c_int":798530029,"c_bigint":4622710207120546816,"c_float":2.7438526E38,"c_double":3.710018378162975E306,"c_bytes":"WWlCdWk=","c_date":"2022-10-08","c_decimal":21195432655142738238.345609599825344131,"c_timestamp":"2022-01-12T10:58:00","c_row":{"C_MAP":{"HdaHZ":"KMWIb","ETTGr":"zDkTq","kdTfa":"AyDqd","beLSj":"gCVdP","RDgtj":"YhJcx"},"C_ARRAY":[1665702810,2138839494,2129312562,1248002085,1536850903],"C_STRING":"jJotn","C_BOOLEAN":false,"C_TINYINT":90,"C_SMALLINT":5092,"C_INT":543799429,"C_BIGINT":3526775209703891968,"C_FLOAT":1.9285203E37,"C_DOUBLE":1.1956984788876983E308,"C_BYTES":"RVd4a1g=","C_DATE":"2022-09-19","C_DECIMAL":86909407361565847023.835229924753629936,"C_TIMESTAMP":"2022-09-15T18:06:00"}}
{"c_map":{"aDAzK":"sMIOi","NSyDX":"TKSoT","JLxhC":"NpeWZ","LAjup":"KmHDA","HUIPE":"yAOKq"},"c_array":[1046349188,1243865078,849372657,522012053,644827083],"c_string":"pwRSn","c_boolean":true,"c_tinyint":55,"c_smallint":14285,"c_int":290002708,"c_bigint":4717741595193431040,"c_float":3.0965473E38,"c_double":1.2984472295257766E308,"c_bytes":"TE1oUWg=","c_date":"2022-05-05","c_decimal":75406296065465000885.249652183329686608,"c_timestamp":"2022-07-05T14:40:00","c_row":{"C_MAP":{"WTqxL":"RuJsv","UXnhR":"HOjTp","EeFOQ":"PSpGy","YtxFI":"ACjTB","YAlWV":"NlOjQ"},"C_ARRAY":[1610325348,1432388472,557306114,590115029,1704913966],"C_STRING":"Pnkxe","C_BOOLEAN":false,"C_TINYINT":-15,"C_SMALLINT":8909,"C_INT":2084130154,"C_BIGINT":3344333580258222592,"C_FLOAT":3.3306473E38,"C_DOUBLE":9.233143817392184E307,"C_BYTES":"enpuUXk=","C_DATE":"2022-07-01","C_DECIMAL":87998983887293909887.925694693860636437,"C_TIMESTAMP":"2022-02-12T07:45:00"}}
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,41 @@ env {

source {
FakeSource {
schema {
fields {
c_map = "map<string, string>"
c_array = "array<boolean>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_decimal = "decimal(30, 8)"
c_bytes = bytes
c_date = date
c_timestamp = timestamp
}
}
result_table_name = "fake"
schema = {
fields {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
c_row = {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
}
}
}
result_table_name = "fake"
}
}

Expand All @@ -62,6 +78,5 @@ sink {
file_format = "json"
filename_time_format = "yyyy.MM.dd"
is_enable_transaction = true
save_mode = "error"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#
# 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.
#

env {
execution.parallelism = 1
spark.app.name = "SeaTunnel"
spark.executor.instances = 2
spark.executor.cores = 1
spark.executor.memory = "1g"
spark.master = local
job.mode = "BATCH"
}

source {
LocalFile {
path = "/seatunnel/read/json"
type = "json"
schema = {
fields {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
c_row = {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
}
}
}
result_table_name = "fake"
}
}

transform {
}

sink {
Assert {
rules {
row_rules = [
{
rule_type = MAX_ROW
rule_value = 5
}
],
field_rules = [
{
field_name = c_string
field_type = string
field_value = [
{
rule_type = NOT_NULL
}
]
},
{
field_name = c_boolean
field_type = boolean
field_value = [
{
rule_type = NOT_NULL
}
]
},
{
field_name = c_double
field_type = double
field_value = [
{
rule_type = NOT_NULL
}
]
},
{
field_name = name
field_type = string
field_value = [
{
rule_type = NOT_NULL
}
]
},
{
field_name = hobby
field_type = string
field_value = [
{
rule_type = NOT_NULL
}
]
}
]
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,41 @@ env {

source {
FakeSource {
schema {
fields {
c_map = "map<string, string>"
c_array = "array<boolean>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_decimal = "decimal(30, 8)"
c_bytes = bytes
c_date = date
c_timestamp = timestamp
}
}
result_table_name = "fake"
schema = {
fields {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
c_row = {
c_map = "map<string, string>"
c_array = "array<int>"
c_string = string
c_boolean = boolean
c_tinyint = tinyint
c_smallint = smallint
c_int = int
c_bigint = bigint
c_float = float
c_double = double
c_bytes = bytes
c_date = date
c_decimal = "decimal(38, 18)"
c_timestamp = timestamp
}
}
}
result_table_name = "fake"
}
}

Expand All @@ -62,6 +78,5 @@ sink {
file_format = "orc"
filename_time_format = "yyyy.MM.dd"
is_enable_transaction = true
save_mode = "error"
}
}
Loading

0 comments on commit 409fdf7

Please sign in to comment.