[infinispan-commits] Infinispan SVN: r2053 - in branches/4.1.x/demos/lucene-directory-demo: src/main/java/org/infinispan/lucenedemo and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Jul 19 07:31:55 EDT 2010


Author: sannegrinovero
Date: 2010-07-19 07:31:54 -0400 (Mon, 19 Jul 2010)
New Revision: 2053

Removed:
   branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java
Modified:
   branches/4.1.x/demos/lucene-directory-demo/
   branches/4.1.x/demos/lucene-directory-demo/pom.xml
   branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java
   branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java
   branches/4.1.x/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java
Log:
[ISPN-544] (Lucene Demo broke after Directory updates) - branch 4.1


Property changes on: branches/4.1.x/demos/lucene-directory-demo
___________________________________________________________________
Name: svn:ignore
   - target
.classpath
.project

   + target
.classpath
.project
.settings
test-output


Modified: branches/4.1.x/demos/lucene-directory-demo/pom.xml
===================================================================
--- branches/4.1.x/demos/lucene-directory-demo/pom.xml	2010-07-19 11:18:51 UTC (rev 2052)
+++ branches/4.1.x/demos/lucene-directory-demo/pom.xml	2010-07-19 11:31:54 UTC (rev 2053)
@@ -21,30 +21,6 @@
          <version>${project.version}</version>
       </dependency>
       <dependency>
-         <groupId>jboss.jbossts</groupId>
-         <artifactId>jbossjta</artifactId>
-         <version>4.9.0.GA</version>
-      </dependency>
-      <dependency>
-         <groupId>commons-logging</groupId>
-         <artifactId>commons-logging</artifactId>
-         <version>1.1</version>
-         <exclusions>
-         	<exclusion>
-         		<artifactId>servlet-api</artifactId>
-         		<groupId>javax.servlet</groupId>
-         	</exclusion>
-         	<exclusion>
-         		<artifactId>avalon-framework</artifactId>
-         		<groupId>avalon-framework</groupId>
-         	</exclusion>
-         	<exclusion>
-         		<artifactId>logkit</artifactId>
-         		<groupId>logkit</groupId>
-         	</exclusion>
-         </exclusions>
-      </dependency>
-      <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>infinispan-core</artifactId>
          <version>${project.version}</version>

Modified: branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java
===================================================================
--- branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java	2010-07-19 11:18:51 UTC (rev 2052)
+++ branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java	2010-07-19 11:31:54 UTC (rev 2053)
@@ -41,6 +41,7 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.util.Version;
 import org.infinispan.lucene.InfinispanDirectory;
 import org.infinispan.manager.EmbeddedCacheManager;
 import org.infinispan.remoting.transport.Address;
@@ -58,14 +59,10 @@
    private static final String MAIN_FIELD = "myField";
 
    /** The Analyzer used in all methods **/
-   private static final Analyzer analyzer = new StandardAnalyzer();
+   private static final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
 
    private InfinispanDirectory index;
    
-   public DemoActions() {
-      index = DirectoryFactory.getIndex("index");
-   }
-   
    public DemoActions(InfinispanDirectory index) {
       this.index = index;
    }
