diff --git a/pom.xml b/pom.xml index 553659dc0e64a..28668daedd74f 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,7 @@ flexible messaging model and an intuitive client API. 2.3.1 1.5.0 5.2.2 + 3.1 0.6.1 @@ -1078,31 +1079,37 @@ flexible messaging model and an intuitive client API. opencensus-api ${opencensus.version} + io.opencensus opencensus-contrib-grpc-metrics ${opencensus.version} + org.elasticsearch.client elasticsearch-rest-high-level-client ${elasticsearch.version} + joda-time joda-time ${joda.version} + org.javassist javassist ${javassist.version} + net.jcip jcip-annotations ${jcip.version} + io.airlift aircompressor @@ -1114,6 +1121,13 @@ flexible messaging model and an intuitive client API. + + + org.objenesis + objenesis + ${objenesis.version} + + diff --git a/testmocks/pom.xml b/testmocks/pom.xml index a4dfd4b799b5b..2ae204454b2f6 100644 --- a/testmocks/pom.xml +++ b/testmocks/pom.xml @@ -53,6 +53,11 @@ org.testng testng + + + org.objenesis + objenesis + diff --git a/testmocks/src/main/java/org/apache/zookeeper/MockZooKeeper.java b/testmocks/src/main/java/org/apache/zookeeper/MockZooKeeper.java index 1d642d82741e7..a1a7c617ba7b2 100644 --- a/testmocks/src/main/java/org/apache/zookeeper/MockZooKeeper.java +++ b/testmocks/src/main/java/org/apache/zookeeper/MockZooKeeper.java @@ -25,8 +25,6 @@ import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; import io.netty.util.concurrent.DefaultThreadFactory; -import java.lang.reflect.Constructor; -import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.Set; @@ -35,7 +33,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; import java.util.function.BiPredicate; @@ -50,10 +47,12 @@ import org.apache.zookeeper.Watcher.Event.KeeperState; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; +import org.objenesis.Objenesis; +import org.objenesis.ObjenesisStd; +import org.objenesis.instantiator.ObjectInstantiator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@SuppressWarnings({ "deprecation", "restriction", "rawtypes" }) public class MockZooKeeper extends ZooKeeper { private TreeMap> tree; private SetMultimap watchers; @@ -67,6 +66,10 @@ public class MockZooKeeper extends ZooKeeper { private int readOpDelayMs; private ReentrantLock mutex; + + //see details of Objenesis caching - http://objenesis.org/details.html + //see supported jvms - https://github.com/easymock/objenesis/blob/master/SupportedJVMs.md + private static final Objenesis objenesis = new ObjenesisStd(); public enum Op { CREATE, GET, SET, GET_CHILDREN, DELETE, EXISTS, SYNC, @@ -92,11 +95,8 @@ public static MockZooKeeper newInstance(ExecutorService executor) { public static MockZooKeeper newInstance(ExecutorService executor, int readOpDelayMs) { try { - - sun.reflect.ReflectionFactory rf = sun.reflect.ReflectionFactory.getReflectionFactory(); - Constructor objDef = Object.class.getDeclaredConstructor(); - Constructor intConstr = rf.newConstructorForSerialization(MockZooKeeper.class, objDef); - MockZooKeeper zk = (MockZooKeeper) intConstr.newInstance(); + ObjectInstantiator mockZooKeeperInstantiator = objenesis.getInstantiatorOf(MockZooKeeper.class); + MockZooKeeper zk = (MockZooKeeper) mockZooKeeperInstantiator.newInstance(); zk.init(executor); zk.readOpDelayMs = readOpDelayMs; zk.mutex = new ReentrantLock(); @@ -290,7 +290,7 @@ public void getData(final String path, boolean watch, final DataCallback cb, fin cb.processResult(failure.get().intValue(), path, ctx, null, null); return; } else if (stopped) { - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null, null); return; } @@ -303,7 +303,7 @@ public void getData(final String path, boolean watch, final DataCallback cb, fin } if (value == null) { - cb.processResult(KeeperException.Code.NoNode, path, ctx, null, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null, null); } else { Stat stat = new Stat(); stat.setVersion(value.getRight()); @@ -356,13 +356,13 @@ public void getChildren(final String path, final Watcher watcher, final Children return; } else if (stopped) { mutex.unlock(); - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null); return; } if (!tree.containsKey(path)) { mutex.unlock(); - cb.processResult(KeeperException.Code.NoNode, path, ctx, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null); return; } @@ -475,11 +475,11 @@ public void getChildren(final String path, boolean watcher, final Children2Callb return; } else if (stopped) { mutex.unlock(); - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null, null); return; } else if (!tree.containsKey(path)) { mutex.unlock(); - cb.processResult(KeeperException.Code.NoNode, path, ctx, null, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null, null); return; } @@ -567,7 +567,7 @@ public void exists(String path, boolean watch, StatCallback cb, Object ctx) { return; } else if (stopped) { mutex.unlock(); - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null); return; } @@ -576,7 +576,7 @@ public void exists(String path, boolean watch, StatCallback cb, Object ctx) { cb.processResult(0, path, ctx, new Stat()); } else { mutex.unlock(); - cb.processResult(KeeperException.Code.NoNode, path, ctx, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null); } }); } @@ -592,7 +592,7 @@ public void exists(String path, Watcher watcher, StatCallback cb, Object ctx) { return; } else if (stopped) { mutex.unlock(); - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null); return; } @@ -605,7 +605,7 @@ public void exists(String path, Watcher watcher, StatCallback cb, Object ctx) { cb.processResult(0, path, ctx, new Stat()); } else { mutex.unlock(); - cb.processResult(KeeperException.Code.NoNode, path, ctx, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null); } }); } @@ -618,7 +618,7 @@ public void sync(String path, VoidCallback cb, Object ctx) { cb.processResult(failure.get().intValue(), path, ctx); return; } else if (stopped) { - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx); return; } @@ -675,7 +675,7 @@ public Stat setData(final String path, byte[] data, int version) throws KeeperEx @Override public void setData(final String path, final byte[] data, int version, final StatCallback cb, final Object ctx) { if (stopped) { - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null); return; } @@ -691,13 +691,13 @@ public void setData(final String path, final byte[] data, int version, final Sta return; } else if (stopped) { mutex.unlock(); - cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); + cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null); return; } if (!tree.containsKey(path)) { mutex.unlock(); - cb.processResult(KeeperException.Code.NoNode, path, ctx, null); + cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null); return; } @@ -707,7 +707,7 @@ public void setData(final String path, final byte[] data, int version, final Sta if (version != -1 && version != currentVersion) { log.debug("[{}] Current version: {} -- Expected: {}", path, currentVersion, version); mutex.unlock(); - cb.processResult(KeeperException.Code.BadVersion, path, ctx, null); + cb.processResult(KeeperException.Code.BADVERSION.intValue(), path, ctx, null); return; }