From 07420b0c56066326bd409e9537ee3d43ab6b1a51 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Fri, 30 Aug 2024 07:50:53 +0530 Subject: [PATCH] GH-43869: [Java][CI] Flight related failure in the AMD64 Windows Server 2022 Java JDK 11 CI (#43850) ### Rationale for this change CIs have been consistently failing on windows recently due to an issue with derby configuration. This PR investigates a solution for this. ### What changes are included in this PR? Changing the flow of the exception handling and state return. ### Are these changes tested? Via existing test cases. ### Are there any user-facing changes? No * GitHub Issue: #43869 Authored-by: Vibhatha Lakmal Abeykoon Signed-off-by: David Li --- .../flight/sql/example/FlightSqlExample.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java index e7127faf97539..67bfc85c48602 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java @@ -181,9 +181,8 @@ public static void main(String[] args) throws Exception { public FlightSqlExample(final Location location, final String dbName) { // TODO Constructor should not be doing work. - checkState( - removeDerbyDatabaseIfExists(dbName) && populateDerbyDatabase(dbName), - "Failed to reset Derby database!"); + checkState(removeDerbyDatabaseIfExists(dbName), "Failed to clear Derby database!"); + checkState(populateDerbyDatabase(dbName), "Failed to populate Derby database!"); databaseUri = "jdbc:derby:target/" + dbName; final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(databaseUri, new Properties()); @@ -253,36 +252,35 @@ public FlightSqlExample(final Location location, final String dbName) { } public static boolean removeDerbyDatabaseIfExists(final String dbName) { - boolean wasSuccess; final Path path = Paths.get("target" + File.separator + dbName); try (final Stream walk = Files.walk(path)) { /* * Iterate over all paths to delete, mapping each path to the outcome of its own - * deletion as a boolean representing whether or not each individual operation was - * successful; then reduce all booleans into a single answer, and store that into - * `wasSuccess`, which will later be returned by this method. + * deletion as a boolean representing whether each individual operation was + * successful; then reduce all booleans into a single answer. * If for whatever reason the resulting `Stream` is empty, throw an `IOException`; * this not expected. */ - wasSuccess = + boolean unused = walk.sorted(Comparator.reverseOrder()) .map(Path::toFile) .map(File::delete) .reduce(Boolean::logicalAnd) .orElseThrow(IOException::new); - } catch (IOException e) { + } catch (NoSuchFileException e) { /* * The only acceptable scenario for an `IOException` to be thrown here is if * an attempt to delete an non-existing file takes place -- which should be * alright, since they would be deleted anyway. */ - if (!(wasSuccess = e instanceof NoSuchFileException)) { - LOGGER.error(format("Failed attempt to clear DerbyDB: <%s>", e.getMessage()), e); - } + LOGGER.error(format("No existing Derby database to delete.: <%s>", e.getMessage()), e); + return true; + } catch (Exception e) { + LOGGER.error(format("Failed attempt to clear DerbyDB.: <%s>", e.getMessage()), e); + return false; } - - return wasSuccess; + return true; } private static boolean populateDerbyDatabase(final String dbName) {