vlingo / xoom-actors

The VLINGO XOOM platform SDK for the type-safe Actor Model, delivering Reactive concurrency, high scalability, high-throughput, and resiliency using Java and other JVM languages.
https://vlingo.io
Mozilla Public License 2.0
229 stars 28 forks source link

Dynamic proxy generation writes java code for test actors into non-test directory #98

Closed bwehrle closed 2 years ago

bwehrle commented 2 years ago

When using IntelliJ the xoom-actors project does not compile. The proxies generated for test classes are put into the generated-soures directory (for main modules). The compilation of this directory fails because these proxies are referencing types in the test path that are not in the non-test compile path.

It turns out that every proxy is generated and put inside the main generated resources. This is not technically correct- even if it works for maven- as it implies shipping production jars with non-production interfaces/implementations.

See io/vlingo/xoom/actors/ActorProxy.java:82

private static <T> T tryGenerateCreate(
          final Class<T> protocol,
          final Actor actor,
          final Mailbox mailbox,
          final String targetClassname) {

    final ClassLoader classLoader = classLoaderFor(actor);
    try (final ProxyGenerator generator = ProxyGenerator.forMain(classLoader, true, actor.logger())) {
      return tryGenerateCreate(protocol, actor, mailbox, generator, targetClassname);
    } catch (Exception emain) {

The solution should consider the source of the class and chose the ProxyGenerator "forMain" or "forTest" method.

VaughnVernon commented 2 years ago

Thanks @bwehrle We don't see that failure at all. Are you using Gradle?

bwehrle commented 2 years ago

No, this is using normal IntelliJ with maven. I had not had this problem before, but have not been able to compile xoom-actors in IntelliJ without manually fixing the file to code to use "forTest" while running my tests. Regardless, even if it works in Maven, there is an undesirable consequence of shipping test code with production jars.

When I do all of my building using Maven inside IntelliJ it works fine. But when I try to run/debug an individual test, the build fails. In order to reproduct, you need to try to run a specific test or test class.

If I delegate all the build to Maven the problem goes away. But the debugger does not work for me in IntelliJ when trying to debug maven executions, so that is not a work around.

VaughnVernon commented 2 years ago

@bwehrle I found the issue. Some of our pom.xml files across the platform are missing the plugin and test-compile configuration that prevents this issue:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>

We should soon have fixes in xoom-*-1.9.4-SNAPSHOT.

VaughnVernon commented 2 years ago

@bwehrle I was wrong in my previous diagnosis. The way this has been addressed is as follows:

You can review the code here: https://github.com/vlingo/xoom-actors/compare/7e51eea466e1...0711bab912da

Please test with your environment. Another developer on our team will test inside IntelliJ.

bwehrle commented 2 years ago

Hi @VaughnVernon - thanks for fixing this. I was surprised to see that there is no other way to determine that something is running under test or main. However, this does indeed fix the problem.

I confirmed that under Maven there is no such problem and in no case does test code get shipped with the production jar even without this fix. So we can close this one.

VaughnVernon commented 2 years ago

Thanks for confirming @bwehrle!