Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): convert groovy based test to java while upgrading spockframework to 2.2-groovy-3.0 #1201

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

j-sandy
Copy link
Contributor

@j-sandy j-sandy commented Jul 30, 2024

While upgrading spockframework from 2.0-groovy-3.0 to 2.2-groovy-3.0, encountered below errors during test execution of kork-exceptions and kork-pubsub-aws modules:

java.lang.ExceptionInInitializerError
        at org.spockframework.mock.runtime.CglibMockFactory.createMock(CglibMockFactory.java:24)
        at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:45)
        at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:58)
        at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:38)
        at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
        at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:50)
        at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:305)
        at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:295)
        at org.spockframework.lang.SpecInternals.SpyImpl(SpecInternals.java:172)
        at com.netflix.spinnaker.kork.core.RetrySupportSpec.should retry until success or #maxRetries attempts is reached(RetrySupportSpec.groovy:28)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4afcd809
        at app//net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464)
        at app//net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:339)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
        at app//net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
        at [email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at app//net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
        at app//net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
        at app//net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
        at app//net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
        at app//net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
        at app//net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
        at app//net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
        ... 10 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4afcd809
        at net.sf.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
        at net.sf.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:52)
        at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243)
        at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:332)
        ... 22 more

In order to fix this issue, converted the groovy based test classes RetrySupportSpec.groovy and SQSSubscriberSpec.groovy as java test classes.

}

@Test
void testRetryFailureMoreThanMaxretries() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try combining this with testRetryFailureLessThanMaxretries using e.g. CsvSource? That matches the spock tests and reduces a bunch of duplication.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose testSleepExponentially could get combined too with another param, but since it's separate in spock, I'm OK with it staying separate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

subscriber.listenForMessages();

// then
verify(messageAcknowledger, atLeastOnce()).ack(any(), any());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the groovy test do

Suggested change
verify(messageAcknowledger, atLeastOnce()).ack(any(), any());
verify(messageAcknowledger, once()).ack(any(), any());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.


// then
verify(messageAcknowledger, never()).ack(any(), any());
verify(messageAcknowledger, atLeastOnce()).nack(any(), any());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
verify(messageAcknowledger, atLeastOnce()).nack(any(), any());
verify(messageAcknowledger, once()).nack(any(), any());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

…ockframework to 2.2-groovy-3.0

While upgrading spockframework from 2.0-groovy-3.0 to 2.2-groovy-3.0, encountered below errors during test execution of kork-exceptions and kork-pubsub-aws modules:

```
java.lang.ExceptionInInitializerError
        at org.spockframework.mock.runtime.CglibMockFactory.createMock(CglibMockFactory.java:24)
        at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:45)
        at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:58)
        at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:38)
        at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
        at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:50)
        at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:305)
        at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:295)
        at org.spockframework.lang.SpecInternals.SpyImpl(SpecInternals.java:172)
        at com.netflix.spinnaker.kork.core.RetrySupportSpec.should retry until success or #maxRetries attempts is reached(RetrySupportSpec.groovy:28)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4afcd809
        at app//net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464)
        at app//net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:339)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
        at app//net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
        at [email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at app//net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
        at app//net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
        at app//net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
        at app//net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
        at app//net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
        at app//net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
        at app//net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
        at app//net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
        ... 10 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4afcd809
        at net.sf.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
        at net.sf.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:52)
        at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243)
        at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:332)
        ... 22 more
```

In order to fix this issue, converted the groovy based test classes `RetrySupportSpec.groovy` and `SQSSubscriberSpec.groovy` as java test classes.
@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Aug 1, 2024
@mergify mergify bot added the auto merged label Aug 1, 2024
@mergify mergify bot merged commit f4262c1 into spinnaker:master Aug 1, 2024
6 checks passed
@j-sandy j-sandy deleted the groovy2java branch August 1, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged ready to merge Approved and ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants