You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "kbuntrock (via GitHub)" <gi...@apache.org> on 2024/04/22 21:20:35 UTC

[PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

kbuntrock opened a new pull request, #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147

   The project tests cannot be run on a jdk21. See : https://issues.apache.org/jira/browse/MBUILDCACHE-88
   
   Please not that this fix does not address the comment line 123 of `CacheConfigImplTest.class` : 
   
   `// unfortunate and potentially fragile deep mocking, but helps avoid most disk involvement while working around
    // the static nio Files.exists method`
   
   The mock implementation can still be considered as fragile.
   
   --------------------------------------------------------------
   
   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [x] Make sure there is a [MBUILDCACHE JIRA issue](https://issues.apache.org/jira/browse/MBUILDCACHE) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes.
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Format the pull request title like `[MBUILDCACHE-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MBUILDCACHE-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [x] You have run the [Core IT][core-its] successfully.
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [x] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#issuecomment-2955471533

   Resolve #316


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#issuecomment-2955452063

   Resolve #316


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "AlexanderAshitkin (via GitHub)" <gi...@apache.org>.
AlexanderAshitkin commented on code in PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#discussion_r1580025685


##########
src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java:
##########
@@ -122,11 +126,30 @@ private static void deepMockConfigFile(File mockFile, boolean exists) throws IOE
         when(mockPath.getFileSystem()).thenReturn(mockFileSystem);
         FileSystemProvider mockProvider = mock(FileSystemProvider.class);
         when(mockFileSystem.provider()).thenReturn(mockProvider);
+
+        // Mock for java < 20.
         if (!exists) {
             doThrow(new IOException("mock IOException"))
                     .when(mockProvider)
                     .checkAccess(ArgumentMatchers.eq(mockPath), ArgumentMatchers.any(AccessMode.class));
         }
+
+        // Mock for java >= 20. Since the FileSystemProvider.exists method does not exist before v20, we use reflection
+        // to create the mock
+        Optional<Method> methodToMock = Arrays.stream(FileSystemProvider.class.getDeclaredMethods())
+                .filter(method -> "exists".equals(method.getName()))
+                .findAny();
+        if (methodToMock.isPresent()) {
+            Class<?>[] paramTypes = methodToMock.get().getParameterTypes();
+            Object[] params = Arrays.stream(paramTypes)
+                    .map(paramType -> Mockito.any(paramType))
+                    .toArray();
+            try {
+                Mockito.when(methodToMock.get().invoke(mockProvider, params)).thenReturn(exists);

Review Comment:
   Looks correct, but why need to Mock it at all? If it is not present in java 17, we are not using it in code. Is it used by JDK 20 internally?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "kbuntrock (via GitHub)" <gi...@apache.org>.
kbuntrock commented on code in PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#discussion_r1580192169


##########
src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java:
##########
@@ -122,11 +126,30 @@ private static void deepMockConfigFile(File mockFile, boolean exists) throws IOE
         when(mockPath.getFileSystem()).thenReturn(mockFileSystem);
         FileSystemProvider mockProvider = mock(FileSystemProvider.class);
         when(mockFileSystem.provider()).thenReturn(mockProvider);
+
+        // Mock for java < 20.
         if (!exists) {
             doThrow(new IOException("mock IOException"))
                     .when(mockProvider)
                     .checkAccess(ArgumentMatchers.eq(mockPath), ArgumentMatchers.any(AccessMode.class));
         }
+
+        // Mock for java >= 20. Since the FileSystemProvider.exists method does not exist before v20, we use reflection
+        // to create the mock
+        Optional<Method> methodToMock = Arrays.stream(FileSystemProvider.class.getDeclaredMethods())
+                .filter(method -> "exists".equals(method.getName()))
+                .findAny();
+        if (methodToMock.isPresent()) {
+            Class<?>[] paramTypes = methodToMock.get().getParameterTypes();
+            Object[] params = Arrays.stream(paramTypes)
+                    .map(paramType -> Mockito.any(paramType))
+                    .toArray();
+            try {
+                Mockito.when(methodToMock.get().invoke(mockProvider, params)).thenReturn(exists);

Review Comment:
   Yes, it is used internally by the static `java.nio.file.Files#exists` method.
   
   Implementation differs from jdk versions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "kbuntrock (via GitHub)" <gi...@apache.org>.
kbuntrock commented on PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#issuecomment-2075794776

   > Thanks for this. To be sure this is tested maybe you could add build on jdk21 for both GHA and Jenkins. Thanks
   
   I tried very empirically to add a jdk21 string to the GHA actions files and Jenkins, but I have no idea how to try theses changes:
   - I guess github actions workflows needs an approval before running?
   - And Jenkins access requires an account. Is there an entry point to create an account?
   
   PS : I will squash all the extra commits when the devs are done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy merged PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#issuecomment-2073450704

   Thanks for this.
   To be sure this is tested maybe you could add build on jdk21 for both GHA and Jenkins.
   Thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [MBUILDCACHE-88] Fix tests execution on jdk > 20 [maven-build-cache-extension]

Posted by "kbuntrock (via GitHub)" <gi...@apache.org>.
kbuntrock commented on PR #147:
URL: https://github.com/apache/maven-build-cache-extension/pull/147#issuecomment-2081974049

   @olamy: thank you :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org