You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/30 02:19:11 UTC

[dubbo] branch 3.0 updated: [3.0] Patch shutdown hook test (#8958)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 423612a  [3.0] Patch shutdown hook test (#8958)
423612a is described below

commit 423612a60f5664475b56288d695b873841d68482
Author: zrlw <zr...@sina.com>
AuthorDate: Thu Sep 30 10:19:03 2021 +0800

    [3.0] Patch shutdown hook test (#8958)
    
    * reset dubbo boot strap before each testing
    
    * wait for deployer started
    
    * add private modifier
---
 .../dubbo/config/spring/DubboStateListener.java    | 35 ++++++++++++++++++++++
 .../dubbo/config/spring/ShutdownHookTest.java      | 11 ++++++-
 .../apache/dubbo/config/spring/demo-provider.xml   |  1 +
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/DubboStateListener.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/DubboStateListener.java
new file mode 100644
index 0000000..c5b6326
--- /dev/null
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/DubboStateListener.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config.spring;
+
+import org.apache.dubbo.common.deploy.DeployState;
+import org.apache.dubbo.config.spring.context.event.DubboApplicationStateEvent;
+import org.springframework.context.ApplicationListener;
+
+public class DubboStateListener implements ApplicationListener<DubboApplicationStateEvent> {
+
+    private DeployState state;
+    
+    @Override
+    public void onApplicationEvent(DubboApplicationStateEvent event) {
+        state = event.getState();
+    }
+    
+    public DeployState getState() {
+        return state;
+    }
+}
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ShutdownHookTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ShutdownHookTest.java
index 9c98cc6..2612ad7 100644
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ShutdownHookTest.java
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ShutdownHookTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.config.spring;
 
+import org.apache.dubbo.common.deploy.DeployState;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.context.DubboSpringInitCustomizerHolder;
 import org.apache.dubbo.rpc.model.ModuleModel;
@@ -26,7 +27,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
 public class ShutdownHookTest {
 
     @Test
-    public void testDisableShutdownHook(){
+    public void testDisableShutdownHook() throws InterruptedException {
 
         // set KeepRunningOnSpringClosed flag for next spring context
         DubboSpringInitCustomizerHolder.get().addCustomizer(context-> {
@@ -41,6 +42,14 @@ public class ShutdownHookTest {
                 resourcePath + "/demo-provider-properties.xml");
             providerContext.start();
 
+            DubboStateListener listener = providerContext.getBean(DubboStateListener.class);
+            for (int i = 0; i < 10; i++) {
+                if (DeployState.STARTED.equals(listener.getState())) {
+                    break;
+                }
+                Thread.sleep(100);
+            }
+
             ModuleModel moduleModel = providerContext.getBean(ModuleModel.class);
             Assertions.assertTrue(moduleModel.getDeployer().isStarted());
             Assertions.assertEquals(true, DubboBootstrap.getInstance().isStarted());
diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/demo-provider.xml b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/demo-provider.xml
index 414b7ba..2825b1e 100644
--- a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/demo-provider.xml
+++ b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/demo-provider.xml
@@ -36,4 +36,5 @@
 
     <bean id="demoService" class="org.apache.dubbo.config.spring.impl.DemoServiceImpl"/>
 
+    <bean id="dubboEventListener" class="org.apache.dubbo.config.spring.DubboStateListener" />
 </beans>