Skip to content

Commit

Permalink
apacheGH-43869: [Java][CI] Flight related failure in the AMD64 Window…
Browse files Browse the repository at this point in the history
…s Server 2022 Java JDK 11 CI (apache#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: apache#43869

Authored-by: Vibhatha Lakmal Abeykoon <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
vibhatha authored Aug 30, 2024
1 parent 6b24253 commit 07420b0
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<Path> 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<Boolean>` 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) {
Expand Down

0 comments on commit 07420b0

Please sign in to comment.