You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by al...@apache.org on 2021/05/24 10:48:42 UTC

[geode] branch develop updated: GEODE-9288: DeployedJarTest fails because JavaCompiler fails to delete temp dir (#6501)

This is an automated email from the ASF dual-hosted git repository.

albertobr pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6702402  GEODE-9288: DeployedJarTest fails because JavaCompiler fails to delete temp dir (#6501)
6702402 is described below

commit 6702402a98de98c61b71d9d017c863dc659acf0c
Author: Alberto Bustamante Reyes <al...@est.tech>
AuthorDate: Mon May 24 12:47:37 2021 +0200

    GEODE-9288: DeployedJarTest fails because JavaCompiler fails to delete temp dir (#6501)
---
 .../rest/internal/web/RestFunctionExecuteDUnitTest.java   |  3 ++-
 .../internal/deployment/FunctionScannerTest.java          |  3 ++-
 .../org/apache/geode/test/compiler/JarBuilderTest.java    |  3 ++-
 .../org/apache/geode/test/compiler/JavaCompilerTest.java  |  3 ++-
 .../java/org/apache/geode/test/compiler/JarBuilder.java   |  6 +++++-
 .../java/org/apache/geode/test/compiler/JavaCompiler.java | 15 ++++++++-------
 6 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/rest/internal/web/RestFunctionExecuteDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/rest/internal/web/RestFunctionExecuteDUnitTest.java
index dd63738..7ff1f3d 100644
--- a/geode-assembly/src/distributedTest/java/org/apache/geode/rest/internal/web/RestFunctionExecuteDUnitTest.java
+++ b/geode-assembly/src/distributedTest/java/org/apache/geode/rest/internal/web/RestFunctionExecuteDUnitTest.java
@@ -45,7 +45,7 @@ public class RestFunctionExecuteDUnitTest {
   @ClassRule
   public static GfshCommandRule gfsh = new GfshCommandRule();
 
-  private static final JarBuilder jarBuilder = new JarBuilder();
+  private static JarBuilder jarBuilder;
 
   private static MemberVM locator;
   private static MemberVM server1;
@@ -55,6 +55,7 @@ public class RestFunctionExecuteDUnitTest {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
+    jarBuilder = new JarBuilder();
     // prepare the jar to deploy
     File jarsToDeploy = new File(gfsh.getWorkingDir(), "function.jar");
     jarBuilder.buildJar(jarsToDeploy, loadClassToFile());
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/deployment/FunctionScannerTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/deployment/FunctionScannerTest.java
index e7be9ae..9c19a3e 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/deployment/FunctionScannerTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/deployment/FunctionScannerTest.java
@@ -18,6 +18,7 @@ import static org.apache.geode.test.util.ResourceUtils.createTempFileFromResourc
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
 
 import org.junit.Before;
@@ -40,7 +41,7 @@ public class FunctionScannerTest {
   private File outputJar;
 
   @Before
-  public void setup() {
+  public void setup() throws IOException {
     jarBuilder = new JarBuilder();
     functionScanner = new FunctionScanner();
     outputJar = new File(temporaryFolder.getRoot(), "output.jar");
diff --git a/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JarBuilderTest.java b/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JarBuilderTest.java
index 9a2f0d8..ab0b768 100644
--- a/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JarBuilderTest.java
+++ b/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JarBuilderTest.java
@@ -18,6 +18,7 @@ import static java.util.stream.Collectors.toSet;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -42,7 +43,7 @@ public class JarBuilderTest {
   private File outputJar;
 
   @Before
-  public void setup() {
+  public void setup() throws IOException {
     jarBuilder = new JarBuilder();
     outputJar = new File(temporaryFolder.getRoot(), "output.jar");
   }
diff --git a/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JavaCompilerTest.java b/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JavaCompilerTest.java
index e3923ea..4c241e8 100644
--- a/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JavaCompilerTest.java
+++ b/geode-junit/src/integrationTest/java/org/apache/geode/test/compiler/JavaCompilerTest.java
@@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -55,7 +56,7 @@ public class JavaCompilerTest {
   }
 
   @Test
-  public void invalidSourceThrowsException() {
+  public void invalidSourceThrowsException() throws IOException {
     JavaCompiler javaCompiler = new JavaCompiler();
     String sourceCode = "public class foo {this is not valid java source code}";
     assertThatThrownBy(() -> javaCompiler.compile(sourceCode)).isInstanceOf(Exception.class);
diff --git a/geode-junit/src/main/java/org/apache/geode/test/compiler/JarBuilder.java b/geode-junit/src/main/java/org/apache/geode/test/compiler/JarBuilder.java
index 96ef3a5..ee838f6 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/compiler/JarBuilder.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/compiler/JarBuilder.java
@@ -59,7 +59,11 @@ import java.util.jar.JarOutputStream;
  * </pre>
  **/
 public class JarBuilder {
-  private final JavaCompiler javaCompiler = new JavaCompiler();
+  private final JavaCompiler javaCompiler;
+
+  public JarBuilder() throws IOException {
+    javaCompiler = new JavaCompiler();
+  }
 
   /**
    * Adds the given jarFile to the classpath that will be used for compilation by the buildJar
diff --git a/geode-junit/src/main/java/org/apache/geode/test/compiler/JavaCompiler.java b/geode-junit/src/main/java/org/apache/geode/test/compiler/JavaCompiler.java
index 7abbcd1..e6fef06 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/compiler/JavaCompiler.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/compiler/JavaCompiler.java
@@ -18,6 +18,8 @@ import static java.util.stream.Collectors.toList;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -26,17 +28,16 @@ import java.util.stream.Stream;
 import javax.tools.ToolProvider;
 
 import com.google.common.base.Charsets;
-import com.google.common.io.Files;
 import org.apache.commons.io.FileUtils;
 
 
 public class JavaCompiler {
-  private File tempDir;
+  private Path tempDir;
   private String classpath;
 
-  public JavaCompiler() {
-    this.tempDir = Files.createTempDir();
-    tempDir.deleteOnExit();
+  public JavaCompiler() throws IOException {
+    this.tempDir = Files.createTempDirectory("javaCompiler");
+    tempDir.toFile().deleteOnExit();
     this.classpath = System.getProperty("java.class.path");
   }
 
@@ -108,8 +109,8 @@ public class JavaCompiler {
     }
   }
 
-  private File createSubdirectory(File parent, String directoryName) {
-    File subdirectory = parent.toPath().resolve(directoryName).toFile();
+  private File createSubdirectory(Path parent, String directoryName) {
+    File subdirectory = parent.resolve(directoryName).toFile();
     if (!subdirectory.exists()) {
       subdirectory.mkdirs();
     }