lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r412574 [4/4] - in /lucene/java/trunk: ./ contrib/gdata-server/ contrib/gdata-server/lib/ contrib/gdata-server/src/ contrib/gdata-server/src/java/ contrib/gdata-server/src/java/org/ contrib/gdata-server/src/java/org/apache/ contrib/gdata-se...
Date Wed, 07 Jun 2006 21:56:29 GMT
Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestGDataEntityBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestGDataEntityBuilder.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestGDataEntityBuilder.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestGDataEntityBuilder.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,98 @@
+/** 
+ * Copyright 2004 The Apache Software Foundation 
+ * 
+ * Licensed 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.lucene.gdata.server.registry; 
+ 
+import java.io.File; 
+import java.io.FileReader; 
+import java.io.IOException; 
+import java.io.Reader; 
+ 
+import junit.framework.TestCase; 
+ 
+import org.apache.lucene.gdata.server.FeedNotFoundException; 
+import org.apache.lucene.gdata.server.GDataEntityBuilder; 
+ 
+import com.google.gdata.data.BaseEntry; 
+import com.google.gdata.data.BaseFeed; 
+import com.google.gdata.data.Entry; 
+import com.google.gdata.data.ExtensionProfile; 
+import com.google.gdata.data.Feed; 
+import com.google.gdata.util.ParseException; 
+ 
+/** 
+ * @author Simon Willnauer 
+ * 
+ */ 
+public class TestGDataEntityBuilder extends TestCase { 
+    private static File incomingFeed = new File("src/test/org/apache/lucene/gdata/server/registry/TestEntityBuilderIncomingFeed.xml");

+    private static File incomingEntry = new File("src/test/org/apache/lucene/gdata/server/registry/TestEntityBuilderIncomingEntry.xml");

+    private static String feedTitleFromXML = "Simon Willnauer"; 
+    private static String entrySummaryFromXML = "When: 2006-12-23 to 2006-12-31 America/Los_Angeles";

+    private static GDataServerRegistry reg = GDataServerRegistry.getRegistry(); 
+    private Reader reader;  
+    private static String feedID = "myFeed"; 
+    private ExtensionProfile profile; 
+    private static Class feedType = Feed.class; 
+     
+     
+    /** 
+     * @see junit.framework.TestCase#setUp() 
+     */ 
+    @Override 
+    protected void setUp() throws Exception { 
+        FeedInstanceConfigurator config = new FeedInstanceConfigurator(); 
+        config.setFeedId(feedID); 
+        config.setFeedType(feedType); 
+        this.profile = new ExtensionProfile(); 
+        reg.registerFeed(config); 
+    } 
+ 
+    /** 
+     * @see junit.framework.TestCase#tearDown() 
+     */ 
+    @Override 
+    protected void tearDown() throws Exception { 
+        reg.flushRegistry(); 
+        this.reader = null; 
+    } 
+ 
+    /** 
+     * Test method for 'org.apache.lucene.gdata.data.GDataEntityBuilder.buildFeed(String,
Reader)' 
+     */ 
+    public void testBuildFeedStringReader() throws FeedNotFoundException, ParseException,
IOException { 
+        this.reader = new FileReader(incomingFeed); 
+        BaseFeed feed = GDataEntityBuilder.buildFeed(feedID,this.reader,this.profile); 
+        assertNotNull(feed); 
+        assertEquals("feed title",feed.getTitle().getPlainText(), feedTitleFromXML); 
+        assertTrue( feed instanceof Feed); 
+         
+    } 
+ 
+    /* 
+     * Test method for 'org.apache.lucene.gdata.data.GDataEntityBuilder.buildEntry(String,
Reader)' 
+     */ 
+    public void testBuildEntryStringReader() throws FeedNotFoundException, ParseException,
IOException { 
+        this.reader = new FileReader(incomingEntry); 
+        BaseEntry entry = GDataEntityBuilder.buildEntry(feedID,this.reader,this.profile);

+        assertNotNull(entry); 
+        assertEquals("entry summary",entry.getSummary().getPlainText(),entrySummaryFromXML);

+        assertTrue(entry instanceof Entry); 
+         
+    } 
+     
+     
+ 
+} 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/TestAbstractGdataServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/TestAbstractGdataServlet.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/TestAbstractGdataServlet.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/TestAbstractGdataServlet.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,282 @@
+package org.apache.lucene.gdata.servlet; 
+ 
+import java.io.IOException; 
+ 
+import javax.servlet.ServletException; 
+import javax.servlet.http.HttpServletRequest; 
+import javax.servlet.http.HttpServletResponse; 
+ 
+import org.easymock.MockControl; 
+ 
+import junit.framework.TestCase; 
+ 
+/** 
+ * @author Simon Willnauer 
+ * 
+ */ 
+public class TestAbstractGdataServlet extends TestCase { 
+    private static final String METHOD_DELETE = "DELETE"; 
+ 
+    private static final String METHOD_GET = "GET"; 
+ 
+    private static final String METHOD_POST = "POST"; 
+ 
+    private static final String METHOD_PUT = "PUT"; 
+ 
+    private static final String METHOD_HEADER_NAME = "x-http-method-override"; 
+ 
+    private HttpServletRequest mockRequest = null; 
+ 
+    private HttpServletResponse mockResponse = null; 
+ 
+    private AbstractGdataServlet servletInstance = null; 
+ 
+    private MockControl requestMockControl; 
+ 
+    private MockControl responseMockControl; 
+ 
+    protected void setUp() throws Exception { 
+        this.requestMockControl = MockControl 
+                .createControl(HttpServletRequest.class); 
+        this.responseMockControl = MockControl 
+                .createControl(HttpServletResponse.class); 
+        this.mockRequest = (HttpServletRequest) this.requestMockControl 
+                .getMock(); 
+        this.mockResponse = (HttpServletResponse) this.responseMockControl 
+                .getMock(); 
+        this.servletInstance = new StubGDataServlet(); 
+    } 
+ 
+    /** 
+     * Test method for 
+     * 'org.apache.lucene.gdata.servlet.AbstractGdataServlet.service(HttpServletRequest,

+     * HttpServletResponse)' 
+     */ 
+    public void testServiceHttpServletRequestHttpServletResponseDelete() { 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_DELETE); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_DELETE); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+        this.requestMockControl.reset(); 
+ 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_POST); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_DELETE); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+    } 
+ 
+    /** 
+     *  
+     */ 
+    public void testServiceNullOverrideHeader() { 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_POST); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), null); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+        this.requestMockControl.reset(); 
+    } 
+ 
+    /** 
+     * Test method for 
+     * 'org.apache.lucene.gdata.servlet.AbstractGdataServlet.service(HttpServletRequest,

+     * HttpServletResponse)' 
+     */ 
+    public void testServiceHttpServletRequestHttpServletResponsePOST() { 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_POST); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_POST); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+        this.requestMockControl.reset(); 
+ 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_PUT); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_POST); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+    } 
+ 
+    /** 
+     * Test method for 
+     * 'org.apache.lucene.gdata.servlet.AbstractGdataServlet.service(HttpServletRequest,

+     * HttpServletResponse)' 
+     */ 
+    public void testServiceHttpServletRequestHttpServletResponsePUT() { 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_PUT); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_PUT); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+        this.requestMockControl.reset(); 
+ 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_POST); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_PUT); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+    } 
+ 
+    /** 
+     * Test method for 
+     * 'org.apache.lucene.gdata.servlet.AbstractGdataServlet.service(HttpServletRequest,

+     * HttpServletResponse)' 
+     */ 
+    public void testServiceHttpServletRequestHttpServletResponseGET() { 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_GET); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_GET); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+        this.requestMockControl.reset(); 
+ 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getMethod(), METHOD_POST); 
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getHeader(METHOD_HEADER_NAME), METHOD_GET); 
+        this.requestMockControl.replay(); 
+ 
+        try { 
+            this.servletInstance.service(this.mockRequest, this.mockResponse); 
+        } catch (ServletException e) { 
+            fail("ServeltExpception not expected"); 
+        } catch (IOException e) { 
+            fail("IOExpception not expected"); 
+        } 
+ 
+        this.requestMockControl.verify(); 
+ 
+    } 
+    /** 
+     * Stub Implementation for <code>AbstractGdataServlet</code> 
+     * @author Simon Willnauer 
+     * 
+     */ 
+    static class StubGDataServlet extends AbstractGdataServlet { 
+ 
+        private static final long serialVersionUID = -6271464588547620925L; 
+ 
+        protected void doDelete(HttpServletRequest arg0, 
+                HttpServletResponse arg1) { 
+            if (arg0.getHeader(METHOD_HEADER_NAME) == null) 
+                assertEquals("Http-Method --DELETE--", METHOD_DELETE, arg0 
+                        .getMethod()); 
+            else 
+                assertEquals("Http-Method override --DELETE--", METHOD_DELETE, 
+                        arg0.getHeader(METHOD_HEADER_NAME)); 
+ 
+        } 
+ 
+        protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) { 
+            if (arg0.getHeader(METHOD_HEADER_NAME) == null) 
+                assertEquals("Http-Method --GET--", arg0.getMethod(), 
+                        METHOD_GET); 
+            else 
+                assertEquals("Http-Method override --GET--", arg0 
+                        .getHeader(METHOD_HEADER_NAME), METHOD_GET); 
+        } 
+ 
+        protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) { 
+            if (arg0.getHeader(METHOD_HEADER_NAME) == null) 
+                assertEquals("Http-Method --POST--", arg0.getMethod(), 
+                        METHOD_POST); 
+            else 
+                assertEquals("Http-Method override --POST--", METHOD_POST, arg0 
+                        .getHeader(METHOD_HEADER_NAME)); 
+ 
+        } 
+ 
+        protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1) { 
+            if (arg0.getHeader(METHOD_HEADER_NAME) == null) 
+                assertEquals("Http-Method --PUT--", arg0.getMethod(), 
+                        METHOD_PUT); 
+            else 
+                assertEquals("Http-Method override --PUT--", arg0 
+                        .getHeader(METHOD_HEADER_NAME), METHOD_PUT); 
+        } 
+ 
+    } 
+ 
+} 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,52 @@
+package org.apache.lucene.gdata.storage; 
+ 
+import java.util.ArrayList; 
+import java.util.List; 
+ 
+import junit.framework.TestCase; 
+ 
+import org.apache.lucene.gdata.storage.IDGenerator; 
+ 
+/** 
+ * @author Simon Willnauer 
+ * 
+ */ 
+public class TestIDGenerator extends TestCase { 
+    private IDGenerator idgen; 
+ 
+    private int initialCap = 100; 
+ 
+    @Override 
+    protected void setUp() throws Exception { 
+        this.idgen = new IDGenerator(this.initialCap); 
+         
+         
+    } 
+ 
+    @Override 
+    protected void tearDown() throws Exception { 
+        this.idgen.stopIDGenerator(); 
+    } 
+ 
+    /** 
+     * Test method for 'org.apache.lucene.gdata.storage.IDGenerator.getUID()' 
+     * @throws InterruptedException  
+     */ 
+    public void testGetUID() throws InterruptedException { 
+         
+        List<String> idlist = new ArrayList<String>(); 
+        //TODO think about a better way to test this 
+        for (int i = 0; i < 1000; i++) { 
+            String id = this.idgen.getUID(); 
+            assertNotNull(id); 
+            assertFalse(idlist.contains(id)); 
+            idlist.add(id); 
+             
+                         
+             
+        } 
+ 
+    } 
+ 
+     
+} 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestModifiedEntryFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestModifiedEntryFilter.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestModifiedEntryFilter.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestModifiedEntryFilter.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,66 @@
+package org.apache.lucene.gdata.storage.lucenestorage; 
+ 
+import java.io.IOException; 
+import java.util.ArrayList; 
+import java.util.List; 
+ 
+import junit.framework.TestCase; 
+ 
+import org.apache.lucene.analysis.standard.StandardAnalyzer; 
+import org.apache.lucene.document.Document; 
+import org.apache.lucene.document.Field; 
+import org.apache.lucene.gdata.storage.lucenestorage.ModifiedEntryFilter; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper; 
+import org.apache.lucene.index.IndexReader; 
+import org.apache.lucene.index.IndexWriter; 
+import org.apache.lucene.index.Term; 
+import org.apache.lucene.search.Hits; 
+import org.apache.lucene.search.IndexSearcher; 
+import org.apache.lucene.search.Query; 
+import org.apache.lucene.search.Searcher; 
+import org.apache.lucene.search.TermQuery; 
+import org.apache.lucene.store.RAMDirectory; 
+ 
+public class TestModifiedEntryFilter extends TestCase { 
+    IndexWriter writer; 
+    IndexReader reader; 
+    List<String> excludeList; 
+    String feedID = "feed"; 
+    String fieldFeedId = "feedID"; 
+    protected void setUp() throws Exception { 
+        RAMDirectory dir = new RAMDirectory(); 
+        this.writer = new IndexWriter(dir,new StandardAnalyzer(),true); 
+        Document doc = new Document(); 
+        doc.add(new Field(StorageEntryWrapper.FIELD_ENTRY_ID,"1",Field.Store.YES,Field.Index.UN_TOKENIZED));

+        doc.add(new Field(fieldFeedId,feedID,Field.Store.YES,Field.Index.UN_TOKENIZED));

+        Document doc1 = new Document(); 
+        doc1.add(new Field(StorageEntryWrapper.FIELD_ENTRY_ID,"2",Field.Store.YES,Field.Index.UN_TOKENIZED));

+        doc1.add(new Field(fieldFeedId,feedID,Field.Store.YES,Field.Index.UN_TOKENIZED));

+        this.writer.addDocument(doc); 
+        this.writer.addDocument(doc1); 
+        this.writer.close(); 
+        this.reader = IndexReader.open(dir); 
+        this.excludeList = new ArrayList(); 
+        this.excludeList.add("1"); 
+         
+         
+    } 
+ 
+    protected void tearDown() throws Exception { 
+        super.tearDown(); 
+    } 
+    public void testFilter() throws IOException{ 
+        Searcher s = new IndexSearcher(this.reader); 
+        Query q = new TermQuery(new Term(fieldFeedId,feedID)); 
+        Hits hits = s.search(q); 
+        assertEquals(2,hits.length()); 
+         
+        hits = s.search(q,new ModifiedEntryFilter(this.excludeList)); 
+        assertEquals(1,hits.length()); 
+        this.excludeList.add("2"); 
+ 
+        hits = s.search(q,new ModifiedEntryFilter(this.excludeList)); 
+        assertEquals(0,hits.length()); 
+         
+    } 
+} 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageModifier.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageModifier.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageModifier.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageModifier.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,247 @@
+package org.apache.lucene.gdata.storage.lucenestorage; 
+ 
+import java.io.IOException; 
+import java.util.Date; 
+ 
+import junit.framework.TestCase; 
+ 
+import org.apache.lucene.analysis.standard.StandardAnalyzer; 
+import org.apache.lucene.gdata.server.FeedNotFoundException; 
+import org.apache.lucene.gdata.server.registry.FeedInstanceConfigurator; 
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry; 
+import org.apache.lucene.gdata.server.registry.RegistryBuilder; 
+import org.apache.lucene.gdata.storage.StorageException; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifier; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageQuery; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;

