nastra commented on a change in pull request #3663:
URL: https://github.com/apache/iceberg/pull/3663#discussion_r762900329
##########
File path: core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java
##########
@@ -419,4 +422,33 @@ public void testCanReadOldCompressedManifestFiles() throws
Exception {
List<FileScanTask> tasks =
Lists.newArrayList(reloaded.newScan().planFiles());
Assert.assertEquals("Should scan 1 files", 1, tasks.size());
}
+
+ @Test
+ public void testConcurrentAppend() throws Exception {
+ assertTrue("Should create v1 metadata",
+ version(1).exists() && version(1).isFile());
+ File dir = temp.newFolder();
+ dir.delete();
+
+ Table tableWithHighRetries = TABLES.create(SCHEMA, SPEC, new
HashMap<String, String>() {
+ {
+ put(TableProperties.COMMIT_NUM_RETRIES, "1000");
+ }
+ }, dir.toURI().toString());
+ int threadsCount = 30;
+ Thread[] threads = new Thread[threadsCount];
+ for (int i = 0; i < threadsCount; i++) {
+ threads[i] = new Thread(() ->
tableWithHighRetries.newAppend().appendFile(FILE_A).commit());
+ threads[i].start();
+ }
+ Arrays.stream(threads).forEach(t -> {
+ try {
+ t.join();
Review comment:
this is unfortunately a recipe for flaky tests. It would be much nicer
if we could use https://github.com/awaitility/awaitility and have something
like `Awaitility.await().atMost(X, SECONDS).untilAsserted(() ->
assertThat(...).isEqualTo(..))`
##########
File path:
spark/v2.4/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkDataWrite.java
##########
@@ -189,6 +192,56 @@ public void testAppend() throws IOException {
Assert.assertEquals("Result rows should match", expected, actual);
}
+ @Test
+ public void testConcurrentAppend() throws IOException {
+ File parent = temp.newFolder(format.toString());
+ File location = new File(parent, "test");
+
+ HadoopTables tables = new HadoopTables(CONF);
+ Map<String, String> properties = new HashMap<>();
+ properties.put(TableProperties.COMMIT_NUM_RETRIES, "1000");
+ Table table = tables.create(SCHEMA, null, properties, location.toString());
+
+ List<SimpleRecord> records = Lists.newArrayList(
+ new SimpleRecord(1, "a"),
+ new SimpleRecord(2, "b"),
+ new SimpleRecord(3, "c")
+ );
+
+ Dataset<Row> df = spark.createDataFrame(records, SimpleRecord.class);
+ int threadsCount = 10;
+ Thread[] threads = new Thread[threadsCount];
+ for (int i = 0; i < threadsCount; i++) {
+ threads[i] = new Thread(() -> {
+ try {
+ df.select("id", "data").write()
+ .format("iceberg")
+ .option(SparkWriteOptions.WRITE_FORMAT, format.toString())
+ .mode(SaveMode.Append)
+ .save(location.toString());
+ } catch (Exception e) {
+ // intentionally swallow to check result later
+ }
+ });
+ threads[i].start();
+ }
+ Arrays.stream(threads).forEach(t -> {
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ // intentionally swallow to check result later
+ }
+ });
+ table.refresh();
+ Assert.assertEquals(threadsCount,
Lists.newArrayList(table.snapshots()).size());
+ Dataset<Row> result = spark.read()
+ .format("iceberg")
+ .load(location.toString());
+
+ List<SimpleRecord> actual =
result.orderBy("id").as(Encoders.bean(SimpleRecord.class)).collectAsList();
+ Assert.assertEquals("Number of rows should match", 3 * threadsCount,
actual.size());
Review comment:
same comment here about using Awaitility to assert async code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]