[infinispan-commits] Infinispan SVN: r1535 - in trunk: demos and 13 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Feb 23 09:13:33 EST 2010


Author: sannegrinovero
Date: 2010-02-23 09:13:32 -0500 (Tue, 23 Feb 2010)
New Revision: 1535

Added:
   trunk/demos/lucene-directory-demo/
   trunk/demos/lucene-directory-demo/pom.xml
   trunk/demos/lucene-directory-demo/src/
   trunk/demos/lucene-directory-demo/src/main/
   trunk/demos/lucene-directory-demo/src/main/java/
   trunk/demos/lucene-directory-demo/src/main/java/org/
   trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/
   trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/
   trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java
   trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java
   trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java
   trunk/demos/lucene-directory-demo/src/main/resources/
   trunk/demos/lucene-directory-demo/src/main/resources/log4j.xml
   trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.bat
   trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.sh
   trunk/demos/lucene-directory-demo/src/test/
   trunk/demos/lucene-directory-demo/src/test/java/
   trunk/demos/lucene-directory-demo/src/test/java/org/
   trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/
   trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/
   trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java
   trunk/demos/lucene-directory-demo/src/test/resources/
Removed:
   trunk/demos/lucene-directory/
Modified:
   trunk/pom.xml
Log:
fixing lucene-directory-demo (name clash with lucene-demo module and wrong jboss-ts dependency)

Added: trunk/demos/lucene-directory-demo/pom.xml
===================================================================
--- trunk/demos/lucene-directory-demo/pom.xml	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/pom.xml	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,108 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+
+   <parent>
+      <groupId>org.infinispan</groupId>
+      <artifactId>infinispan-parent</artifactId>
+      <version>4.0.0-SNAPSHOT</version>
+      <relativePath>../../parent/pom.xml</relativePath>
+   </parent>
+
+   <artifactId>infinispan-lucene-demo</artifactId>
+   <version>4.0.0-SNAPSHOT</version>
+   <name>Infinispan Lucene Directory Demo</name>
+   <description>Infinispan - Lucene Directory Demo</description>
+
+   <dependencies>
+      <dependency>
+         <groupId>${project.groupId}</groupId>
+         <artifactId>infinispan-lucene-directory</artifactId>
+         <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>log4j</groupId>
+         <artifactId>log4j</artifactId>
+         <version>1.2.14</version>
+      </dependency>
+      <dependency>
+         <groupId>${project.groupId}</groupId>
+         <artifactId>infinispan-core</artifactId>
+         <version>${project.version}</version>
+         <type>test-jar</type>
+         <scope>test</scope>
+      </dependency>
+   </dependencies>
+
+   <build>
+      <plugins>
+      
+         <!-- Creates executable scripts -->
+         <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>appassembler-maven-plugin</artifactId>
+            <version>1.0</version>
+            <configuration>
+               <programs>
+                  <program>
+                     <mainClass>org.infinispan.lucenedemo.DemoDriver</mainClass>
+                     <name>lucene-demo</name>
+                  </program>
+               </programs>
+               <extraJvmArguments>-Djava.net.preferIPv4Stack=true -Dprotocol.stack=udp</extraJvmArguments>
+               <assembleDirectory>${project.build.directory}/assembly</assembleDirectory>
+            </configuration>
+         </plugin>
+         
+         <!-- Testing Configuration -->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <version>2.4.3</version>
+            <configuration>
+               <parallel>false</parallel>
+               <threadCount>1</threadCount>
+               <forkMode>once</forkMode>
+               <systemProperties>
+                  <property>
+                     <name>bind.address</name>
+                     <value>127.0.0.1</value>
+                  </property>
+                  <property>
+                     <name>java.net.preferIPv4Stack</name>
+                     <value>true</value>
+                  </property>
+               </systemProperties>
+               <trimStackTrace>false</trimStackTrace>
+            </configuration>
+         </plugin>
+         
+      </plugins>
+   </build>
+
+</project>