+import org.apache.lucene.gdata.storage.lucenestorage.util.ReferenceCounter; 
+import org.apache.lucene.index.IndexWriter; 
+import org.apache.lucene.index.Term; 
+import org.apache.lucene.search.Hits; 
+import org.apache.lucene.search.IndexSearcher; 
+import org.apache.lucene.search.Query; 
+import org.apache.lucene.search.TermQuery; 
+import org.apache.lucene.store.Directory; 
+import org.apache.lucene.store.RAMDirectory; 
+ 
+import com.google.gdata.data.BaseEntry; 
+import com.google.gdata.data.DateTime; 
+import com.google.gdata.data.Entry; 
+import com.google.gdata.data.ExtensionProfile; 
+import com.google.gdata.data.Feed; 
+import com.google.gdata.data.PlainTextConstruct; 
+import com.google.gdata.data.TextConstruct; 
+import com.google.gdata.data.TextContent; 
+import com.google.gdata.util.ParseException; 
+ 
+public class TestStorageModifier extends TestCase { 
+    private StorageModifier modifier; 
+    private int count = 1; 
+    
+    private ExtensionProfile profile; 
+    private  Directory dir; 
+ 
+    
+    private static String feedId = "myFeed"; 
+   
+    protected void setUp() throws Exception { 
+        FeedInstanceConfigurator configurator = new FeedInstanceConfigurator(); 
+        configurator.setFeedType(Feed.class); 
+        configurator.setFeedId(feedId); 
+        configurator.setExtensionProfileClass(ExtensionProfile.class); 
+        GDataServerRegistry.getRegistry().registerFeed(configurator); 
+        dir = new RAMDirectory(); 
+        this.profile = new ExtensionProfile(); 
+        IndexWriter writer; 
+         
+        writer = new IndexWriter(dir,new StandardAnalyzer(),true); 
+        writer.close(); 
+        modifier = StorageCoreController.getStorageCoreController(dir).getStorageModifier();

+         
+        
+    } 
+ 
+    protected void tearDown() throws Exception { 
+        this.count = 1; 
+        // destroy all resources 
+        GDataServerRegistry.getRegistry().destroy();//TODO remove dependency here 
+         
+    } 
+ 
+    /* 
+     * Test method for 
+     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.StorageModifier(Directory,

+     * int)' 
+     */ 
+    public void testStorageModifier() { 
+ 
+    } 
+ 
+    /* 
+     * Test method for 
+     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.updateEntry(StroageEntryWrapper)'

+     */ 
+    public void testUpdateEntry() throws IOException, InterruptedException, FeedNotFoundException,
ParseException, StorageException { 
+        testInsertEntry(); 
+        for(int i = 1; i < this.count; i++){ 
+            Entry e = new Entry(); 
+            e.setId(""+i); 
+            String insertString = "Hello world"+i; 
+            e.setTitle(new PlainTextConstruct(insertString)); 
+            StorageEntryWrapper wrapper = new StorageEntryWrapper(e,feedId,StorageOperation.UPDATE,this.profile);

+            this.modifier.updateEntry(wrapper); 
+            ReferenceCounter<StorageQuery> innerQuery = StorageCoreController.getStorageCoreController().getStorageQuery();

+            BaseEntry fetchedEntry = innerQuery.get().singleEntryQuery(""+i,feedId,this.profile);

+            assertEquals("updated Title:",insertString,fetchedEntry.getTitle().getPlainText());
            
+        } 
+        // double updates 
+        for(int i = 1; i < this.count; i++){ 
+            Entry e = new Entry(); 
+            e.setId(""+i); 
+            String insertString = "Hello world"+i; 
+            e.setTitle(new PlainTextConstruct(insertString)); 
+            StorageEntryWrapper wrapper = new StorageEntryWrapper(e,feedId,StorageOperation.UPDATE,this.profile);

+            this.modifier.updateEntry(wrapper); 
+             
+            e = new Entry(); 
+            e.setId(""+i); 
+            insertString = "Foo Bar"+i; 
+            e.setTitle(new PlainTextConstruct(insertString)); 
+            wrapper = new StorageEntryWrapper(e,feedId,StorageOperation.UPDATE,this.profile);

+            this.modifier.updateEntry(wrapper); 
+             
+            ReferenceCounter<StorageQuery> innerQuery = StorageCoreController.getStorageCoreController().getStorageQuery();

+             
+            BaseEntry fetchedEntry = innerQuery.get().singleEntryQuery(""+i,feedId,this.profile);

+            assertEquals("updated Title:",insertString,fetchedEntry.getTitle().getPlainText());
            
+        } 
+ 
+         
+         
+    } 
+ 
+    /* 
+     * Test method for 
+     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.insertEntry(StroageEntryWrapper)'

+     */ 
+    public void testInsertEntry() throws IOException, InterruptedException, FeedNotFoundException,
ParseException, StorageException { 
+        
+        Thread a = getRunnerThread(this.count); 
+        a.start(); 
+         
+        Thread b = getRunnerThread((this.count+=10)); 
+        b.start(); 
+        a.join(); 
+        for (int i = 1; i < this.count ; i++) { 
+            ReferenceCounter<StorageQuery> innerQuery = StorageCoreController.getStorageCoreController().getStorageQuery();

+            BaseEntry e = innerQuery.get().singleEntryQuery(""+i,feedId,this.profile); 
+            assertEquals("get entry for id"+i,""+i,e.getId()); 
+             
+             
+        } 
+        b.join(); 
+        ReferenceCounter<StorageQuery> query = StorageCoreController.getStorageCoreController().getStorageQuery();

+         
+        this.count+=10; 
+        for (int i = 1; i < this.count ; i++) { 
+            BaseEntry e = query.get().singleEntryQuery(""+i,feedId,this.profile); 
+            assertEquals("get entry for id"+i,""+i,e.getId()); 
+        } 
+        
+        BaseEntry e = query.get().singleEntryQuery(""+this.count,feedId,this.profile); 
+        assertNull("not entry for ID",e); 
+        query.decrementRef(); 
+         
+    } 
+ 
+    /* 
+     * Test method for 
+     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.deleteEntry(String)' 
+     */ 
+    public void testDeleteEntry() throws IOException, InterruptedException, FeedNotFoundException,
ParseException, StorageException { 
+        testInsertEntry(); 
+        for (int i = 1; i < this.count ; i++) { 
+            if(i%2 == 0 || i< 10){ 
+                this.modifier.deleteEntry(""+i,feedId); 
+            } 
+            ReferenceCounter<StorageQuery> query = StorageCoreController.getStorageCoreController().getStorageQuery();

+            if(i%2 == 0 || i< 10){ 
+                assertNull(query.get().singleEntryQuery(""+i,feedId,this.profile)); 
+            } 
+            else 
+                assertEquals(""+i,query.get().singleEntryQuery(""+i,feedId,this.profile).getId());

+            query.decrementRef(); 
+        } 
+         
+        StorageCoreController.getStorageCoreController().forceWrite(); 
+        IndexSearcher searcher = new IndexSearcher(this.dir); 
+         
+        for (int i = 1; i < this.count ; i++) { 
+            Query luceneQuery = new TermQuery(new Term(StorageEntryWrapper.FIELD_ENTRY_ID,""+i));

+            Hits hits = searcher.search(luceneQuery); 
+            if(i%2 == 0 || i< 10){ 
+                 
+                assertEquals(0,hits.length()); 
+            } 
+            else 
+                assertEquals(1,hits.length()); 
+        } 
+        searcher.close(); 
+         
+    } 
+     
+     
+    private Thread getRunnerThread(int idIndex){ 
+        Thread t = new Thread(new Runner(idIndex)); 
+        return t; 
+    } 
+     
+    private class Runner implements Runnable{ 
+        private int idIndex; 
+        public Runner(int idIndex){ 
+            this.idIndex = idIndex; 
+        } 
+        public void run() { 
+            for (int i = idIndex; i < idIndex+10; i++) { 
+               
+                BaseEntry e = buildEntry(""+i); 
+                try { 
+                StorageEntryWrapper wrapper = new StorageEntryWrapper(e,feedId,StorageOperation.INSERT,new
ExtensionProfile()); 
+                modifier.insertEntry(wrapper); 
+                } catch (Exception e1) { 
+                     
+                    e1.printStackTrace(); 
+                } 
+            
+                 
+                 
+     
+            } 
+          
+                             
+        }//end run 
+         
+        private BaseEntry buildEntry(String id){ 
+            Entry e = new Entry(); 
+            e.setId(id); 
+            e.setTitle(new PlainTextConstruct("Monty Python")); 
+             
+            e.setPublished(DateTime.now()); 
+             
+            e.setUpdated(DateTime.now()); 
+            String content = "1st soldier with a keen interest in birds: Who goes there?"
+ 
+                    "King Arthur: It is I, Arthur, son of Uther Pendragon, from the castle
of Camelot. King of the Britons, defeater of the Saxons, Sovereign of all England!" + 
+                    "1st soldier with a keen interest in birds: Pull the other one!" + 
+                    "King Arthur: I am, and this is my trusty servant Patsy. We have ridden
the length and breadth of the land in search of knights who will join me in my court at Camelot.
I must speak with your lord and master." + 
+                    "1st soldier with a keen interest in birds: What? Ridden on a horse?"
+ 
+                    "King Arthur: Yes!"; 
+            e.setContent(new TextContent(new PlainTextConstruct(content))); 
+            e.setSummary(new PlainTextConstruct("The Holy Grail")); 
+            return e; 
+        } 
+         
+    } 
+ 
+} 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageQuery.java?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageQuery.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageQuery.java
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,175 @@
+package org.apache.lucene.gdata.storage.lucenestorage; 
+ 
+import java.io.IOException; 
+import java.util.ArrayList; 
+import java.util.List; 
+ 
+import junit.framework.TestCase; 
+ 
+import org.apache.lucene.analysis.standard.StandardAnalyzer; 
+import org.apache.lucene.gdata.server.FeedNotFoundException; 
+import org.apache.lucene.gdata.server.registry.FeedInstanceConfigurator; 
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry; 
+import org.apache.lucene.gdata.server.registry.RegistryBuilder; 
+import org.apache.lucene.gdata.storage.StorageException; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifier; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageQuery; 
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;

