Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-3863: [Java] Delete temporary test data after tests finish #2506

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void throttledInputStream() throws IOException {
.parse("{\"type\": \"record\", \"name\": \"TestSchema\", \"fields\": "
+ "[ {\"name\": \"id\", \"type\": [\"long\", \"null\"], \"default\": null}]}");
File f = Files.createTempFile("testThrottledInputStream", ".avro").toFile();
f.deleteOnExit();
try (DataFileWriter<?> w = new DataFileWriter<>(new GenericDatumWriter<>())) {
w.create(legacySchema, f);
w.flush();
Expand Down Expand Up @@ -150,6 +151,7 @@ void inputStreamEOF() throws IOException {
.parse("{\"type\": \"record\", \"name\": \"TestSchema\", \"fields\": "
+ "[ {\"name\": \"id\", \"type\": [\"long\", \"null\"], \"default\": null}]}");
File f = Files.createTempFile("testInputStreamEOF", ".avro").toFile();
f.deleteOnExit();
try (DataFileWriter<?> w = new DataFileWriter<>(new GenericDatumWriter<>())) {
w.create(legacySchema, f);
w.flush();
Expand Down Expand Up @@ -201,6 +203,7 @@ void ignoreSchemaValidationOnRead() throws IOException {

// Create a file with the legacy schema.
File f = Files.createTempFile("testIgnoreSchemaValidationOnRead", ".avro").toFile();
f.deleteOnExit();
try (DataFileWriter<?> w = new DataFileWriter<>(new GenericDatumWriter<>())) {
w.create(legacySchema, f);
w.flush();
Expand All @@ -215,6 +218,7 @@ void ignoreSchemaValidationOnRead() throws IOException {
@Test
void invalidMagicLength() throws IOException {
File f = Files.createTempFile("testInvalidMagicLength", ".avro").toFile();
f.deleteOnExit();
try (FileWriter w = new FileWriter(f)) {
w.write("-");
}
Expand All @@ -227,6 +231,7 @@ void invalidMagicLength() throws IOException {
@Test
void invalidMagicBytes() throws IOException {
File f = Files.createTempFile("testInvalidMagicBytes", ".avro").toFile();
f.deleteOnExit();
try (FileWriter w = new FileWriter(f)) {
w.write("invalid");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ void arrayBackedByteBuffer() throws IOException {
@Test
void mappedByteBuffer() throws IOException {
Path file = Paths.get(DIR.getPath() + "testMappedByteBuffer.avro");
file.toFile().deleteOnExit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Path file = Paths.get(DIR.getPath() + "testMappedByteBuffer.avro");
file.toFile().deleteOnExit();
Path file = DIR.toPath().resolve( "testMappedByteBuffer.avro");

For example: here we have a @TempDir already present, and cleaned up automatically in the test case -- we just accidentally forgot the path separator so the file was outside!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, O.K. I'll try it.

Files.write(file, someBytes(EXAMPLE_DATA_SIZE));
MappedByteBuffer buffer = FileChannel.open(file, StandardOpenOption.READ).map(FileChannel.MapMode.READ_ONLY, 0,
EXAMPLE_DATA_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.avro.util.RandomData;
import org.apache.trevni.TestUtil;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -66,6 +67,11 @@ public void after() throws Exception {
err.close();
}

@AfterAll
public static void afterAll() throws Exception {
OUT_FILE.delete();
}

private int run(List<String> args) throws Exception {
PrintStream output = new PrintStream(out);
PrintStream saveOut = System.out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.util.RandomData;
import org.apache.trevni.avro.AvroColumnReader;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

public class TestToTrevniTool {
Expand All @@ -41,6 +42,11 @@ public class TestToTrevniTool {
private static final File TREVNI_FILE = new File(DIR, "random.trv");
private static final File SCHEMA_FILE = new File("../../../share/test/schemas/weather.avsc");

@AfterAll
public static void afterAll() throws Exception {
AVRO_FILE.delete();
}

private String run(String... args) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream p = new PrintStream(baos);
Expand Down
Loading