From 97d990c3b84511669ea5b43545c2a0d29d1f590d Mon Sep 17 00:00:00 2001 From: otrack <0track@gmail.com> Date: Thu, 7 Jun 2018 15:50:36 +0200 Subject: [PATCH] [FIX] skip locking interceptor [FIX] align emulation and remote test --- .../creson/utils/ConfigurationHelper.java | 27 +++++------------- .../org/infinispan/creson/test/Emulation.java | 9 +++--- .../infinispan/creson/test/RemoteTest.java | 28 +++++-------------- 3 files changed, 19 insertions(+), 45 deletions(-) diff --git a/server/src/main/java/org/infinispan/creson/utils/ConfigurationHelper.java b/server/src/main/java/org/infinispan/creson/utils/ConfigurationHelper.java index b884d49..b41c433 100644 --- a/server/src/main/java/org/infinispan/creson/utils/ConfigurationHelper.java +++ b/server/src/main/java/org/infinispan/creson/utils/ConfigurationHelper.java @@ -1,14 +1,15 @@ package org.infinispan.creson.utils; +import org.infinispan.commands.FlagAffectedCommand; import org.infinispan.commands.VisitableCommand; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.cache.Index; import org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder; import org.infinispan.context.InvocationContext; +import org.infinispan.context.impl.FlagBitSets; import org.infinispan.creson.Factory; import org.infinispan.creson.server.StateMachineInterceptor; -import org.infinispan.interceptors.AsyncInterceptor; import org.infinispan.interceptors.BaseAsyncInterceptor; import org.infinispan.interceptors.impl.CallInterceptor; import org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor; @@ -42,17 +43,8 @@ public static void installCreson( // SMR interceptor StateMachineInterceptor stateMachineInterceptor = new StateMachineInterceptor(); builder.customInterceptors().addInterceptor().before(CallInterceptor.class).interceptor(stateMachineInterceptor); - - // FIXME skip lock interceptor properly - AsyncInterceptor after = new BaseAsyncInterceptor() { - @Override - public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { - return invokeNext(ctx,command); - } - }; - SkipInterceptor before = new SkipInterceptor(after); - builder.customInterceptors().addInterceptor().before(NonTransactionalLockingInterceptor.class).interceptor(before); - builder.customInterceptors().addInterceptor().after(NonTransactionalLockingInterceptor.class).interceptor(after); + builder.customInterceptors().addInterceptor().before(NonTransactionalLockingInterceptor.class). + interceptor(new ForceSkipLockInterceptor()); // clustering builder.clustering() @@ -85,17 +77,12 @@ public Object visitCommand(InvocationContext ctx, VisitableCommand command) thro } - public static class SkipInterceptor extends BaseAsyncInterceptor{ - - AsyncInterceptor forward; - - public SkipInterceptor(AsyncInterceptor interceptor) { - this.forward = interceptor; - } + public static class ForceSkipLockInterceptor extends BaseAsyncInterceptor{ @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { - return forward.visitCommand(ctx,command); + ((FlagAffectedCommand) command).setFlagsBitSet(FlagBitSets.SKIP_LOCKING); + return invokeNext(ctx, command); } } diff --git a/server/src/test/java/org/infinispan/creson/test/Emulation.java b/server/src/test/java/org/infinispan/creson/test/Emulation.java index 4612de6..ef6844d 100644 --- a/server/src/test/java/org/infinispan/creson/test/Emulation.java +++ b/server/src/test/java/org/infinispan/creson/test/Emulation.java @@ -8,6 +8,7 @@ import org.infinispan.server.hotrod.HotRodServer; import org.infinispan.server.hotrod.test.HotRodTestingUtil; import org.infinispan.test.MultipleCacheManagersTest; +import org.infinispan.test.fwk.CleanupAfterTest; import org.infinispan.test.fwk.TransportFlags; import java.util.ArrayList; @@ -16,6 +17,7 @@ import static org.infinispan.creson.Factory.CRESON_CACHE_NAME; import static org.infinispan.creson.utils.ConfigurationHelper.installCreson; +@CleanupAfterTest public class Emulation extends MultipleCacheManagersTest { protected static final CacheMode CACHE_MODE = CacheMode.DIST_SYNC; @@ -26,7 +28,7 @@ public class Emulation extends MultipleCacheManagersTest { private static List remoteCacheManagers = new ArrayList<>(); protected int numberOfCaches(){ - return 1; + return 3; } private static List servers = new ArrayList<>(); @@ -37,7 +39,7 @@ private boolean addContainer() { // embedded cache manager TransportFlags flags = new TransportFlags(); flags.withFD(true).withMerge(true); - EmbeddedCacheManager cm = addClusterEnabledCacheManager(flags); + EmbeddedCacheManager cm = addClusterEnabledCacheManager(); installCreson( cm, CACHE_MODE, @@ -68,10 +70,9 @@ private boolean addContainer() { } @Override - protected void createCacheManagers() throws Throwable { + protected void createCacheManagers() { for (int i = 0; i< numberOfCaches(); i++) { addContainer(); - waitForClusterToForm(); System.out.println("Node " + remoteCacheManagers.get(i)+ " added."); } } diff --git a/server/src/test/java/org/infinispan/creson/test/RemoteTest.java b/server/src/test/java/org/infinispan/creson/test/RemoteTest.java index ff6fb8f..9685c3f 100644 --- a/server/src/test/java/org/infinispan/creson/test/RemoteTest.java +++ b/server/src/test/java/org/infinispan/creson/test/RemoteTest.java @@ -3,13 +3,12 @@ import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.commons.api.BasicCacheContainer; import org.infinispan.commons.marshall.Marshaller; -import org.infinispan.configuration.cache.CacheMode; -import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.creson.Factory; import org.infinispan.lifecycle.ComponentStatus; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.server.hotrod.HotRodServer; import org.infinispan.server.hotrod.test.HotRodTestingUtil; +import org.infinispan.test.fwk.TransportFlags; import org.testng.annotations.Test; import java.util.ArrayList; @@ -30,7 +29,6 @@ public class RemoteTest extends AbstractTest { private static List servers = new ArrayList<>(); private static List remoteCacheManagers = new ArrayList<>(); - private static ConfigurationBuilder defaultBuilder; @Override public BasicCacheContainer container(int i) { @@ -47,13 +45,16 @@ public boolean addContainer() { int index = servers.size(); // embedded cache manager - EmbeddedCacheManager cm = addClusterEnabledCacheManager(); + TransportFlags flags = new TransportFlags(); + flags.withFD(true).withMerge(true); + EmbeddedCacheManager cm = addClusterEnabledCacheManager(flags); installCreson( cm, CACHE_MODE, - REPLICATION_FACTOR, MAX_ENTRIES, + REPLICATION_FACTOR, + MAX_ENTRIES, PASSIVATION, - PERSISTENT_STORAGE_DIR + "/" + containers().size(), + PERSISTENT_STORAGE_DIR + "/" + index, true, false); waitForClusterToForm(CRESON_CACHE_NAME); @@ -104,7 +105,6 @@ public boolean deleteContainer() { @Override protected void createCacheManagers() throws Throwable { - createDefaultBuilder(); for (int j = 0; j < NMANAGERS; j++) { addContainer(); @@ -123,18 +123,4 @@ protected void createCacheManagers() throws Throwable { Factory.forCache(container(0).getCache(CRESON_CACHE_NAME), true); } - // Helpers - - private void createDefaultBuilder() { - defaultBuilder = getDefaultClusteredCacheConfig(CACHE_MODE, false); - defaultBuilder - .clustering().cacheMode(CacheMode.DIST_SYNC).hash().numOwners(REPLICATION_FACTOR) - .locking().useLockStriping(false) - .compatibility().enable(); - defaultBuilder.clustering().stateTransfer() - .awaitInitialTransfer(true) - .timeout(10000) - .fetchInMemoryState(true); - } - }