[infinispan-commits] Infinispan SVN: r2297 - in trunk: query/src/main/java/org/infinispan/query/backend and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Sep 2 05:24:22 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-09-02 05:24:21 -0400 (Thu, 02 Sep 2010)
New Revision: 2297

Added:
   trunk/query/src/test/java/org/infinispan/query/config/CacheModeTest.java
   trunk/query/src/test/java/org/infinispan/query/helper/TestQUeryHelperFactory.java
Modified:
   trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
   trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
Log:
[ISPN-624] (QueryInterceptor injected after LockingInterceptor - hence doesn't work with distributed mode)

Modified: trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-09-02 09:22:58 UTC (rev 2296)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-09-02 09:24:21 UTC (rev 2297)
@@ -156,6 +156,14 @@
       return newDefaultCacheManager(configuration, new Configuration(), enforceJmxDomain);
    }
 
+   public static EmbeddedCacheManager createCacheManager(Configuration.CacheMode mode, boolean indexing) {
+      GlobalConfiguration gc = mode.isClustered() ? GlobalConfiguration.getClusteredDefault() : GlobalConfiguration.getNonClusteredDefault();
+      Configuration c = new Configuration();
+      if (indexing) c.setIndexingEnabled(true);
+      c.setCacheMode(mode);
+      return createCacheManager(gc, c);
+   }
+
    /**
     * Creates a local cache manager and amends so that it won't conflict (e.g. jmx) with other managers whilst running
     * tests in parallel.  This is a non-transactional cache manager.

Modified: trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2010-09-02 09:22:58 UTC (rev 2296)
+++ trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2010-09-02 09:24:21 UTC (rev 2297)
@@ -30,6 +30,7 @@
 import org.infinispan.config.Configuration;
 import org.infinispan.factories.ComponentRegistry;
 import org.infinispan.factories.InterceptorChainFactory;
+import org.infinispan.interceptors.DistLockingInterceptor;
 import org.infinispan.interceptors.LockingInterceptor;
 import org.infinispan.interceptors.base.CommandInterceptor;
 import org.infinispan.util.logging.Log;
@@ -129,11 +130,11 @@
          try {
             if (cfg.isIndexLocalOnly()) {
                // Add a LocalQueryInterceptor to the chain
-               initComponents(LocalQueryInterceptor.class);
+               initComponents(cfg, LocalQueryInterceptor.class);
             } else {
                // We're indexing data even if it comes from other sources
                // Add in a QueryInterceptor to the chain
-               initComponents(QueryInterceptor.class);
+               initComponents(cfg, QueryInterceptor.class);
             }
          } catch (Exception e) {
             throw new CacheException("Unable to add interceptor", e);
@@ -176,7 +177,7 @@
    // Private method that adds the interceptor from the classname parameter.
 
 
-   private void initComponents(Class<? extends QueryInterceptor> interceptorClass)
+   private void initComponents(Configuration cfg, Class<? extends QueryInterceptor> interceptorClass)
          throws IllegalAccessException, InstantiationException {
 
       // get the component registry and then register the searchFactory.
@@ -189,8 +190,10 @@
       CommandInterceptor inter = icf.createInterceptor(interceptorClass);
       cr.registerComponent(inter, QueryInterceptor.class);
 
-      cache.getAdvancedCache().addInterceptorAfter(inter, LockingInterceptor.class);
-
+      cache.getAdvancedCache().addInterceptorAfter(inter,
+              cfg.getCacheMode().isDistributed() ?
+                      DistLockingInterceptor.class :
+                      LockingInterceptor.class);
    }
 
    //This is to check that both the @ProvidedId is present and the the @DocumentId is not present. This is because

Copied: trunk/query/src/test/java/org/infinispan/query/config/CacheModeTest.java (from rev 2295, branches/4.1.x/query/src/test/java/org/infinispan/query/config/CacheModeTest.java)
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/config/CacheModeTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/config/CacheModeTest.java	2010-09-02 09:24:21 UTC (rev 2297)
@@ -0,0 +1,53 @@
+package org.infinispan.query.config;
+
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.interceptors.base.CommandInterceptor;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.query.backend.QueryInterceptor;
+import org.infinispan.query.test.Person;
+import org.infinispan.test.AbstractInfinispanTest;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.Test;
+
+import java.util.Properties;
+
+ at Test(groups = "functional", testName = "query.config.CacheModeTest")
+public class CacheModeTest extends AbstractInfinispanTest {
+   public void testLocal() {
+      doTest(Configuration.CacheMode.LOCAL);
+   }
+
+   public void testReplicated() {
+      doTest(Configuration.CacheMode.REPL_SYNC);
+   }
+
+   public void testInvalidated() {
+      doTest(Configuration.CacheMode.INVALIDATION_SYNC);
+   }
+
+   public void testDistributed() {
+      doTest(Configuration.CacheMode.DIST_SYNC);
+   }
+
+   private void doTest(Configuration.CacheMode m) {
+      CacheContainer cc = null;
+
+      try {
+         cc = TestCacheManagerFactory.createCacheManager(m, true);
+         QueryHelper qh = new QueryHelper(cc.getCache(), new Properties(), Person.class);
+         boolean found = false;
+         for (CommandInterceptor i : cc.getCache().getAdvancedCache().getInterceptorChain()) {
+            System.out.println("  Testing " + i.getClass().getSimpleName());
+            if (i instanceof QueryInterceptor) found = true;
+         }
+         assert found : "Didn't find a query interceptor in the chain!!";
+      } finally {
+         TestingUtil.killCacheManagers(cc);
+      }      
+   }
+}

Added: trunk/query/src/test/java/org/infinispan/query/helper/TestQUeryHelperFactory.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/helper/TestQUeryHelperFactory.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/helper/TestQUeryHelperFactory.java	2010-09-02 09:24:21 UTC (rev 2297)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.query.helper;
+
+import org.infinispan.Cache;
+import org.infinispan.query.backend.QueryHelper;
+
+import java.util.Properties;
+
+/**
+ * Creates a test query helper
+ *
+ * @author Manik Surtani
+ * @since 4.0
+ */
+public class TestQueryHelperFactory {
+   public static QueryHelper createTestQueryHelperInstance(Cache<?, ?> cache, Class... classes) {
+      if (cache == null) throw new NullPointerException("Cache should not be null!");
+      Properties p = new Properties();
+      p.setProperty("hibernate.search.default.directory_provider", "org.hibernate.search.store.RAMDirectoryProvider");
+      return new QueryHelper(cache, p, classes);
+   }
+}



More information about the infinispan-commits mailing list