Skip to content

Commit

Permalink
Flink 1.17: Create JUnit5 version of TestFlinkScan (apache#9185)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgpoh authored Jan 5, 2024
1 parent 12b3ccd commit 0bf2602
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package org.apache.iceberg.data;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.AppendFiles;
Expand All @@ -32,7 +35,6 @@
import org.apache.iceberg.Table;
import org.apache.iceberg.io.FileAppender;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.junit.Assert;
import org.junit.rules.TemporaryFolder;

/** Helper for appending {@link DataFile} to a table or appending {@link Record}s to a table. */
Expand All @@ -44,20 +46,35 @@ public class GenericAppenderHelper {
private final Table table;
private final FileFormat fileFormat;
private final TemporaryFolder tmp;
private final Path temp;
private final Configuration conf;

@Deprecated
public GenericAppenderHelper(
Table table, FileFormat fileFormat, TemporaryFolder tmp, Configuration conf) {
this.table = table;
this.fileFormat = fileFormat;
this.tmp = tmp;
this.temp = null;
this.conf = conf;
}

public GenericAppenderHelper(Table table, FileFormat fileFormat, Path temp, Configuration conf) {
this.table = table;
this.fileFormat = fileFormat;
this.tmp = null;
this.temp = temp;
this.conf = conf;
}

public GenericAppenderHelper(Table table, FileFormat fileFormat, TemporaryFolder tmp) {
this(table, fileFormat, tmp, null);
}

public GenericAppenderHelper(Table table, FileFormat fileFormat, Path temp) {
this(table, fileFormat, temp, null);
}

public void appendToTable(String branch, DataFile... dataFiles) {
Preconditions.checkNotNull(table, "table not set");

Expand Down Expand Up @@ -94,15 +111,15 @@ public void appendToTable(StructLike partition, List<Record> records) throws IOE

public DataFile writeFile(List<Record> records) throws IOException {
Preconditions.checkNotNull(table, "table not set");
File file = tmp.newFile();
Assert.assertTrue(file.delete());
File file = null != tmp ? tmp.newFile() : File.createTempFile("junit", null, temp.toFile());
assertThat(file.delete()).isTrue();
return appendToLocalFile(table, file, fileFormat, null, records, conf);
}

public DataFile writeFile(StructLike partition, List<Record> records) throws IOException {
Preconditions.checkNotNull(table, "table not set");
File file = tmp.newFile();
Assert.assertTrue(file.delete());
File file = null != tmp ? tmp.newFile() : File.createTempFile("junit", null, temp.toFile());
assertThat(file.delete()).isTrue();
return appendToLocalFile(table, file, fileFormat, partition, records, conf);
}

Expand Down
Loading

0 comments on commit 0bf2602

Please sign in to comment.