Repository: curator Updated Branches: refs/heads/CURATOR-397 11cb97036 -> 50b054cc6
removed integrated caching for now - it was getting too cumbersome. I have some other ideas Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/50b054cc Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/50b054cc Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/50b054cc Branch: refs/heads/CURATOR-397 Commit: 50b054cc6af009c721e859398efcef5023f3cd3b Parents: 11cb970 Author: randgalt <randg...@apache.org> Authored: Sun Apr 30 14:02:07 2017 -0500 Committer: randgalt <randg...@apache.org> Committed: Sun Apr 30 14:02:07 2017 -0500 ---------------------------------------------------------------------- .../async/modeled/ModeledCuratorFramework.java | 10 -- .../modeled/ModeledCuratorFrameworkBuilder.java | 23 +-- .../x/async/modeled/caching/Caching.java | 44 ----- .../x/async/modeled/caching/CachingOption.java | 28 --- .../x/async/modeled/details/CachingImpl.java | 173 ------------------- .../details/ModeledCuratorFrameworkImpl.java | 100 +---------- .../TestCachedModeledCuratorFramework.java | 95 ---------- 7 files changed, 8 insertions(+), 465 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java index a53eb77..f4eed45 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java @@ -22,7 +22,6 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.transaction.CuratorOp; import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.curator.x.async.AsyncStage; -import org.apache.curator.x.async.modeled.caching.Caching; import org.apache.zookeeper.data.Stat; import java.util.List; @@ -61,15 +60,6 @@ public interface ModeledCuratorFramework<T> CuratorFramework unwrap(); /** - * Return the caching APIs. Only valid if {@link ModeledCuratorFrameworkBuilder#cached()} or - * {@link ModeledCuratorFrameworkBuilder#cached(java.util.Set)} was called when building the instance. - * - * @return caching APIs - * @throws java.lang.IllegalStateException if caching was not enabled when building the instance - */ - Caching<T> caching(); - - /** * Return a new Modeled Curator instance with all the same options but applying to the given child node of this Modeled Curator's * path. E.g. if this Modeled Curator instance applies to "/a/b", calling <code>modeled.at("c")</code> returns an instance that applies to * "/a/b/c". http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java index 1ed4b8d..76926e9 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java @@ -22,12 +22,9 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.CuratorEvent; import org.apache.curator.framework.api.UnhandledErrorListener; import org.apache.curator.x.async.WatchMode; -import org.apache.curator.x.async.modeled.caching.CachingOption; import org.apache.curator.x.async.modeled.details.ModeledCuratorFrameworkImpl; import org.apache.zookeeper.WatchedEvent; -import java.util.Collections; import java.util.Objects; -import java.util.Set; import java.util.function.UnaryOperator; public class ModeledCuratorFrameworkBuilder<T> @@ -38,8 +35,6 @@ public class ModeledCuratorFrameworkBuilder<T> private UnaryOperator<WatchedEvent> watcherFilter; private UnhandledErrorListener unhandledErrorListener; private UnaryOperator<CuratorEvent> resultFilter; - private Set<CachingOption> cachingOptions = Collections.emptySet(); - private boolean cached = false; /** * Build a new ModeledCuratorFramework instance @@ -54,9 +49,7 @@ public class ModeledCuratorFrameworkBuilder<T> watchMode, watcherFilter, unhandledErrorListener, - resultFilter, - cachingOptions, - cached + resultFilter ); } @@ -125,20 +118,6 @@ public class ModeledCuratorFrameworkBuilder<T> return this; } - public ModeledCuratorFrameworkBuilder<T> cached() - { - this.cachingOptions = Collections.emptySet(); - this.cached = true; - return this; - } - - public ModeledCuratorFrameworkBuilder<T> cached(Set<CachingOption> cachingOptions) - { - this.cachingOptions = Objects.requireNonNull(cachingOptions, "cachingOptions cannot be null"); - this.cached = true; - return this; - } - ModeledCuratorFrameworkBuilder(CuratorFramework client, CuratorModelSpec<T> model) { this.client = Objects.requireNonNull(client, "client cannot be null"); http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/Caching.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/Caching.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/Caching.java deleted file mode 100644 index 6bd460e..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/Caching.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.x.async.modeled.caching; - -import org.apache.curator.framework.listen.Listenable; -import org.apache.curator.x.async.modeled.recipes.ModeledCacheListener; -import java.io.Closeable; - -public interface Caching<T> extends Closeable -{ - /** - * Forwards to the internal cache's start method. Not idempotent. - */ - void start(); - - /** - * Forwards to the internal cache's close method. - */ - @Override - void close(); - - /** - * Return the listener container so that you can add/remove listeners - * - * @return listener container - */ - Listenable<ModeledCacheListener<T>> getListenable(); -} http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/CachingOption.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/CachingOption.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/CachingOption.java deleted file mode 100644 index 6611301..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/caching/CachingOption.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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.x.async.modeled.caching; - -public enum CachingOption -{ - metaDataOnly, - - dirtyReads, - - createParentNodes -} http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachingImpl.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachingImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachingImpl.java deleted file mode 100644 index 01566d1..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachingImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * 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.x.async.modeled.details; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.listen.Listenable; -import org.apache.curator.framework.recipes.cache.TreeCache; -import org.apache.curator.x.async.api.CreateOption; -import org.apache.curator.x.async.modeled.ModelSerializer; -import org.apache.curator.x.async.modeled.ZPath; -import org.apache.curator.x.async.modeled.caching.Caching; -import org.apache.curator.x.async.modeled.caching.CachingOption; -import org.apache.curator.x.async.modeled.recipes.ModeledCacheEvent; -import org.apache.curator.x.async.modeled.recipes.ModeledCacheListener; -import org.apache.curator.x.async.modeled.recipes.ModeledCachedNode; -import org.apache.curator.x.async.modeled.recipes.ModeledTreeCache; -import org.apache.zookeeper.data.Stat; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; - -class CachingImpl<T> implements Caching<T>, ModeledCacheListener<T> -{ - private final ModeledTreeCache<T> treeCache; - private final AtomicLong dirtyZxid = new AtomicLong(-1); - private final ZPath path; - private final boolean dirtyReads; - - CachingImpl(CuratorFramework client, ModelSerializer<T> serializer, ZPath path, Set<CachingOption> cachingOptions, Set<CreateOption> createOptions) - { - this.path = path; - TreeCache.Builder builder = TreeCache.newBuilder(client, path.fullPath()); - builder = builder.setCacheData(!cachingOptions.contains(CachingOption.metaDataOnly)).setCreateParentNodes(cachingOptions.contains(CachingOption.createParentNodes)); - if ( ModeledCuratorFrameworkImpl.isCompressed(createOptions) ) - { - builder = builder.setDataIsCompressed(true); - } - TreeCache cache = builder.build(); - treeCache = ModeledTreeCache.wrap(cache, serializer); - - treeCache.getListenable().addListener(this); - - dirtyReads = cachingOptions.contains(CachingOption.dirtyReads); - } - - CachingImpl<T> at(String child) - { - return new CachingImpl<>(treeCache, path.at(child), dirtyReads); - } - - @Override - public void start() - { - treeCache.start(); - } - - @Override - public void close() - { - treeCache.close(); - } - - @Override - public Listenable<ModeledCacheListener<T>> getListenable() - { - return treeCache.getListenable(); - } - - @Override - public void event(ModeledCacheEvent<T> event) - { - switch ( event.getType() ) - { - case NODE_ADDED: - case NODE_UPDATED: - case NODE_REMOVED: - { - ModeledCachedNode<T> node = event.getNode(); - Stat stat = (node != null) ? node.getStat() : null; - long mzxid = (stat != null) ? stat.getMzxid() : -1; - updateDirtyZxid(mzxid); - break; - } - - case CONNECTION_RECONNECTED: - { - dirtyZxid.set(-1); - break; - } - } - } - - long getCurrentZxid() - { - return treeCache.getCurrentData(path).map(cache -> (cache.getStat() != null) ? cache.getStat().getMzxid() : -1).orElse(-1L); - } - - void markDirty(long zxid) - { - if ( !dirtyReads && (zxid >= 0) ) - { - long currentDirtyZxid = dirtyZxid.get(); - if ( zxid > currentDirtyZxid ) - { - dirtyZxid.compareAndSet(currentDirtyZxid, zxid); - } - } - } - - ModeledTreeCache<T> getCache() - { - return treeCache; - } - - ModeledCachedNode<T> getCacheIf() - { - Optional<ModeledCachedNode<T>> currentData = treeCache.getCurrentData(path); - return currentData.map(this::getDataWithDirtyCheck).orElse(null); - } - - private ModeledCachedNode<T> getDataWithDirtyCheck(ModeledCachedNode<T> data) - { - Stat stat = data.getStat(); - if ( stat != null ) - { - if ( stat.getMzxid() > dirtyZxid.get() ) - { - return data; - } - } - return null; - } - - private void updateDirtyZxid(long newZxid) - { - if ( dirtyReads ) - { - return; - } - - long currentDirtyZxid = dirtyZxid.get(); - if ( (currentDirtyZxid >= 0) && (newZxid > currentDirtyZxid) ) - { - if ( !dirtyZxid.compareAndSet(currentDirtyZxid, -1) ) - { - updateDirtyZxid(newZxid); - } - } - } - - private CachingImpl(ModeledTreeCache<T> treeCache, ZPath path, boolean dirtyReads) - { - this.treeCache = treeCache; - this.path = path; - this.dirtyReads = dirtyReads; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java index b58e1e5..841c64f 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java @@ -19,7 +19,6 @@ package org.apache.curator.x.async.modeled.details; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.CuratorEvent; import org.apache.curator.framework.api.UnhandledErrorListener; @@ -37,13 +36,9 @@ import org.apache.curator.x.async.api.WatchableAsyncCuratorFramework; import org.apache.curator.x.async.modeled.CuratorModelSpec; import org.apache.curator.x.async.modeled.ModeledCuratorFramework; import org.apache.curator.x.async.modeled.ZPath; -import org.apache.curator.x.async.modeled.caching.Caching; -import org.apache.curator.x.async.modeled.caching.CachingOption; -import org.apache.curator.x.async.modeled.recipes.ModeledCachedNode; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.DataTree; import java.util.List; import java.util.Objects; import java.util.Set; @@ -61,9 +56,8 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T private final UnhandledErrorListener unhandledErrorListener; private final UnaryOperator<CuratorEvent> resultFilter; private final AsyncCuratorFrameworkDsl dslClient; - private final CachingImpl<T> caching; - public static <T> ModeledCuratorFrameworkImpl<T> build(CuratorFramework client, CuratorModelSpec<T> model, WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter, UnhandledErrorListener unhandledErrorListener, UnaryOperator<CuratorEvent> resultFilter, Set<CachingOption> cachingOptions, boolean cached) + public static <T> ModeledCuratorFrameworkImpl<T> build(CuratorFramework client, CuratorModelSpec<T> model, WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter, UnhandledErrorListener unhandledErrorListener, UnaryOperator<CuratorEvent> resultFilter) { boolean localIsWatched = (watchMode != null); @@ -76,8 +70,6 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T AsyncCuratorFrameworkDsl dslClient = asyncClient.with(watchMode, unhandledErrorListener, resultFilter, watcherFilter); WatchableAsyncCuratorFramework watchableClient = localIsWatched ? dslClient.watched() : dslClient; - CachingImpl<T> caching = cached ? new CachingImpl<>(client, model.serializer(), model.path(), cachingOptions, model.createOptions()) : null; - return new ModeledCuratorFrameworkImpl<>( asyncClient, dslClient, @@ -86,12 +78,11 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T watchMode, watcherFilter, unhandledErrorListener, - resultFilter, - caching + resultFilter ); } - private ModeledCuratorFrameworkImpl(AsyncCuratorFramework client, AsyncCuratorFrameworkDsl dslClient, WatchableAsyncCuratorFramework watchableClient, CuratorModelSpec<T> modelSpec, WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter, UnhandledErrorListener unhandledErrorListener, UnaryOperator<CuratorEvent> resultFilter, CachingImpl<T> caching) + private ModeledCuratorFrameworkImpl(AsyncCuratorFramework client, AsyncCuratorFrameworkDsl dslClient, WatchableAsyncCuratorFramework watchableClient, CuratorModelSpec<T> modelSpec, WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter, UnhandledErrorListener unhandledErrorListener, UnaryOperator<CuratorEvent> resultFilter) { this.client = client; this.dslClient = dslClient; @@ -101,7 +92,6 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T this.watcherFilter = watcherFilter; this.unhandledErrorListener = unhandledErrorListener; this.resultFilter = resultFilter; - this.caching = caching; } @Override @@ -111,13 +101,6 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T } @Override - public Caching<T> caching() - { - Preconditions.checkState(caching != null, "Caching is not enabled for this instance"); - return caching; - } - - @Override public AsyncStage<String> set(T item) { return set(item, null); @@ -126,12 +109,8 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T @Override public AsyncStage<String> set(T item, Stat storingStatIn) { - long dirtyZxid = getDirtyZxid(); byte[] bytes = modelSpec.serializer().serialize(item); - AsyncStage<String> asyncStage = dslClient.create().withOptions(modelSpec.createOptions(), modelSpec.createMode(), fixAclList(modelSpec.aclList()), storingStatIn).forPath(modelSpec.path().fullPath(), bytes); - ModelStage<String> modelStage = new ModelStage<>(); - markDirtyCompleter(dirtyZxid, asyncStage, modelStage); - return modelStage; + return dslClient.create().withOptions(modelSpec.createOptions(), modelSpec.createMode(), fixAclList(modelSpec.aclList()), storingStatIn).forPath(modelSpec.path().fullPath(), bytes); } private List<ACL> fixAclList(List<ACL> aclList) @@ -151,23 +130,6 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T @Override public AsyncStage<T> read(Stat storingStatIn) { - ModeledCachedNode<T> node = getCached(); - if ( node != null ) - { - if ( node.getModel() != null ) - { - if ( storingStatIn != null ) - { - DataTree.copyStat(node.getStat(), storingStatIn); - } - if ( debugCachedReadCount != null ) - { - debugCachedReadCount.incrementAndGet(); - } - return new ModelStage<>(node.getModel()); - } - } - AsyncPathable<AsyncStage<byte[]>> next; if ( isCompressed() ) { @@ -208,28 +170,14 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T @Override public AsyncStage<Stat> update(T item, int version) { - long dirtyZxid = getDirtyZxid(); byte[] bytes = modelSpec.serializer().serialize(item); AsyncPathAndBytesable<AsyncStage<Stat>> next = isCompressed() ? dslClient.setData().compressedWithVersion(version) : dslClient.setData(); - AsyncStage<Stat> asyncStage = next.forPath(modelSpec.path().fullPath(), bytes); - ModelStage<Stat> modelStage = new ModelStage<>(asyncStage.event()); - markDirtyCompleter(dirtyZxid, asyncStage, modelStage); - return modelStage; + return next.forPath(modelSpec.path().fullPath(), bytes); } @Override public AsyncStage<Stat> checkExists() { - ModeledCachedNode<T> node = getCached(); - if ( node != null ) - { - AsyncStage<Stat> result = new ModelStage<>(node.getStat()); - if ( debugCachedReadCount != null ) - { - debugCachedReadCount.incrementAndGet(); - } - return result; - } return watchableClient.checkExists().forPath(modelSpec.path().fullPath()); } @@ -242,11 +190,7 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T @Override public AsyncStage<Void> delete(int version) { - long dirtyZxid = getDirtyZxid(); - AsyncStage<Void> asyncStage = dslClient.delete().withVersion(-1).forPath(modelSpec.path().fullPath()); - ModelStage<Void> modelStage = new ModelStage<>(asyncStage.event()); - markDirtyCompleter(dirtyZxid, asyncStage, modelStage); - return modelStage; + return dslClient.delete().withVersion(-1).forPath(modelSpec.path().fullPath()); } @Override @@ -271,7 +215,6 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T public ModeledCuratorFramework<T> at(String child) { CuratorModelSpec<T> childModel = modelSpec.at(child); - CachingImpl<T> newCaching = (caching != null) ? caching.at(child) : null; return new ModeledCuratorFrameworkImpl<>( client, dslClient, @@ -280,8 +223,7 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T watchMode, watcherFilter, unhandledErrorListener, - resultFilter, - newCaching + resultFilter ); } @@ -346,36 +288,8 @@ public class ModeledCuratorFrameworkImpl<T> implements ModeledCuratorFramework<T return client.transaction().forOperations(operations); } - private <U> void markDirtyCompleter(long dirtyZxid, AsyncStage<U> asyncStage, ModelStage<U> modelStage) - { - asyncStage.whenComplete((value, e) -> { - if ( e != null ) - { - modelStage.completeExceptionally(e); - } - else - { - if ( caching != null ) - { - caching.markDirty(dirtyZxid); - } - modelStage.complete(value); - } - }); - } - private boolean isCompressed() { return modelSpec.createOptions().contains(CreateOption.compress); } - - private ModeledCachedNode<T> getCached() - { - return (caching != null) ? caching.getCacheIf() : null; - } - - private long getDirtyZxid() - { - return (caching != null) ? caching.getCurrentZxid() : -1L; - } } http://git-wip-us.apache.org/repos/asf/curator/blob/50b054cc/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/details/TestCachedModeledCuratorFramework.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/details/TestCachedModeledCuratorFramework.java b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/details/TestCachedModeledCuratorFramework.java deleted file mode 100644 index 4954ae2..0000000 --- a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/details/TestCachedModeledCuratorFramework.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * 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.x.async.modeled.details; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.RetryOneTime; -import org.apache.curator.utils.CloseableUtils; -import org.apache.curator.x.async.CompletableBaseClassForTests; -import org.apache.curator.x.async.modeled.CuratorModelSpec; -import org.apache.curator.x.async.modeled.JacksonModelSerializer; -import org.apache.curator.x.async.modeled.ModelSerializer; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; -import org.apache.curator.x.async.modeled.ZPath; -import org.apache.curator.x.async.modeled.models.TestSimpleModel; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import java.util.concurrent.atomic.AtomicInteger; - -public class TestCachedModeledCuratorFramework extends CompletableBaseClassForTests -{ - private static final ZPath path = ZPath.parse("/test/path"); - private CuratorFramework rawClient; - private ModeledCuratorFramework<TestSimpleModel> client; - - @BeforeMethod - @Override - public void setup() throws Exception - { - super.setup(); - - rawClient = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); - rawClient.start(); - - ModelSerializer<TestSimpleModel> serializer = new JacksonModelSerializer<>(TestSimpleModel.class); - client = ModeledCuratorFramework.builder(rawClient, CuratorModelSpec.builder(path, serializer).build()).cached().build(); - } - - @AfterMethod - @Override - public void teardown() throws Exception - { - CloseableUtils.closeQuietly(rawClient); - super.teardown(); - } - - @Test - public void testBasic() throws InterruptedException - { - client.caching().start(); - - AtomicInteger counter = new AtomicInteger(); - ((ModeledCuratorFrameworkImpl)client).debugCachedReadCount = counter; - - complete(client.read()); - Assert.assertEquals(counter.get(), 0); - - complete(client.set(new TestSimpleModel("test", 10))); - Assert.assertEquals(counter.get(), 0); - - timing.sleepABit(); - - complete(client.read()); - Assert.assertEquals(counter.get(), 1); - counter.set(0); - - complete(client.set(new TestSimpleModel("test2", 20))); - Assert.assertEquals(counter.get(), 0); - - timing.sleepABit(); - - complete(client.read(), (model, e) -> Assert.assertEquals(model, new TestSimpleModel("test2", 20))); - Assert.assertEquals(counter.get(), 1); - - client.caching().close(); - } -}