@@ -76,7 +73,7 @@
     */
    public List<String> listStoredValuesMatchingQuery(Query query) {
       try {
-         IndexSearcher searcher = new IndexSearcher(index);
+         IndexSearcher searcher = new IndexSearcher(index, true);
          TopDocs topDocs = searcher.search(query, null, 100);// demo limited to 100 documents!
          ScoreDoc[] scoreDocs = topDocs.scoreDocs;
          List<String> list = new ArrayList<String>();
@@ -126,7 +123,7 @@
     * @throws ParseException 
     */
    public Query parseQuery(String queryLine) throws ParseException {
-      QueryParser parser = new QueryParser(MAIN_FIELD, analyzer);
+      QueryParser parser = new QueryParser(Version.LUCENE_29, MAIN_FIELD, analyzer);
       return parser.parse(queryLine);
    }
 

Modified: branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java
===================================================================
--- branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java	2010-07-19 11:18:51 UTC (rev 2052)
+++ branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java	2010-07-19 11:31:54 UTC (rev 2053)
@@ -27,6 +27,9 @@
 
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
+import org.infinispan.Cache;
+import org.infinispan.lucene.InfinispanDirectory;
+import org.infinispan.manager.DefaultCacheManager;
 import org.infinispan.remoting.transport.Address;
 
 /**
@@ -39,12 +42,24 @@
  */
 public class DemoDriver implements Runnable {
    
-   private final DemoActions actions = new DemoActions();
+   private final DemoActions actions;
 
+   public DemoDriver(InfinispanDirectory infinispanDirectory) {
+      actions = new DemoActions(infinispanDirectory);
+   }
+
    public static void main(String[] args) throws IOException {
-      DemoDriver driver = new DemoDriver();
-      driver.run();
-      DirectoryFactory.close();
+      DefaultCacheManager cacheManager = new DefaultCacheManager("config-samples/lucene-demo-cache-config.xml");
+      cacheManager.start();
+      try {
+         Cache cache = cacheManager.getCache();
+         InfinispanDirectory directory = new InfinispanDirectory(cache);
+         DemoDriver driver = new DemoDriver(directory);
+         driver.run();
+      }
+      finally {
+         cacheManager.stop();
+      }
    }
 
    private void doQuery(Scanner scanner) throws IOException {

Deleted: branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java
===================================================================
--- branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java	2010-07-19 11:18:51 UTC (rev 2052)
+++ branches/4.1.x/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java	2010-07-19 11:31:54 UTC (rev 2053)
@@ -1,91 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.lucenedemo;
-
-import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.GlobalConfiguration;
-import org.infinispan.lucene.CacheKey;
-import org.infinispan.lucene.InfinispanDirectory;
-import org.infinispan.manager.CacheContainer;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
-import org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Utility to create an InfinispanDirectory for the demo.
- * 
- * @see org.infinispan.lucene.InfinispanDirectory
- * 
- * @author Sanne Grinovero
- * @since 4.0
- */
-public class DirectoryFactory {
-
-   public static final String CACHE_NAME_FOR_INDEXES = "LuceneIndex";
-
-   private static CacheContainer container = null;
-   private static final Map<String, InfinispanDirectory> directories = new HashMap<String, InfinispanDirectory>();
-
-   private static Cache<CacheKey, Object> buildCacheForIndexes() {
-      return getCacheManager().getCache(CACHE_NAME_FOR_INDEXES);
-   }
-
-   public static synchronized CacheContainer getCacheManager() {
-      if (container != null)
-         return container;
-      GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
-      gc.setClusterName("infinispan-lucene-demo-cluster");
-      gc.setTransportClass(JGroupsTransport.class.getName());
-
-      Configuration config = new Configuration();
-      config.setCacheMode(Configuration.CacheMode.DIST_SYNC);
-      config.setSyncCommitPhase(true);
-      config.setSyncRollbackPhase(true);
-      config.setTransactionManagerLookupClass(JBossStandaloneJTAManagerLookup.class.getName());
-      config.setNumOwners(2);
-      config.setL1CacheEnabled(true);
-      config.setInvocationBatchingEnabled(true);
-      config.setL1Lifespan(6000000);
-      container = new DefaultCacheManager(gc, config, false);
-      return container;
-   }
-
-   public static synchronized InfinispanDirectory getIndex(String indexName) {
-      InfinispanDirectory dir = directories.get(indexName);
-      if (dir == null) {
-         dir = new InfinispanDirectory(buildCacheForIndexes(), indexName);
-         directories.put(indexName, dir);
-      }
-      return dir;
-   }
-   
-   public static synchronized void close() {
-      if (container !=null) {
-         container.stop();
-      }
-   }
-
-}

Modified: branches/4.1.x/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java
===================================================================
--- branches/4.1.x/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java	2010-07-19 11:18:51 UTC (rev 2052)
+++ branches/4.1.x/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java	2010-07-19 11:31:54 UTC (rev 2053)
@@ -26,8 +26,10 @@
 
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
+import org.infinispan.Cache;
+import org.infinispan.lucene.CacheKey;
 import org.infinispan.lucene.InfinispanDirectory;
-import org.infinispan.lucenedemo.DirectoryFactory;
+import org.infinispan.manager.DefaultCacheManager;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -41,40 +43,44 @@
 @Test
 public class CacheConfigurationTest {
    
-   private InfinispanDirectory cacheForIndex1;
-   private InfinispanDirectory cacheForIndex2;
-   private InfinispanDirectory cacheForIndex3;
+   private DefaultCacheManager cacheManager1;
+   private DefaultCacheManager cacheManager2;
+   private InfinispanDirectory directoryNodeOne;
+   private InfinispanDirectory directoryNodeTwo;
 
    @BeforeClass
-   public void init() {
-      cacheForIndex1 = DirectoryFactory.getIndex("firstIndex");
-      cacheForIndex2 = DirectoryFactory.getIndex("firstIndex");
-      cacheForIndex3 = DirectoryFactory.getIndex("secondIndex");
+   public void init() throws IOException {
+      cacheManager1 = new DefaultCacheManager("config-samples/lucene-demo-cache-config.xml");
+      cacheManager1.start();
+      Cache<CacheKey, Object> cache1 = cacheManager1.getCache();
+      cache1.clear();
+      directoryNodeOne = new InfinispanDirectory(cache1);
+      cacheManager2 = new DefaultCacheManager("config-samples/lucene-demo-cache-config.xml");
+      cacheManager2.start();
+      Cache<CacheKey, Object> cache2 = cacheManager2.getCache();
+      cache2.clear();
+      directoryNodeTwo = new InfinispanDirectory(cache2);
    }
    
    @AfterClass
-   public void cleanup() {
-      DirectoryFactory.close();
+   public void cleanup() throws IOException {
+      directoryNodeOne.close();
+      directoryNodeTwo.close();
+      cacheManager1.stop();
+      cacheManager2.stop();
    }
 
    @Test
-   public void testCorrectCacheInstances() {
-      assert cacheForIndex1 != null;
-      assert cacheForIndex1 == cacheForIndex2;
-      assert cacheForIndex1 != cacheForIndex3;
-   }
-   
-   @Test
    public void inserting() throws IOException, ParseException {
-      DemoActions node1 = new DemoActions(cacheForIndex1);
-      DemoActions node2 = new DemoActions(cacheForIndex2);
+      DemoActions node1 = new DemoActions(directoryNodeOne);
+      DemoActions node2 = new DemoActions(directoryNodeTwo);
       node1.addNewDocument("hello?");
-      assert node1.listAllDocuments().size()==1;
+      assert node1.listAllDocuments().size() == 1;
       node1.addNewDocument("anybody there?");
-      assert node2.listAllDocuments().size()==2;
+      assert node2.listAllDocuments().size() == 2;
       Query query = node1.parseQuery("hello world");
       List<String> valuesMatchingQuery = node2.listStoredValuesMatchingQuery(query);
-      assert valuesMatchingQuery.size()==1;
+      assert valuesMatchingQuery.size() == 1;
       assert valuesMatchingQuery.get(0).equals("hello?");
    }
 



More information about the infinispan-commits mailing list