+import org.apache.lucene.gdata.storage.lucenestorage.util.ReferenceCounter; 
+import org.apache.lucene.index.IndexWriter; 
+import org.apache.lucene.store.Directory; 
+import org.apache.lucene.store.RAMDirectory; 
+ 
+import com.google.gdata.data.BaseEntry; 
+import com.google.gdata.data.DateTime; 
+import com.google.gdata.data.Entry; 
+import com.google.gdata.data.ExtensionProfile; 
+import com.google.gdata.data.Feed; 
+import com.google.gdata.util.ParseException; 
+ 
+public class TestStorageQuery extends TestCase { 
+    private StorageModifier modifier; 
+    private int count = 30; 
+    private ReferenceCounter<StorageQuery> query; 
+    private ExtensionProfile profile; 
+ 
+    private  Directory dir; 
+    private static String feedId = "myFeed"; 
+    protected void setUp() throws Exception { 
+        FeedInstanceConfigurator configurator = new FeedInstanceConfigurator(); 
+        configurator.setFeedType(Feed.class); 
+        configurator.setFeedId(feedId); 
+        configurator.setExtensionProfileClass(ExtensionProfile.class); 
+        GDataServerRegistry.getRegistry().registerFeed(configurator); 
+        this.profile = new ExtensionProfile(); 
+        this.dir = new RAMDirectory(); 
+        IndexWriter writer; 
+        writer = new IndexWriter(this.dir,new StandardAnalyzer(),true); 
+        writer.close(); 
+        this.modifier = StorageCoreController.getStorageCoreController(this.dir).getStorageModifier();

+        insertEntries(this.count); 
+        this.query = StorageCoreController.getStorageCoreController().getStorageQuery();

+       
+         
+         
+    } 
+     
+     
+    public void insertEntries(int count) throws IOException,InterruptedException, StorageException{

+        List<StorageEntryWrapper> tempList = new ArrayList<StorageEntryWrapper>();

+        for (int i = 0; i <= count ; i++) { 
+            Entry entry = new Entry(); 
+            entry.setId(""+i); 
+             
+            entry.setUpdated(new DateTime(System.currentTimeMillis(),0)); 
+            StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,feedId,StorageOperation.INSERT,this.profile);

+            tempList.add(i,wrapper); 
+            
+            // force different timestamps --> DateTime 2006-06-05T13:37:55.724Z 
+            Thread.sleep(50); 
+           
+        } 
+        for (StorageEntryWrapper entry : tempList) { 
+            this.modifier.insertEntry(entry); 
+        } 
+         
+         
+         
+         
+    } 
+ 
+    protected void tearDown() throws Exception { 
+        this.query.decrementRef(); 
+        GDataServerRegistry.getRegistry().destroy();//TODO remove dependency here 
+    } 
+ 
+    /* 
+     * Test method for 'org.apache.lucene.storage.lucenestorage.StorageQuery.feedQuery(String,
int, int)' 
+     */ 
+    public void testFeedQuery() throws IOException, FeedNotFoundException, ParseException,
StorageException { 
+        FeedQueryHelper(this.query); 
+        StorageCoreController.getStorageCoreController().forceWrite(); 
+        ReferenceCounter<StorageQuery> queryAssureWritten = StorageCoreController.getStorageCoreController().getStorageQuery();

+        
+        assertNotSame(queryAssureWritten,this.query); 
+        FeedQueryHelper(queryAssureWritten); 
+        queryAssureWritten.decrementRef(); 
+    } 
+    private void FeedQueryHelper(ReferenceCounter<StorageQuery> currentQuery) throws
IOException, FeedNotFoundException, ParseException{ 
+        List<BaseEntry> entryList = currentQuery.get().getLatestFeedQuery(feedId,25,1,this.profile);

+         
+        assertTrue("listSize: "+entryList.size(),entryList.size() == 25); 
+         
+        BaseEntry tempEntry = null; 
+        for (BaseEntry entry : entryList) { 
+           
+            assertNotNull("entry",entry); 
+            if(tempEntry != null){ 
+                assertTrue(tempEntry.getUpdated().compareTo(entry.getUpdated())>=0) ;

+                tempEntry = entry; 
+            }else 
+                tempEntry = entry; 
+             
+        } 
+        // test sub retrieve sublist 
+        int offset = 15; 
+        int resultCount = 5;  
+        List<BaseEntry> entrySubList = currentQuery.get().getLatestFeedQuery(feedId,resultCount,offset,this.profile);

+         
+        assertTrue("listSize: "+entrySubList.size(),entrySubList.size() == resultCount);

+        offset--; 
+        for (BaseEntry entry : entrySubList) { 
+             
+            assertEquals(entry.getId(),entryList.get(offset).getId()); 
+            offset++; 
+             
+        } 
+         
+         
+         
+    } 
+ 
+    /* 
+     * Test method for 'org.apache.lucene.storage.lucenestorage.StorageQuery.singleEntryQuery(String,
String)' 
+     */ 
+    public void testSingleEntryQuery() throws FeedNotFoundException, ParseException, IOException
{ 
+        for (int i = 1; i <= this.count; i++) { 
+            BaseEntry entry = this.query.get().singleEntryQuery(""+i,feedId,this.profile);

+            assertEquals(""+i,entry.getId()); 
+        } 
+         
+    } 
+ 
+    /* 
+     * Test method for 'org.apache.lucene.storage.lucenestorage.StorageQuery.entryQuery(List<String>,
String)' 
+     */ 
+    public void testEntryQuery() throws FeedNotFoundException, ParseException, IOException,
StorageException { 
+        entryQueryHelper(this.query); 
+        StorageCoreController.getStorageCoreController().forceWrite(); 
+        ReferenceCounter<StorageQuery> queryAssureWritten = StorageCoreController.getStorageCoreController().getStorageQuery();

+        
+        assertNotSame(queryAssureWritten,query); 
+        entryQueryHelper(queryAssureWritten); 
+        queryAssureWritten.decrementRef(); 
+    } 
+     
+     
+    private void entryQueryHelper(ReferenceCounter<StorageQuery> currentQuery) throws
IOException, FeedNotFoundException, ParseException{ 
+         
+        List<String> entryIdList = new ArrayList<String>(); 
+        for (int i = 1; i <= this.count; i++) { 
+           entryIdList.add(""+i); 
+        } 
+        List<BaseEntry> entryList = currentQuery.get().entryQuery(entryIdList,feedId,this.profile);

+        assertEquals(entryIdList.size(),entryList.size()); 
+        List<String> entryIdCompare = new ArrayList<String>(); 
+        for (BaseEntry entry : entryList) { 
+            entryIdCompare.add(entry.getId()); 
+        } 
+        assertTrue(entryIdList.containsAll(entryIdCompare)); 
+         
+    } 
+ 
+} 