Added: trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoActions.java	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,139 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
+import org.infinispan.lucene.InfinispanDirectory;
+import org.infinispan.remoting.transport.Address;
+
+/**
+ * DemoActions does some basic operations on the Lucene index,
+ * to be used by DemoDriver to show base operations on Lucene.
+ * 
+ * @author Sanne Grinovero
+ * @since 4.0
+ */
+public class DemoActions {
+
+   /** The MAIN_FIELD */
+   private static final String MAIN_FIELD = "myField";
+
+   /** The Analyzer used in all methods **/
+   private static final Analyzer analyzer = new StandardAnalyzer();
+
+   private InfinispanDirectory index;
+   
+   public DemoActions() {
+      index = DirectoryFactory.getIndex("index");
+   }
+   
+   public DemoActions(InfinispanDirectory index) {
+      this.index = index;
+   }
+
+   /**
+    * Runs a Query and returns the stored field for each matching document
+    * @throws IOException
+    */
+   public List<String> listStoredValuesMatchingQuery(Query query) {
+      try {
+         IndexSearcher searcher = new IndexSearcher(index);
+         TopDocs topDocs = searcher.search(query, null, 100);// demo limited to 100 documents!
+         ScoreDoc[] scoreDocs = topDocs.scoreDocs;
+         List<String> list = new ArrayList<String>();
+         for (ScoreDoc sd : scoreDocs) {
+            Document doc = searcher.doc(sd.doc);
+            list.add(doc.get(MAIN_FIELD));
+         }
+         return list;
+      } catch (IOException ioe) {
+         // not recommended: in the simple demo this likely means that the index was not yet
+         // initialized, so returning empty list.
+         return Collections.EMPTY_LIST;
+      }
+   }
+   
+   /**
+    * Returns a list of the values of all stored fields
+    * @throws IOException 
+    */
+   public List<String> listAllDocuments() {
+      MatchAllDocsQuery q = new MatchAllDocsQuery();
+      return listStoredValuesMatchingQuery(q);
+   }
+
+   /**
+    * Creates a new document having just one field containing a string
+    * 
+    * @param line The text snippet to add
+    * @throws IOException
+    */
+   public void addNewDocument(String line) throws IOException {
+      IndexWriter iw = new IndexWriter(index, analyzer, MaxFieldLength.UNLIMITED);
+      try {
+         Document doc = new Document();
+         Field field = new Field(MAIN_FIELD, line, Store.YES, Index.ANALYZED);
+         doc.add(field);
+         iw.addDocument(doc);
+         iw.commit();
+      } finally {
+         iw.close();
+      }
+   }
+
+   /**
+    * Parses a query using the single field as default
+    * 
+    * @throws ParseException 
+    */
+   public Query parseQuery(String queryLine) throws ParseException {
+      QueryParser parser = new QueryParser(MAIN_FIELD, analyzer);
+      return parser.parse(queryLine);
+   }
+
+   /**
+    * Returns a list of Addresses of all members in the cluster 
+    */
+   public List<Address> listAllMembers() {
+      return index.getCache().getCacheManager().getMembers();
+   }
+
+}

