Skip to content

Commit e87c884

Browse files
Merge pull request #7 from oracle/test_config_error
Aborting test run if config is missing
2 parents 1203b99 + 0bc7e3e commit e87c884

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/test/java/oracle/r2dbc/DatabaseConfig.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@
2929
import org.reactivestreams.Publisher;
3030

3131
import java.io.FileNotFoundException;
32-
import java.io.IOException;
3332
import java.io.InputStream;
3433
import java.sql.DriverManager;
3534
import java.sql.SQLException;
3635
import java.time.Duration;
3736
import java.util.Properties;
3837

39-
import static org.junit.jupiter.api.Assertions.fail;
40-
4138
/**
4239
* Stores configuration used by integration tests that connect to a database.
4340
* The configuration is read from a resource file named "config.properties"
@@ -194,12 +191,13 @@ public static int databaseVersion() {
194191

195192
if (inputStream == null) {
196193
throw new FileNotFoundException(
197-
"property file '" + CONFIG_FILE_NAME
198-
+ "' not found in the classpath");
194+
CONFIG_FILE_NAME + " resource not found. " +
195+
"Check if it exists under src/test/resources/");
199196
}
200197

201198
Properties prop = new Properties();
202199
prop.load(inputStream);
200+
203201
HOST = prop.getProperty("HOST");
204202
PORT = Integer.parseInt(prop.getProperty("PORT"));
205203
SERVICE_NAME = prop.getProperty("DATABASE");
@@ -224,8 +222,17 @@ public static int databaseVersion() {
224222
CONNECTION_FACTORY.create(),
225223
CONNECTION_FACTORY.getMetadata());
226224
}
227-
catch (IOException loadFileException) {
228-
throw new RuntimeException(loadFileException);
225+
catch (Throwable initializationFailure) {
226+
// Most test cases require a database connection; If it can't be
227+
// configured, then the test run can not proceed. Print the failure and
228+
// terminate the JVM:
229+
initializationFailure.printStackTrace();
230+
System.exit(-1);
231+
232+
// This throw is dead code; exit(-1) doesn't return. This throw helps
233+
// javac to understand that the final fields are always initialized when
234+
// this static initialization block returns successfully.
235+
throw new RuntimeException(initializationFailure);
229236
}
230237
}
231238
}

0 commit comments

Comments
 (0)