Skip to content

Commit

Permalink
Fix ZookeeperRegistry destroy by DestroyHook invoke error. (sofastack…
Browse files Browse the repository at this point in the history
…#244)

* Fix ZookeeperRegistry destroy by DestroyHook invoke error.

* add /ZookeeperRegistry destory test case

* refine test code

* fix failed test cases
  • Loading branch information
tiansxx authored and JervyShi committed Aug 4, 2018
1 parent d16f0ae commit b904f00
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void destroy() {

@Override
public void destroy(DestroyHook hook) {
hook.postDestroy();
hook.preDestroy();
destroy();
hook.postDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 com.alipay.sofa.rpc.registry.zk;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.alipay.sofa.rpc.base.Destroyable;
import com.alipay.sofa.rpc.config.RegistryConfig;
import com.alipay.sofa.rpc.registry.RegistryFactory;
import com.alipay.sofa.rpc.registry.zk.base.BaseZkTest;

/**
* @author tian
*/
public class ZookeeperRegistryDestroyTest extends BaseZkTest {

private static RegistryConfig registryConfig;

private static ZookeeperRegistry registry;

@BeforeClass
public static void setUp() {
registryConfig = new RegistryConfig()
.setProtocol("zookeeper")
.setSubscribe(true)
.setAddress("127.0.0.1:2181")
.setRegister(true);

registry = (ZookeeperRegistry) RegistryFactory.getRegistry(registryConfig);
registry.init();
Assert.assertTrue(registry.start());
}

@AfterClass
public static void tearDown() {
registry.destroy();
registry = null;
}

@Test
public void testDestroy() {
MockDestroyHook mockHook = new MockDestroyHook();
registry.destroy(mockHook);

Assert.assertTrue(mockHook.isPreDestory());
Assert.assertTrue(mockHook.isPostDestroy());
}

private static class MockDestroyHook implements Destroyable.DestroyHook {
private boolean preDestory = false;

private boolean postDestroy = false;

@Override
public void preDestroy() {
preDestory = true;
}

@Override
public void postDestroy() {
postDestroy = true;
}

public boolean isPreDestory() {
return preDestory;
}

public boolean isPostDestroy() {
return postDestroy;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,5 @@ public Map<String, String> getData() {
return concurrentHashMap;
}
}

}

0 comments on commit b904f00

Please sign in to comment.