Added: trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DemoDriver.java	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,148 @@
+/*
+ * 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 java.io.IOException;
+import java.util.List;
+import java.util.Scanner;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+import org.infinispan.remoting.transport.Address;
+
+/**
+ * DemoDriver is a console hello-world application to show the Lucene
+ * clustering capabilities.
+ * This class parses the user input and drives the actions implemented in DemoActions.
+ * 
+ * @author Sanne Grinovero
+ * @since 4.0
+ */
+public class DemoDriver implements Runnable {
+   
+   private final DemoActions actions = new DemoActions();
+
+   public static void main(String[] args) throws IOException {
+      DemoDriver driver = new DemoDriver();
+      driver.run();
+      DirectoryFactory.close();
+   }
+
+   private void doQuery(Scanner scanner) throws IOException {
+      scanner.nextLine();
+      Query query = null;
+      while (query == null) {
+         System.out.println("Enter a query:");
+         String queryLine = scanner.nextLine();
+         try {
+            query = actions.parseQuery(queryLine);
+         } catch (ParseException e) {
+            System.out.println("Wrong syntax in query: " + e.getMessage());
+            System.out.println("type it again: ");
+         }
+      }
+      List<String> listMatches = actions.listStoredValuesMatchingQuery(query);
+      printResult(listMatches);
+   }
+
+   private void insertNewText(Scanner scanner) throws IOException {
+      System.out.println("Enter string as new document:");
+      scanner.nextLine();
+      String line = scanner.nextLine();
+      actions.addNewDocument(line);
+   }
+
+   private void listAllDocuments() {
+      List<String> listMatches = actions.listAllDocuments();
+      printResult(listMatches);
+   }
+
+   private void listMembers() {
+      List<Address> members = actions.listAllMembers();
+      System.out.println("\tmembers:\t" + members);
+   }
+
+   private void showOptions() {
+      System.out.println(
+               "Options:\n" +
+               "\t[1] List cluster members\n" +
+               "\t[2] List all documents in index\n" +
+               "\t[3] insert new text\n" +
+               "\t[4] enter a query\n" +
+               "\t[5] quit");
+   }
+
+   private void printResult(List<String> storedValues) {
+      System.out.println("Matching documents:\n");
+      if (storedValues.isEmpty()) {
+         System.out.println("\tNo documents found.");
+      }
+      else {
+         int i = 0;
+         for (String value : storedValues) {
+            System.out.println(++i + "\t\"" + value + "\"");
+         }   
+      }
+   }
+
+   @Override
+   public void run() {
+      Scanner scanner = new Scanner(System.in);
+      while (true) {
+         showOptions();
+         boolean warned = false;
+         while (!scanner.hasNextInt()) {
+            if (!warned) {
+               System.out.println("Invalid option, try again:");
+               warned = true;
+            }
+            scanner.nextLine();
+         }
+         int result = scanner.nextInt();
+         try {
+            switch (result) {
+               case 1:
+                  listMembers();
+                  break;
+               case 2:
+                  listAllDocuments();
+                  break;
+               case 3:
+                  insertNewText(scanner);
+                  break;
+               case 4:
+                  doQuery(scanner);
+                  break;
+               case 5:
+                  System.out.println("Quit.");
+                  return;
+               default:
+                  System.out.println("Invalid option.");
+            }
+            System.out.println("");
+         } catch (Exception e) {
+            e.printStackTrace();
+         }
+      }
+   }
+
+}

