vanilla111 opened a new issue #3314:
URL: https://github.com/apache/incubator-dolphinscheduler/issues/3314


   # Why "Failed to load ApplicationContext" when running tests locally
   
   The first is the test command I ran:
   
   ```
   mvn test -pl dolphinscheduler-server -Dtest 
=TaskPriorityQueueConsumerTest#testSHELLTask
   ```
   
   It should be noted that the above test is not the only one with this problem.
   
   ## The environment in which the problem occurs
   
   The problem was originally discovered by running tests in IDEA, but also by 
testing directly with the 'mvn' command.
   
   - Operating system: MacOS
   - JAVA: 1.8.0_111
   - Maven: 3.5.2
   - DS version: dev branch
   
   To verify that it was a local environment problem, I created a new virtual 
machine to test, which had the same problem.
   
   - Operating system: CentOS 7
   - JAVA: 1.8.0_221
   - Maven: 3.6.3
   - DS version: dev branch
   
   ## Action steps
   
   I tested it on my virtual machine using the following steps:
   
   ```
   git clone ...
   cd incubator-dolphinscheduler-github/
   git checkout dev
   mvn clean install -pl dolphinscheduler-common -am -Dmaven.test.skip=true
   mvn clean install -pl dolphinscheduler-dao -am -Dmaven.test.skip=true
   mvn clean install -pl dolphinscheduler-service -am -Dmaven.test.skip=true
   mvn clean install -pl dolphinscheduler-alert -am -Dmaven.test.skip=true
   mvn test -pl dolphinscheduler-server 
-Dtest=TaskPriorityQueueConsumerTest#testSHELLTask
   ```
   
   
   ## Error log
   
   ```
   [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 
15.247 s <<< FAILURE! - in 
org.apache.dolphinscheduler.server.master.consumer.TaskPriorityQueueConsumerTest
   [ERROR] 
testSHELLTask(org.apache.dolphinscheduler.server.master.consumer.TaskPriorityQueueConsumerTest)
  Time elapsed: 0 s  <<< ERROR!
   java.lang.IllegalStateException: Failed to load ApplicationContext
   Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'nettyExecutorManager': Unsatisfied dependency 
expressed through field 'zookeeperNodeManager'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperNodeManager': Unsatisfied dependency 
expressed through field 'registryCenter'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperRegistryCenter': Unsatisfied dependency 
expressed through field 'zookeeperCachedOperator'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperCachedOperator': Unsatisfied dependency 
expressed through field 'zookeeperClient'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying 
bean of type 'org.apache.dolphinscheduler.service.zk.CuratorZoo
 keeperClient' available: expected at least 1 bean which qualifies as autowire 
candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
   Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'zookeeperNodeManager': Unsatisfied dependency 
expressed through field 'registryCenter'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperRegistryCenter': Unsatisfied dependency 
expressed through field 'zookeeperCachedOperator'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperCachedOperator': Unsatisfied dependency 
expressed through field 'zookeeperClient'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying 
bean of type 'org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient' 
available: expected at least 1 bean which qualifies as autowire candidate. 
Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
   Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'zookeeperRegistryCenter': Unsatisfied dependency 
expressed through field 'zookeeperCachedOperator'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'zookeeperCachedOperator': Unsatisfied dependency 
expressed through field 'zookeeperClient'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying 
bean of type 'org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient' 
available: expected at least 1 bean which qualifies as autowire candidate. 
Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
   Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'zookeeperCachedOperator': Unsatisfied dependency 
expressed through field 'zookeeperClient'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying 
bean of type 'org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient' 
available: expected at least 1 bean which qualifies as autowire candidate. 
Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
   Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 
'org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency 
annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
   
   01:07:48.958 [SessionTracker] INFO 
org.apache.zookeeper.server.SessionTrackerImpl - SessionTrackerImpl exited loop!
   [INFO]
   [INFO] Results:
   [INFO]
   [ERROR] Errors:
   [ERROR]   TaskPriorityQueueConsumerTest.testSHELLTask ยป IllegalState Failed 
to load Appl...
   [INFO]
   [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
   [INFO]
   [INFO] 
------------------------------------------------------------------------
   [INFO] BUILD FAILURE
   [INFO] 
------------------------------------------------------------------------
   [INFO] Total time:  48.206 s
   [INFO] Finished at: 2020-07-27T01:07:49Z
   [INFO] 
------------------------------------------------------------------------
   [ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on 
project dolphinscheduler-server: There are test failures.
   [ERROR]
   [ERROR] Please refer to 
/root/incubator-dolphinscheduler-github/dolphinscheduler-server/target/surefire-reports
 for the individual test results.
   [ERROR] Please refer to dump files (if any exist) [date].dump, 
[date]-jvmRun[N].dump and [date].dumpstream.
   [ERROR] -> [Help 1]
   [ERROR]
   [ERROR] To see the full stack trace of the errors, re-run Maven with the -e 
switch.
   [ERROR] Re-run Maven using the -X switch to enable full debug logging.
   [ERROR]
   [ERROR] For more information about the errors and possible solutions, please 
read the following articles:
   [ERROR] [Help 1] 
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
   ```
   
   ## Problem analysis
   
   According to my own knowledge, I tried to solve the above problems. Because 
the reason is that `Autowired` errors, so I according to the prompt in the test 
code 
`dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java`,
 To annotate `@ContextConfiguration` added a class 
`CuratorZookeeperClient.class`, problem is solved.
   
   Just like this:
   
   ```java
   @ContextConfiguration(classes={DependencyConfig.class, 
SpringApplicationContext.class, SpringZKServer.class,
           NettyExecutorManager.class, ExecutorDispatcher.class, 
ZookeeperRegistryCenter.class, TaskPriorityQueueConsumer.class,
           ZookeeperNodeManager.class, ZookeeperCachedOperator.class, 
ZookeeperConfig.class, MasterConfig.class,
           CuratorZookeeperClient.class})
   ```
   
   I mentioned this problem with more than one test code, but I'll summarize it 
now:
   
   > if the test code needs to Autowired class A objects, class A needs to 
Autowired class B objects. Then `A.class` appears in the context configuration, 
while `B.class` is not, an 'Failed to load ApplicationContext' exception will 
appear and the test will fail.
   
   ## Question
   
   Every time the project merges new code, it will be tested automatically. Why 
is this test enough to pass without these problems?
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to