Repository: curator Updated Branches: refs/heads/CURATOR-490 1482370a1 -> 8c4095086
CURATOR-490 Abandon the Maven trick to copy the compatibility files from the curator-test module to this module. It's not working in IntelliJ nor Jenkins. Instead there's now a script, copyfiles.sh, that copies those files over. They shouldn't ever change again so this shouldn't be a problem. But if they do, they need to be copied and committed once more. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/8c409508 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/8c409508 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/8c409508 Branch: refs/heads/CURATOR-490 Commit: 8c4095086f961030e657c8273e9731d6c6064bfa Parents: 1482370 Author: randgalt <randg...@apache.org> Authored: Thu Dec 6 19:34:16 2018 -0500 Committer: randgalt <randg...@apache.org> Committed: Thu Dec 6 19:36:36 2018 -0500 ---------------------------------------------------------------------- curator-test-zk34/copyfiles.sh | 22 ++ curator-test-zk34/pom.xml | 25 +- .../test/compatibility/CuratorTestBase.java | 28 ++ .../test/compatibility/KillSession2.java | 40 +++ .../curator/test/compatibility/Timing2.java | 310 +++++++++++++++++++ .../compatibility/Zk35MethodInterceptor.java | 56 ++++ 6 files changed, 457 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/copyfiles.sh ---------------------------------------------------------------------- diff --git a/curator-test-zk34/copyfiles.sh b/curator-test-zk34/copyfiles.sh new file mode 100755 index 0000000..6526f9b --- /dev/null +++ b/curator-test-zk34/copyfiles.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# 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. +# + + +cp curator-test/src/main/java/org/apache/curator/test/compatibility/*.java curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/ http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/pom.xml ---------------------------------------------------------------------- diff --git a/curator-test-zk34/pom.xml b/curator-test-zk34/pom.xml index ff063d4..f9b711f 100644 --- a/curator-test-zk34/pom.xml +++ b/curator-test-zk34/pom.xml @@ -170,29 +170,6 @@ </dependenciesToScan> </configuration> </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <executions> - <execution> - <id>copy-curator-test-classes</id> - <phase>validate</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <outputDirectory>${basedir}/target/generated-test-sources/test-annotations/org/apache/curator/test/compatibility</outputDirectory> - <resources> - <resource> - <directory>../curator-test/src/main/java/org/apache/curator/test/compatibility</directory> - <filtering>false</filtering> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> </plugins> </build> -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/CuratorTestBase.java ---------------------------------------------------------------------- diff --git a/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/CuratorTestBase.java b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/CuratorTestBase.java new file mode 100644 index 0000000..a3c2a29 --- /dev/null +++ b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/CuratorTestBase.java @@ -0,0 +1,28 @@ +/** + * 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.curator.test.compatibility; + +import org.apache.curator.test.BaseClassForTests; +import org.testng.annotations.Listeners; + +@Listeners(Zk35MethodInterceptor.class) +public class CuratorTestBase extends BaseClassForTests +{ + protected final Timing2 timing = new Timing2(); +} http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/KillSession2.java ---------------------------------------------------------------------- diff --git a/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/KillSession2.java b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/KillSession2.java new file mode 100644 index 0000000..d747d3d --- /dev/null +++ b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/KillSession2.java @@ -0,0 +1,40 @@ +/** + * 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.curator.test.compatibility; + +import org.apache.curator.test.Compatibility; +import org.apache.zookeeper.ZooKeeper; + +/** + * <p> + * Utility to simulate a ZK session dying. + * </p> + */ +public class KillSession2 +{ + /** + * Kill the given ZK session + * + * @param client the client to kill + */ + public static void kill(ZooKeeper client) + { + Compatibility.injectSessionExpiration(client); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Timing2.java ---------------------------------------------------------------------- diff --git a/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Timing2.java b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Timing2.java new file mode 100644 index 0000000..5e0274c --- /dev/null +++ b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Timing2.java @@ -0,0 +1,310 @@ +/** + * 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.curator.test.compatibility; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Utility to get various testing times. + * + * Copied from the old Timing class which is now deprecated. Needed this to support ZK 3.4 compatibility + */ +public class Timing2 +{ + private final long value; + private final TimeUnit unit; + private final int waitingMultiple; + + private static final int DEFAULT_LOOP_QTY = 3; + private static final int DEFAULT_SECONDS = 10; + private static final int DEFAULT_WAITING_MULTIPLE = 5; + private static final double SESSION_MULTIPLE = 1.5; + private static final double SESSION_SLEEP_MULTIPLE = SESSION_MULTIPLE * 1.75; // has to be at least session + 2/3 of a session to account for missed heartbeat then session expiration + + /** + * Use the default base time + */ + public Timing2() + { + this(Integer.getInteger("timing-multiple", 1), getWaitingMultiple()); + } + + /** + * Use a multiple of the default base time + * + * @param multiple the multiple + */ + public Timing2(double multiple) + { + this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, getWaitingMultiple()); + } + + /** + * Use a multiple of the default base time + * + * @param multiple the multiple + * @param waitingMultiple multiple of main timing to use when waiting + */ + public Timing2(double multiple, int waitingMultiple) + { + this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, waitingMultiple); + } + + /** + * @param value base time + * @param unit base time unit + */ + public Timing2(long value, TimeUnit unit) + { + this(value, unit, getWaitingMultiple()); + } + + /** + * @param value base time + * @param unit base time unit + * @param waitingMultiple multiple of main timing to use when waiting + */ + public Timing2(long value, TimeUnit unit, int waitingMultiple) + { + this.value = value; + this.unit = unit; + this.waitingMultiple = waitingMultiple; + } + + /** + * Return the base time in milliseconds + * + * @return time ms + */ + public int milliseconds() + { + return (int)TimeUnit.MILLISECONDS.convert(value, unit); + } + + /** + * Return the base time in seconds + * + * @return time secs + */ + public int seconds() + { + return (int)value; + } + + /** + * Wait on the given latch + * + * @param latch latch to wait on + * @return result of {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)} + */ + public boolean awaitLatch(CountDownLatch latch) + { + Timing2 m = forWaiting(); + try + { + return latch.await(m.value, m.unit); + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + } + return false; + } + + /** + * Try to take an item from the given queue + * + * @param queue queue + * @return item + * @throws Exception interrupted or timed out + */ + public <T> T takeFromQueue(BlockingQueue<T> queue) throws Exception + { + Timing2 m = forWaiting(); + try + { + T value = queue.poll(m.value, m.unit); + if ( value == null ) + { + throw new TimeoutException("Timed out trying to take from queue"); + } + return value; + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + throw e; + } + } + + /** + * Wait on the given semaphore + * + * @param semaphore the semaphore + * @return result of {@link java.util.concurrent.Semaphore#tryAcquire()} + */ + public boolean acquireSemaphore(Semaphore semaphore) + { + Timing2 m = forWaiting(); + try + { + return semaphore.tryAcquire(m.value, m.unit); + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + } + return false; + } + + /** + * Wait on the given semaphore + * + * @param semaphore the semaphore + * @param n number of permits to acquire + * @return result of {@link java.util.concurrent.Semaphore#tryAcquire(int, long, java.util.concurrent.TimeUnit)} + */ + public boolean acquireSemaphore(Semaphore semaphore, int n) + { + Timing2 m = forWaiting(); + try + { + return semaphore.tryAcquire(n, m.value, m.unit); + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + } + return false; + } + + /** + * Return a new timing that is a multiple of the this timing + * + * @param n the multiple + * @return this timing times the multiple + */ + public Timing2 multiple(double n) + { + return new Timing2((int)(value * n), unit); + } + + /** + * Return a new timing that is a multiple of the this timing + * + * @param n the multiple + * @param waitingMultiple new waitingMultiple + * @return this timing times the multiple + */ + public Timing2 multiple(double n, int waitingMultiple) + { + return new Timing2((int)(value * n), unit, waitingMultiple); + } + + /** + * Return a new timing with the standard multiple for waiting on latches, etc. + * + * @return this timing multiplied + */ + @SuppressWarnings("PointlessArithmeticExpression") + public Timing2 forWaiting() + { + return multiple(waitingMultiple); + } + + /** + * Return a new timing with a multiple that ensures a ZK session timeout + * + * @return this timing multiplied + */ + public Timing2 forSessionSleep() + { + return multiple(SESSION_SLEEP_MULTIPLE, 1); + } + + /** + * Return a new timing with a multiple for sleeping a smaller amount of time + * + * @return this timing multiplied + */ + public Timing2 forSleepingABit() + { + return multiple(.25); + } + + /** + * Sleep for a small amount of time + * + * @throws InterruptedException if interrupted + */ + public void sleepABit() throws InterruptedException + { + forSleepingABit().sleep(); + } + + /** + * Sleep for a the full amount of time + * + * @throws InterruptedException if interrupted + */ + public void sleep() throws InterruptedException + { + unit.sleep(value); + } + + /** + * Return the value to use for ZK session timeout + * + * @return session timeout + */ + public int session() + { + return multiple(SESSION_MULTIPLE).milliseconds(); + } + + /** + * Return the value to use for ZK connection timeout + * + * @return connection timeout + */ + public int connection() + { + return milliseconds(); + } + + /** + * For timing loops, etc. the number of times to loop + * + * @return loop qty + */ + public int loopQty() + { + return DEFAULT_LOOP_QTY * Integer.getInteger("timing-loop-multiple", 1); + } + + private static Integer getWaitingMultiple() + { + return Integer.getInteger("timing-waiting-multiple", DEFAULT_WAITING_MULTIPLE); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/8c409508/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Zk35MethodInterceptor.java ---------------------------------------------------------------------- diff --git a/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Zk35MethodInterceptor.java b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Zk35MethodInterceptor.java new file mode 100644 index 0000000..8072b68 --- /dev/null +++ b/curator-test-zk34/src/test/java/org/apache/curator/test/compatibility/Zk35MethodInterceptor.java @@ -0,0 +1,56 @@ +/** + * 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.curator.test.compatibility; + +import org.apache.curator.test.Compatibility; +import org.testng.IMethodInstance; +import org.testng.IMethodInterceptor; +import org.testng.ITestContext; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Zk35MethodInterceptor implements IMethodInterceptor +{ + public static final String zk35Group = "zk35"; + + @Override + public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) + { + if ( !Compatibility.isZK34() ) + { + return methods; + } + + List<IMethodInstance> filteredMethods = new ArrayList<>(); + for ( IMethodInstance method : methods ) + { + if ( !isInGroup(method.getMethod().getGroups()) ) + { + filteredMethods.add(method); + } + } + return filteredMethods; + } + + private boolean isInGroup(String[] groups) + { + return (groups != null) && Arrays.asList(groups).contains(zk35Group); + } +}