Added: trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/java/org/infinispan/lucenedemo/DirectoryFactory.java	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,91 @@
+/*
+ * 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.CacheManager;
+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 CacheManager manager = 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 CacheManager getCacheManager() {
+      if (manager != null)
+         return manager;
+      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);
+      manager = new DefaultCacheManager(gc, config, false);
+      return manager;
+   }
+
+   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 (manager!=null) {
+         manager.stop();
+      }
+   }
+
+}

Added: trunk/demos/lucene-directory-demo/src/main/resources/log4j.xml
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/resources/log4j.xml	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/resources/log4j.xml	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!--
+   For more configuration information and examples see the Apache Log4j website: http://logging.apache.org/log4j/
+ -->
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <!-- A time/date based rolling appender -->
+   <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
+      <param name="File" value="infinispan.log"/>
+      <param name="Append" value="false"/>
+
+      <!-- Rollover at midnight each day -->
+      <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+      <param name="Threshold" value="TRACE"/>
+
+      <layout class="org.apache.log4j.PatternLayout">
+         <!-- The default pattern: Date Priority [Category] Message\n -->
+         <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
+      </layout>
+   </appender>
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Threshold" value="TRACE"/>
+      <param name="Target" value="System.out"/>
+
+      <layout class="org.apache.log4j.PatternLayout">
+         <!-- The default pattern: Date Priority [Category] Message\n -->
+         <param name="ConversionPattern" value="%d %-5p [%c{1}] (%t) %m%n"/>
+      </layout>
+   </appender>
+
+
+   <!-- ================ -->
+   <!-- Limit categories -->
+   <!-- ================ -->
+
+   <category name="org.infinispan">
+      <priority value="INFO"/>
+   </category>
+   
+   <category name="org.infinispan.lucene">
+      <priority value="INFO"/>
+   </category>
+
+   <category name="org.infinispan.factories">
+      <priority value="WARN"/>
+   </category>
+
+   <!-- ======================= -->
+   <!-- Setup the Root category -->
+   <!-- ======================= -->
+
+   <root>
+      <priority value="WARN"/>
+      <appender-ref ref="CONSOLE"/>
+      <appender-ref ref="FILE"/>
+   </root>
+
+</log4j:configuration>

Added: trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.bat
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.bat	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.bat	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,22 @@
+ at echo off
+
+:noenvreset
+set my_classpath=
+for /f "tokens=* delims=" %%f in ('dir /s /b /a-d "..\lib\*.jar"') do (
+		call set my_classpath=%%my_classpath%%;%%~f)
+	)
+set my_classpath=%my_classpath:~1%
+
+set my_classpath=%my_classpath%;..\infinispan-core.jar
+
+for /f "tokens=* delims=" %%f in ('dir /s /b /a-d "..\modules\lucene-directory-demo\*.jar"') do (
+                call set my_classpath=%%my_classpath%%;%%~f)
+        )
+set my_classpath=%my_classpath:~1%
+
+for /f "tokens=* delims=" %%f in ('dir /s /b /a-d "..\modules\lucene-directory-demo\lib\*.jar"') do (
+                call set my_classpath=%%my_classpath%%;%%~f)
+        )
+set my_classpath=%my_classpath:~1%
+
+java -cp %my_classpath% -Dbind.address=127.0.0.1 -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=..\etc\log4j.xml org.infinispan.lucenedemo.DemoDriver

Added: trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.sh
===================================================================
--- trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.sh	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/main/resources/runLuceneDemo.sh	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+DIRNAME=`dirname $0`
+
+# Setup ISPN_HOME
+if [ "x$ISPN_HOME" = "x" ]; then
+    # get the full path (without any relative bits)
+    ISPN_HOME=`cd $DIRNAME/..; pwd`
+fi
+export ISPN_HOME
+
+CP=${CP}:${ISPN_HOME}/infinispan-core.jar
+
+for i in ${ISPN_HOME}/lib/*.jar ; do
+   CP=${i}:${CP}
+done
+
+for i in ${ISPN_HOME}/modules/lucene-directory-demo/*.jar ; do
+   CP=${i}:${CP}
+done
+
+for i in ${ISPN_HOME}/modules/lucene-directory-demo/lib/*.jar ; do
+   CP=${i}:${CP}
+done
+
+JVM_PARAMS="${JVM_PARAMS} -Dbind.address=127.0.0.1 -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=file:${ISPN_HOME}/etc/log4j.xml"
+
+# Sample JPDA settings for remote socket debugging
+#JVM_PARAMS="$JVM_PARAMS -Xrunjdwp:transport=dt_socket,address=8686,server=y,suspend=n"
+
+java -cp ${CP} ${JVM_PARAMS} org.infinispan.lucenedemo.DemoDriver

Added: trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java
===================================================================
--- trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java	                        (rev 0)
+++ trunk/demos/lucene-directory-demo/src/test/java/org/infinispan/lucenedemo/CacheConfigurationTest.java	2010-02-23 14:13:32 UTC (rev 1535)
@@ -0,0 +1,81 @@
+/*
+ * 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 java.io.IOException;
+import java.util.List;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+import org.infinispan.lucene.InfinispanDirectory;
+import org.infinispan.lucenedemo.DirectoryFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * CacheCreationTest.
+ * 
+ * @author Sanne Grinovero
+ * @since 4.0
+ */
+ at Test
+public class CacheConfigurationTest {
+   
+   private InfinispanDirectory cacheForIndex1;
+   private InfinispanDirectory cacheForIndex2;
+   private InfinispanDirectory cacheForIndex3;
+
+   @BeforeClass
+   public void init() {
+      cacheForIndex1 = DirectoryFactory.getIndex("firstIndex");
+      cacheForIndex2 = DirectoryFactory.getIndex("firstIndex");
+      cacheForIndex3 = DirectoryFactory.getIndex("secondIndex");
+   }
+   
+   @AfterClass
+   public void cleanup() {
+      DirectoryFactory.close();
+   }
+
+   @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);
+      node1.addNewDocument("hello?");
+      assert node1.listAllDocuments().size()==1;
+      node1.addNewDocument("anybody there?");
+      assert node2.listAllDocuments().size()==2;
+      Query query = node1.parseQuery("hello world");
+      List<String> valuesMatchingQuery = node2.listStoredValuesMatchingQuery(query);
+      assert valuesMatchingQuery.size()==1;
+      assert valuesMatchingQuery.get(0).equals("hello?");
+   }
+
+}

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2010-02-23 10:25:43 UTC (rev 1534)
+++ trunk/pom.xml	2010-02-23 14:13:32 UTC (rev 1535)
@@ -34,7 +34,7 @@
       <module>demos/gui</module>
       <module>demos/ec2</module>
       <module>demos/directory</module>
-      <module>demos/lucene-directory</module>
+      <module>demos/lucene-directory-demo</module>
       <module>tools</module>
    </modules>
 



More information about the infinispan-commits mailing list