Added: lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/classes/lucenestorage.properties.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/classes/lucenestorage.properties.xml?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/classes/lucenestorage.properties.xml
(added)
+++ lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/classes/lucenestorage.properties.xml
Wed Jun  7 14:56:25 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> 
+<properties> 
+<comment>Lucene Storage Properties</comment> 
+<entry key="gdata.server.storage.lucene.buffersize">20</entry> 
+<entry key="gdata.server.storage.lucene.persistFactor">20</entry> 
+<entry key="gdata.server.storage.lucene.optimizeInterval">20</entry> 
+<entry key="gdata.server.storage.lucene.directory">/tmp/storage/</entry> 
+<entry key="gdata.server.storage.lucene.recover">true</entry> 
+<entry key="gdata.server.storage.lucene.recover.keepFiles">false</entry> 
+</properties> 
\ No newline at end of file

Added: lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/web.xml?rev=412574&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/web.xml (added)
+++ lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/web.xml Wed Jun  7 14:56:25 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" 
+    version="2.4"> 
+    <display-name>Lucene GData - Server</display-name> 
+    <description> 
+        Server-side implementation of the GData protocol based on Apache 
+        - Lucene 
+    </description> 
+    <listener> 
+        <listener-class> org.apache.lucene.gdata.server.registry.RegistryContextListener</listener-class>

+    </listener> 
+    <servlet> 
+        <servlet-name>ControllerServlet</servlet-name> 
+        <servlet-class> 
+            org.apache.lucene.gdata.servlet.RequestControllerServlet 
+        </servlet-class> 
+    </servlet> 
+    <servlet-mapping> 
+        <servlet-name>ControllerServlet</servlet-name> 
+        <url-pattern>/*</url-pattern> 
+    </servlet-mapping> 
+</web-app> 
\ No newline at end of file



Mime
View raw message