Skip to content
Merged
Changes from all commits
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
21 changes: 14 additions & 7 deletions src/test/java/oracle/r2dbc/DatabaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
import org.reactivestreams.Publisher;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.fail;

/**
* Stores configuration used by integration tests that connect to a database.
* The configuration is read from a resource file named "config.properties"
Expand Down Expand Up @@ -194,12 +191,13 @@ public static int databaseVersion() {

if (inputStream == null) {
throw new FileNotFoundException(
"property file '" + CONFIG_FILE_NAME
+ "' not found in the classpath");
CONFIG_FILE_NAME + " resource not found. " +
"Check if it exists under src/test/resources/");
}

Properties prop = new Properties();
prop.load(inputStream);

HOST = prop.getProperty("HOST");
PORT = Integer.parseInt(prop.getProperty("PORT"));
SERVICE_NAME = prop.getProperty("DATABASE");
Expand All @@ -224,8 +222,17 @@ public static int databaseVersion() {
CONNECTION_FACTORY.create(),
CONNECTION_FACTORY.getMetadata());
}
catch (IOException loadFileException) {
throw new RuntimeException(loadFileException);
catch (Throwable initializationFailure) {
// Most test cases require a database connection; If it can't be
// configured, then the test run can not proceed. Print the failure and
// terminate the JVM:
initializationFailure.printStackTrace();
System.exit(-1);

// This throw is dead code; exit(-1) doesn't return. This throw helps
// javac to understand that the final fields are always initialized when
// this static initialization block returns successfully.
throw new RuntimeException(initializationFailure);
}
}
}