Author: kwright
Date: Tue Nov 12 13:19:57 2013
New Revision: 1541051
URL: http://svn.apache.org/r1541051
Log:
Add ZooKeeper test and infrastructure to run the ZooKeeper server from the test
framework
Added:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
(with props)
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
(with props)
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
(with props)
Modified:
manifoldcf/branches/CONNECTORS-13/framework/build.xml
Modified: manifoldcf/branches/CONNECTORS-13/framework/build.xml
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/build.xml?rev=1541051&r1=1541050&r2=1541051&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/build.xml (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/build.xml Tue Nov 12 13:19:57
2013
@@ -1292,7 +1292,8 @@
<test name="org.apache.manifoldcf.core.common.DateTest"
todir="test-output"/>
<test name="org.apache.manifoldcf.core.fuzzyml.TestFuzzyML"
todir="test-output"/>
-
+ <test
name="org.apache.manifoldcf.core.lockmanager.TestZooKeeperLocks"
todir="test-output"/>
+
</junit>
</target>
Added:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java?rev=1541051&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
(added)
+++
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
Tue Nov 12 13:19:57 2013
@@ -0,0 +1,37 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.core.lockmanager;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+import static org.junit.Assert.*;
+
+public class TestZooKeeperLocks extends ZooKeeperBase
+{
+ @Test
+ public void multiThreadZooKeeperLockTest()
+ throws Exception
+ {
+ // Sleep; cuts down on zookeeper noise for now
+ Thread.sleep(1000L);
+ // MHL
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/TestZooKeeperLocks.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java?rev=1541051&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
(added)
+++
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
Tue Nov 12 13:19:57 2013
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.core.lockmanager;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+import static org.junit.Assert.*;
+
+public class ZooKeeperBase
+{
+ protected File tempDir;
+ protected ZooKeeperInstance instance;
+
+ @Before
+ public void startZooKeeper()
+ throws Exception
+ {
+ tempDir = new File("zookeeper");
+ tempDir.mkdir();
+ instance = new ZooKeeperInstance(8348,tempDir);
+ instance.start();
+ }
+
+ @After
+ public void stopZookeeper()
+ throws Exception
+ {
+ instance.stop();
+ deleteRecursively(tempDir);
+ }
+
+ protected static void deleteRecursively(File tempDir)
+ throws Exception
+ {
+ if (tempDir.isDirectory())
+ {
+ File[] files = tempDir.listFiles();
+ for (File f : files)
+ {
+ deleteRecursively(f);
+ }
+ }
+ tempDir.delete();
+ }
+
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperBase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java?rev=1541051&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
(added)
+++
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
Tue Nov 12 13:19:57 2013
@@ -0,0 +1,127 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.core.lockmanager;
+
+import java.util.*;
+import java.io.*;
+import org.apache.zookeeper.server.*;
+import org.apache.zookeeper.server.quorum.*;
+
+public class ZooKeeperInstance
+{
+ protected final int zkPort;
+ protected final File tempDir;
+
+ protected ZooKeeperThread zookeeperThread = null;
+
+ public ZooKeeperInstance(int zkPort, File tempDir)
+ {
+ this.zkPort = zkPort;
+ this.tempDir = tempDir;
+ }
+
+ public void start()
+ throws Exception
+ {
+ Properties startupProperties = new Properties();
+ startupProperties.setProperty("tickTime","2000");
+ startupProperties.setProperty("dataDir",tempDir.toString());
+ startupProperties.setProperty("clientPort",Integer.toString(zkPort));
+
+ final QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
+ quorumConfiguration.parseProperties(startupProperties);
+
+ final ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumConfiguration);
+
+ zookeeperThread = new ZooKeeperThread(configuration);
+ zookeeperThread.start();
+ // We have no way of knowing whether zookeeper is alive or not, but the
+ // client is supposed to know about that.
+ }
+
+ public void stop()
+ throws Exception
+ {
+ while (true)
+ {
+ if (zookeeperThread == null)
+ break;
+ else if (!zookeeperThread.isAlive())
+ {
+ Throwable e = zookeeperThread.finishUp();
+ if (e != null)
+ {
+ if (e instanceof RuntimeException)
+ throw (RuntimeException)e;
+ else if (e instanceof Exception)
+ throw (Exception)e;
+ else if (e instanceof Error)
+ throw (Error)e;
+ }
+ zookeeperThread = null;
+ }
+ else
+ {
+ // This isn't the best way to kill zookeeper but it's the only way
+ // we've got.
+ zookeeperThread.interrupt();
+ Thread.sleep(1000L);
+ }
+ }
+ }
+
+ protected static class ZooKeeperThread extends Thread
+ {
+ protected final ServerConfig config;
+
+ protected Throwable exception = null;
+
+ public ZooKeeperThread(ServerConfig config)
+ {
+ this.config = config;
+ }
+
+ public void run()
+ {
+ try
+ {
+ ZooKeeperServerMain server = new ZooKeeperServerMain();
+ server.runFromConfig(config);
+ }
+ catch (IOException e)
+ {
+ // Ignore IOExceptions, since that seems to be normal when shutting
+ // down zookeeper via thread.interrupt()
+ }
+ catch (Throwable e)
+ {
+ exception = e;
+ }
+ }
+
+ public Throwable finishUp()
+ throws InterruptedException
+ {
+ join();
+ return exception;
+ }
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-13/framework/core/src/test/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperInstance.java
------------------------------------------------------------------------------
svn:keywords = Id