You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/09/02 21:21:29 UTC

[GitHub] [geode] kirklund commented on a change in pull request #6823: GEODE-9486: Fix getSrcPathFor in AnalyzeDataSerializablesJUnitTestBase

kirklund commented on a change in pull request #6823:
URL: https://github.com/apache/geode/pull/6823#discussion_r701430897



##########
File path: geode-dunit/src/integrationTest/java/org/apache/geode/codeAnalysis/AnalyzeDUnitSerializablesIntegrationTest.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.codeAnalysis;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.test.dunit.internal.DUnitSanctionedSerializablesService;
+import org.apache.geode.test.dunit.internal.Master;
+import org.apache.geode.test.junit.categories.SerializationTest;
+
+@Category(SerializationTest.class)
+public class AnalyzeDUnitSerializablesIntegrationTest extends AnalyzeSerializablesJUnitTestBase {
+  private static final Logger logger = LogService.getLogger();
+
+  private static final Set<Class<?>> IGNORE_CLASSES = new HashSet<>();
+  static {
+    IGNORE_CLASSES.add(Master.class);
+    classForName("org.apache.geode.test.dunit.internal.RemoteDUnitVM")
+        .ifPresent(IGNORE_CLASSES::add);

Review comment:
       It's a package-private class, so we couldn't add it in the same way as `Master`. The use of `Optional` was Dale's preferred way for error-handling instead of using `null`. I started out coding this:
   ```
     private static Class<?> classForName(String className) {
       try {
         return Class.forName(className);
       } catch (ClassNotFoundException e) {
         logger.error("Unable to add class {} to IGNORE_CLASSES", className, e);
       }
       return null;
     }
   ```
   Changing from `null` to `Optional` resulted in:
   ```
     private static Optional<Class<?>> classForName(String className) {
       try {
         return Optional.of(Class.forName(className));
       } catch (ClassNotFoundException e) {
         logger.error("Unable to add class {} to IGNORE_CLASSES", className, e);
       }
       return Optional.empty();
     }
   ```
   These 2 RMI classes fail the various checks in AnalyzeSerializable, and the cause seems to be the `CompiledClass` library in geode-junit's org.apache.geode.codeAnalysis package (which I think was a 3rd party library that was pulled into our test code). All `RMIObjects` fail deserialization checks with an "invalid RMI" failure because the library doesn't know how to handle RMI. If `Class.forName` failed to load `RemoteDUnitVM`, 2 or 3 tests end up failing. I'd like to fix that library but this is for test-only code anyway, so I decided to have it just skip RMI classes.
   
   One possibility that I considered was to throw `new RuntimeException(e)` wrapping the `ClassNotFoundException` but I think that will end up throwing a `LinkageError` of type `NoClassDefFoundError` when attempting to load `AnalyzeDUnitSerializablesIntegrationTest`.
   
   Yet another approach might be to not use a static constant for the `IGNORE_CLASSES` and just build up a the `Set` every time `ignoreClass` is called.
   
   I would be happy to change this to something better, especially if you have any other ideas.




-- 
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: notifications-unsubscribe@geode.apache.org

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