0

I'm relatively new to activeJdbc and want to test my models with Junit in Intellij. At first i ran into problems with static instrumentation - so i followed the guide on GitHub to use dynamic instrumentation.

I set up a Junit test in IntelliJ and gave following arguments to the VM: -javaagent:"/home/IdeaProjects/project/libs/activejdbc-instrumentation-2.2.jar" and -Dactivejdbc-instrumentation.log=true .

The models are instrumented, but are not found in the test. From the logs it looks like instrumentation is not finished while the test already starts.

This is the stacktrace i got:

ActiveJDBC Instrumentation - You are using dynamic instrumentation...ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.EmailConfiguration
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.User
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.AuditLog
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.Tag
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.ChannelMessageActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.UserRole
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.MessageContent
ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.Channel
08:47:38.401 [main] INFO org.javalite.activejdbc.Configuration - Reading properties from: /database.properties. Will try classpath, then file system.

org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath

    at org.javalite.activejdbc.ModelFinder.findModels(ModelFinder.java:44)
    at org.javalite.activejdbc.Registry.init(Registry.java:126)
    at org.javalite.activejdbc.Registry.getMetaModel(Registry.java:103)
    at org.javalite.activejdbc.ModelDelegate.metaModelOf(ModelDelegate.java:307)
    at org.javalite.activejdbc.Model.<init>(Model.java:79)
    at team2.demo.ajdbcModels.AuditLog.<init>(AuditLog.java:5)
    at models.AuditLogTest.shouldValidateRequiredAttributes(AuditLogTest.java:16)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:78)
    at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:84)
    at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
    at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:161)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

ActiveJDBC Instrumentation - Instrumented model: team2.demo.ajdbcModels.MessageBox

Process finished with exit code 255
moejoe
  • 138
  • 5

2 Answers2

0

The Dynamic instrumentation makes changes in byte code of classes as they are loaded into runtime. It was designed before Java 8. Unfortunately Java 8 Lambda feature also mangles class byte code, which made for a nasty conflict of byte code instrumentation bug we were never able to resolve. As such, Dynamic instrumentation feature will be pulled from ActiveJDBC, leaving only static instrumentation as an option.

We suggest to switch to static instrumentation only.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • ok, thanks for the quick answer. But how can i execute unit tests with static instrumentation? I ran exactly into those problems described on your github repo. I think those problems are related to some IDEs - is the solution to dont use an IDE for testing? – moejoe Jun 13 '19 at 18:04
  • Please, check out the video on this page: http://javalite.io/instrumentation. The basic idea is to execute instrumentation before running a unit test from a shell/batch/Ant script. You can also do this as a Maven task, but Maven takes 2 - 3 seconds to start, which is annoying. We have been building large systems on ActiveJDBC in the past 10 years, with more than 100 tables in the schema, and even for schemas this large, instrumentation takes less than 1 seconds. You will get used to it and will stop paying attention. Just wire the instrumentation script to your IDE to trigger before tests. – ipolevoy Jun 14 '19 at 20:38
  • if you do not touch morels, and they have been instrumented, no need for instrumentation – ipolevoy Jun 14 '19 at 20:39
  • so i guess instead of the maven goal it is also possible to add the gradle task of the instrumentation as a post-compile step? – moejoe Jun 15 '19 at 09:46
  • Why not? It is just a small task you can call from any technology – ipolevoy Jun 16 '19 at 16:15
0

You have to configure IntelliJ IDEA to delegate IDE build/run actions to Gradle (see option Preferences | Build, Execution, Deployment | Build Tools | Gradle | Runner | Delegate IDE build/run actions to gradle).

This works in my environment: IDEA Ultimate 2018.3, Gradle 4.10.3, JUnit 5, ActiveJDBC 2.2