Zookeeper: use a single ZK instance in tests
This commit is contained in:
committed by
Artem Bilan
parent
ec1154fb93
commit
54a0d0c26a
@@ -687,11 +687,16 @@ project('spring-integration-zookeeper') {
|
||||
description = 'Spring Integration Zookeeper Support'
|
||||
dependencies {
|
||||
compile project(":spring-integration-core")
|
||||
compile ("org.apache.zookeeper:zookeeper:$zookeeperVersion")
|
||||
|
||||
compile ("org.apache.zookeeper:zookeeper:$zookeeperVersion") {
|
||||
exclude group: 'io.netty', module: 'netty'
|
||||
exclude group: 'junit', module: 'junit'
|
||||
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
|
||||
exclude group: 'log4j', module: 'log4j'
|
||||
}
|
||||
|
||||
compile("org.apache.curator:curator-recipes:$curatorVersion") {
|
||||
exclude group: 'org.apache.zookeeper', module: 'zookeeper'
|
||||
exclude group: 'org.jboss.netty', module: 'netty'
|
||||
}
|
||||
|
||||
testCompile "org.springframework.integration:spring-integration-test"
|
||||
|
||||
@@ -43,7 +43,9 @@ import org.apache.curator.test.TestingServer;
|
||||
import org.apache.curator.utils.CloseableUtils;
|
||||
import org.hamcrest.collection.IsIterableContainingInOrder;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -60,24 +62,19 @@ public class ZookeeperMetadataStoreTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZookeeperMetadataStore.class);
|
||||
|
||||
private TestingServer testingServer;
|
||||
private static TestingServer testingServer;
|
||||
|
||||
private CuratorFramework client;
|
||||
|
||||
private ZookeeperMetadataStore metadataStore;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception{
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
testingServer = new TestingServer(true);
|
||||
client = createNewClient();
|
||||
metadataStore = new ZookeeperMetadataStore(client);
|
||||
metadataStore.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.metadataStore.stop();
|
||||
closeClient(this.client);
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
try {
|
||||
testingServer.stop();
|
||||
}
|
||||
@@ -87,6 +84,20 @@ public class ZookeeperMetadataStoreTests {
|
||||
testingServer.getTempDirectory().delete();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception{
|
||||
client = createNewClient();
|
||||
metadataStore = new ZookeeperMetadataStore(client);
|
||||
metadataStore.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
this.metadataStore.stop();
|
||||
this.client.delete().deletingChildrenIfNeeded().forPath(this.metadataStore.getRoot());
|
||||
CloseableUtils.closeQuietly(this.client);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetNonExistingKeyValue() {
|
||||
@@ -144,7 +155,7 @@ public class ZookeeperMetadataStoreTests {
|
||||
return metadataStore.get(testKey2);
|
||||
}
|
||||
})));
|
||||
closeClient(otherClient);
|
||||
CloseableUtils.closeQuietly(otherClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,7 +188,7 @@ public class ZookeeperMetadataStoreTests {
|
||||
}
|
||||
})));
|
||||
assertEquals("Integration-2", otherMetadataStore.get(testKey));
|
||||
closeClient(otherClient);
|
||||
CloseableUtils.closeQuietly(otherClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -410,13 +421,4 @@ public class ZookeeperMetadataStoreTests {
|
||||
return client;
|
||||
}
|
||||
|
||||
private void closeClient(CuratorFramework client) {
|
||||
try {
|
||||
CloseableUtils.closeQuietly(client);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Exception thrown while closing client: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user