ActiveJDBC 和 Junit 中的动态检测问题
Problems with dynamic instrumentation in ActiveJDBC and Junit
我对 activeJdbc 比较陌生,想在 Intellij 中使用 Junit 测试我的模型。起初我 运行 遇到静态检测问题 - 所以我按照 GitHub 上的指南使用动态检测。
我在 IntelliJ 中设置了一个 Junit 测试并向 VM 提供了以下参数:
-javaagent:"/home/IdeaProjects/project/libs/activejdbc-instrumentation-2.2.jar"
和
-Dactivejdbc-instrumentation.log=true
.
模型已检测,但未在测试中找到。从日志看来,测试已经开始时检测尚未完成。
这是我得到的堆栈跟踪:
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.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=10=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.DefaultInternalRunner.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=10=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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
动态检测在 classes 加载到运行时时更改字节码。它是在 Java 8 之前设计的。不幸的是,Java 8 Lambda 功能还破坏了 class 字节代码,这导致了我们永远无法解决的字节代码检测错误的严重冲突。因此,将从 ActiveJDBC 中提取动态检测功能,只留下静态检测作为选项。
我们建议仅切换到静态检测。
您必须配置 IntelliJ IDEA 以将 IDE build/run 操作委托给 Gradle(请参阅选项首选项 | 构建、执行、部署 | 构建工具 | Gradle | 亚军 | 委托 IDE build/run 行动给 gradle).
这适用于我的环境:IDEA Ultimate 2018.3,Gradle 4.10.3,JUnit 5,ActiveJDBC 2.2
我对 activeJdbc 比较陌生,想在 Intellij 中使用 Junit 测试我的模型。起初我 运行 遇到静态检测问题 - 所以我按照 GitHub 上的指南使用动态检测。
我在 IntelliJ 中设置了一个 Junit 测试并向 VM 提供了以下参数:
-javaagent:"/home/IdeaProjects/project/libs/activejdbc-instrumentation-2.2.jar"
和
-Dactivejdbc-instrumentation.log=true
.
模型已检测,但未在测试中找到。从日志看来,测试已经开始时检测尚未完成。
这是我得到的堆栈跟踪:
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.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=10=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.DefaultInternalRunner.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=10=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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
动态检测在 classes 加载到运行时时更改字节码。它是在 Java 8 之前设计的。不幸的是,Java 8 Lambda 功能还破坏了 class 字节代码,这导致了我们永远无法解决的字节代码检测错误的严重冲突。因此,将从 ActiveJDBC 中提取动态检测功能,只留下静态检测作为选项。
我们建议仅切换到静态检测。
您必须配置 IntelliJ IDEA 以将 IDE build/run 操作委托给 Gradle(请参阅选项首选项 | 构建、执行、部署 | 构建工具 | Gradle | 亚军 | 委托 IDE build/run 行动给 gradle).
这适用于我的环境:IDEA Ultimate 2018.3,Gradle 4.10.3,JUnit 5,ActiveJDBC 2.2