diff --git a/wres-io/test/wres/io/database/QueryTest.java b/wres-io/test/wres/io/database/QueryTest.java index a38aa430d0..557140ac2c 100644 --- a/wres-io/test/wres/io/database/QueryTest.java +++ b/wres-io/test/wres/io/database/QueryTest.java @@ -23,9 +23,13 @@ import wres.system.SettingsFactory; import wres.system.SystemSettings; +/** + * Tests database queries. + */ + public class QueryTest { - private static final Logger LOGGER = LoggerFactory.getLogger( QueryTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger( QueryTest.class ); private SystemSettings systemSettings; // We need a way to control faked out database connections @@ -65,7 +69,7 @@ public static void setup() public void beforeEachTest() throws SQLException, DatabaseException { LOGGER.trace( "@Before began" ); - this.systemSettings = SettingsFactory.defaultTest(); + this.systemSettings = SettingsFactory.getDefaultSettings(); this.rawConnection = DriverManager.getConnection( QueryTest.testDatabase.getJdbcString() ); // Set up a bare bones database with only the schema @@ -76,7 +80,6 @@ public void beforeEachTest() throws SQLException, DatabaseException LOGGER.trace( "@Before ended" ); } - /** * Test to see if a Query can execute a single static query in the database and return the desired results * @throws SQLException Thrown if a connection could not be created @@ -138,11 +141,10 @@ public void parameterizedCallTest() throws SQLException // We told it to give us the value 1 as "one", so that should be what we get back int value = results.getInt( "one" ); - Assert.assertEquals( value, 1 ); + Assert.assertEquals( 1, value ); } } - /** * Tests to see if a simple query can be executed * @throws SQLException Thrown if a connection could not be created @@ -175,7 +177,7 @@ public void simpleExecuteTest() throws SQLException, LiquibaseException testQuery = new Query( this.systemSettings, "SELECT hash, project_name FROM wres.Project;" ); - try (ResultSet projects = testQuery.call( connection )) + try ( ResultSet projects = testQuery.call( connection ) ) { // If "isBeforeFirst" is true, it means that there is at least one entry returned, // meaning that inserts occurred as requested @@ -186,10 +188,10 @@ public void simpleExecuteTest() throws SQLException, LiquibaseException // The values we sent into the insert should show up in the results Assert.assertEquals( "abcd123", projects.getString( "hash" ) ); - Assert.assertEquals( "zero", projects.getString("project_name") ); + Assert.assertEquals( "zero", projects.getString( "project_name" ) ); // If there is anything left, it means that too much data got added - Assert.assertFalse(projects.next()); + Assert.assertFalse( projects.next() ); } } @@ -198,7 +200,6 @@ public void simpleExecuteTest() throws SQLException, LiquibaseException QueryTest.testDatabase.dropLiquibaseChangeTables( this.rawConnection ); } - /** * Test to see if many values can be inserted into the database with a single batch execution * @throws SQLException Thrown if a connection could not be created @@ -220,14 +221,14 @@ public void batchExecuteTest() throws SQLException, LiquibaseException String script = "INSERT INTO wres.Project ( hash, project_name ) VALUES ( ?, ? );"; // Since we're going to run this as batch, we need a ton of parameters to pass in - List arguments = new ArrayList<>( ); + List arguments = new ArrayList<>(); - arguments.add(new Object[]{"0", "zero"}); - arguments.add(new Object[]{"1", "one"}); - arguments.add(new Object[]{"2", "two"}); - arguments.add(new Object[]{"3", "three"}); - arguments.add(new Object[]{"4", "four"}); - arguments.add(new Object[]{"5", null}); + arguments.add( new Object[] { "0", "zero" } ); + arguments.add( new Object[] { "1", "one" } ); + arguments.add( new Object[] { "2", "two" } ); + arguments.add( new Object[] { "3", "three" } ); + arguments.add( new Object[] { "4", "four" } ); + arguments.add( new Object[] { "5", null } ); Query testQuery = new Query( this.systemSettings, script ) .setBatchParameters( arguments ); @@ -245,7 +246,7 @@ public void batchExecuteTest() throws SQLException, LiquibaseException testQuery = new Query( this.systemSettings, "SELECT hash, project_name FROM wres.Project;" ); - try (ResultSet projects = testQuery.call( connection )) + try ( ResultSet projects = testQuery.call( connection ) ) { // If "isBeforeFirst" is true, it means that there is at least one entry returned, // meaning that inserts occurred as requested @@ -253,7 +254,7 @@ public void batchExecuteTest() throws SQLException, LiquibaseException // Inserts alone doesn't mean it works, so we need to go through each row and check the arguments // This was done in batch, the values should still be in order - for (Object[] argument : arguments) + for ( Object[] argument : arguments ) { projects.next(); Assert.assertEquals( argument[0], projects.getString( "hash" ) ); @@ -261,7 +262,7 @@ public void batchExecuteTest() throws SQLException, LiquibaseException } // If there is anything left, it means that too much data got added - Assert.assertFalse("Too many values were returned.", projects.next()); + Assert.assertFalse( "Too many values were returned.", projects.next() ); } } @@ -270,7 +271,6 @@ public void batchExecuteTest() throws SQLException, LiquibaseException QueryTest.testDatabase.dropLiquibaseChangeTables( this.rawConnection ); } - /** * Test to see if values may be added to the database with a parameterized statement * @throws SQLException Thrown if a connection could not be created @@ -307,7 +307,7 @@ public void parameterizedExecuteTest() throws SQLException, LiquibaseException testQuery = new Query( this.systemSettings, "SELECT hash, project_name FROM wres.Project;" ); - try (ResultSet projects = testQuery.call( connection )) + try ( ResultSet projects = testQuery.call( connection ) ) { // If "isBeforeFirst" is true, it means that there is at least one entry returned, // meaning that inserts occurred as requested @@ -315,7 +315,7 @@ public void parameterizedExecuteTest() throws SQLException, LiquibaseException int entryCount = 0; - while (projects.next()) + while ( projects.next() ) { entryCount++; Assert.assertEquals( "0", projects.getString( "hash" ) ); @@ -331,7 +331,6 @@ public void parameterizedExecuteTest() throws SQLException, LiquibaseException QueryTest.testDatabase.dropLiquibaseChangeTables( this.rawConnection ); } - /** * The status of a connection's autocommit setting should be appropriate * to whether the query itself was supposed to run in a transaction. @@ -357,7 +356,7 @@ public void disableAutoCommitWhenInTransaction() throws SQLException Assert.assertFalse( "Autocommit should have been switched " + "off, but the query may have been run with " + "autocommit on.", - connection.getAutoCommit() ); + connection.getAutoCommit() ); } } @@ -409,4 +408,4 @@ public static void tearDown() QueryTest.testDatabase = null; LOGGER.trace( "@AfterClass ended" ); } -} +} \ No newline at end of file diff --git a/wres-system/src/wres/system/SettingsFactory.java b/wres-system/src/wres/system/SettingsFactory.java index 467893eab9..4d0e98c374 100644 --- a/wres-system/src/wres/system/SettingsFactory.java +++ b/wres-system/src/wres/system/SettingsFactory.java @@ -86,10 +86,10 @@ public static SystemSettings createSettingsFromXml( InputStream xmlInputStream ) } /** - * Method for construction of default settings used in testing + * Method for construction of default settings used in testing. * @return SystemSettings */ - public static SystemSettings defaultTest() + public static SystemSettings getDefaultSettings() { DatabaseSettings.DatabaseSettingsBuilder builder = DatabaseSettings.builder(); applyDatabaseSystemPropertyOverrides( builder ); @@ -197,6 +197,7 @@ private static void applySystemPropertyOverrides( SystemSettingsBuilder systemBu SettingsFactory.setMaximumReadThreads( systemBuilder, systemSettings ); SettingsFactory.setFeatureBatchSize( systemBuilder, systemSettings ); SettingsFactory.setFeatureBatchThreshold( systemBuilder, systemSettings ); + SettingsFactory.setMaximumSamplingUncertaintyThreads( systemBuilder, systemSettings ); } /** @@ -395,6 +396,20 @@ private static void setMaximumReadThreads( SystemSettingsBuilder systemBuilder, 0 ); } + /** + * Sets the maximum number of sampling uncertainty threads. + * @param systemBuilder the system settings builder to update + * @param systemSettings the existing system settings for defaults + */ + private static void setMaximumSamplingUncertaintyThreads( SystemSettingsBuilder systemBuilder, + SystemSettings systemSettings ) + { + SettingsFactory.setPropertyWithIntegerGreaterThanThis( "wres.maximumSamplingUncertaintyThreads", + systemSettings.getMaximumSamplingUncertaintyThreads(), + systemBuilder::maximumSamplingUncertaintyThreads, + 0 ); + } + /** * Sets the feature batch size. * @param systemBuilder the system settings builder to update