-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test consumer without event flattening, Add flag to control identifie…
…r-field creation (#356)
- Loading branch information
1 parent
219d0c1
commit a50e07e
Showing
13 changed files
with
567 additions
and
21 deletions.
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
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
132 changes: 132 additions & 0 deletions
132
...ink/src/test/java/io/debezium/server/iceberg/IcebergChangeConsumerMysqlTestUnwrapped.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,132 @@ | ||
/* | ||
* | ||
* * Copyright memiiso Authors. | ||
* * | ||
* * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
package io.debezium.server.iceberg; | ||
|
||
import com.google.common.collect.Lists; | ||
import io.debezium.server.iceberg.testresources.BaseTest; | ||
import io.debezium.server.iceberg.testresources.S3Minio; | ||
import io.debezium.server.iceberg.testresources.SourceMysqlDB; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import org.apache.iceberg.catalog.TableIdentifier; | ||
import org.apache.iceberg.data.Record; | ||
import org.apache.iceberg.io.CloseableIterable; | ||
import org.apache.spark.sql.Dataset; | ||
import org.apache.spark.sql.Row; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Ismail Simsek | ||
*/ | ||
@QuarkusTest | ||
@QuarkusTestResource(value = S3Minio.class, restrictToAnnotatedClass = true) | ||
@QuarkusTestResource(value = SourceMysqlDB.class, restrictToAnnotatedClass = true) | ||
@TestProfile(IcebergChangeConsumerMysqlTestUnwrapped.TestProfile.class) | ||
public class IcebergChangeConsumerMysqlTestUnwrapped extends BaseTest { | ||
|
||
@Test | ||
public void testSimpleUpload() throws Exception { | ||
|
||
// make sure its not unwrapped | ||
assertEquals(IcebergUtil.configIncludesUnwrapSmt(), false); | ||
assertEquals(IcebergChangeEvent.eventsAreUnwrapped, false); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> result = getTableDataV2("testc.inventory.customers"); | ||
printTableData(result); | ||
return Lists.newArrayList(result).size() >= 3; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
// test nested data(struct) consumed | ||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> result = getTableDataV2("testc.inventory.geom"); | ||
return Lists.newArrayList(result).size() >= 3; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> d = getTableDataV2(TableIdentifier.of("debeziumevents", "debezium_offset_storage_table")); | ||
System.out.println(Lists.newArrayList(d)); | ||
return Lists.newArrayList(d).size() == 1; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
} | ||
|
||
@Test | ||
public void testDeleteEvents() throws Exception { | ||
|
||
// make sure its not unwrapped | ||
assertEquals(IcebergUtil.configIncludesUnwrapSmt(), false); | ||
assertEquals(IcebergChangeEvent.eventsAreUnwrapped, false); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> result = getTableDataV2("testc.inventory.customers"); | ||
printTableData(result); | ||
return Lists.newArrayList(result).size() >= 4; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
SourceMysqlDB.runSQL("ALTER TABLE inventory.addresses DROP FOREIGN KEY addresses_ibfk_1;"); | ||
SourceMysqlDB.runSQL("DELETE FROM inventory.customers where id = 1004 ;"); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> result = getTableDataV2("testc.inventory.customers"); | ||
printTableData(result); | ||
return Lists.newArrayList(result).size() >= 5; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
|
||
public static class TestProfile implements QuarkusTestProfile { | ||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> config = new HashMap<>(); | ||
config.put("quarkus.profile", "mysql"); | ||
config.put("%mysql.debezium.source.connector.class", "io.debezium.connector.mysql.MySqlConnector"); | ||
config.put("%mysql.debezium.source.table.whitelist", "inventory.customers,inventory.test_delete_table"); | ||
config.put("debezium.transforms", ","); | ||
config.put("debezium.sink.iceberg.upsert", "false"); | ||
config.put("debezium.sink.iceberg.create-identifier-fields", "false"); | ||
return config; | ||
} | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "mysql"; | ||
} | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...rg-sink/src/test/java/io/debezium/server/iceberg/IcebergChangeConsumerTestUnwraapped.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,102 @@ | ||
/* | ||
* | ||
* * Copyright memiiso Authors. | ||
* * | ||
* * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
package io.debezium.server.iceberg; | ||
|
||
import com.google.common.collect.Lists; | ||
import io.debezium.server.iceberg.testresources.BaseSparkTest; | ||
import io.debezium.server.iceberg.testresources.S3Minio; | ||
import io.debezium.server.iceberg.testresources.SourcePostgresqlDB; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import jakarta.inject.Inject; | ||
import org.apache.iceberg.catalog.Namespace; | ||
import org.apache.iceberg.catalog.TableIdentifier; | ||
import org.apache.iceberg.data.Record; | ||
import org.apache.iceberg.io.CloseableIterable; | ||
import org.apache.spark.sql.Dataset; | ||
import org.apache.spark.sql.Row; | ||
import org.awaitility.Awaitility; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Integration test that verifies basic reading from PostgreSQL database and writing to iceberg destination. | ||
* | ||
* @author Ismail Simsek | ||
*/ | ||
@QuarkusTest | ||
@QuarkusTestResource(value = S3Minio.class, restrictToAnnotatedClass = true) | ||
@QuarkusTestResource(value = SourcePostgresqlDB.class, restrictToAnnotatedClass = true) | ||
@TestProfile(IcebergChangeConsumerTestUnwraapped.TestProfile.class) | ||
public class IcebergChangeConsumerTestUnwraapped extends BaseSparkTest { | ||
|
||
@Test | ||
public void testSimpleUpload() { | ||
|
||
// make sure its not unwrapped | ||
assertEquals(IcebergUtil.configIncludesUnwrapSmt(), false); | ||
assertEquals(IcebergChangeEvent.eventsAreUnwrapped, false); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
Dataset<Row> ds = getTableData("testc.inventory.customers"); | ||
ds.show(false); | ||
return ds.count() >= 3; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
// test nested data(struct) consumed | ||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
Dataset<Row> ds = getTableData("testc.inventory.geom"); | ||
ds.show(false); | ||
return ds.count() >= 3; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
|
||
Awaitility.await().atMost(Duration.ofSeconds(120)).until(() -> { | ||
try { | ||
CloseableIterable<Record> d = getTableDataV2(TableIdentifier.of("debeziumevents", "debezium_offset_storage_table")); | ||
System.out.println(Lists.newArrayList(d)); | ||
return Lists.newArrayList(d).size() == 1; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
public static class TestProfile implements QuarkusTestProfile { | ||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> config = new HashMap<>(); | ||
config.put("debezium.sink.iceberg.write.format.default", "orc"); | ||
config.put("debezium.sink.iceberg.destination-regexp", "\\d"); | ||
config.put("debezium.source.hstore.handling.mode", "map"); | ||
config.put("debezium.transforms", ","); | ||
config.put("debezium.sink.iceberg.create-identifier-fields", "false"); | ||
return config; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.