lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1143775 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/contrib/join/ lucene/src/java/org/apache/lucene/store/ lucene/src/test-framework/org/apache/lu...
Date Thu, 07 Jul 2011 11:47:15 GMT
Author: simonw
Date: Thu Jul  7 11:47:14 2011
New Revision: 1143775

URL: http://svn.apache.org/viewvc?rev=1143775&view=rev
Log:
LUCENE-3279: Allow CFS to be empty

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/join/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java?rev=1143775&r1=1143774&r2=1143775&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
Thu Jul  7 11:47:14 2011
@@ -78,6 +78,7 @@ public abstract class CompoundFileDirect
     this.entries = SENTINEL;
     this.openForWrite = true;
     this.isOpen = true;
+    writer = new CompoundFileWriter(directory, fileName);
   }
   
   /** Helper method that reads CFS entries from an input stream */
@@ -269,7 +270,6 @@ public abstract class CompoundFileDirect
   @Override
   public IndexOutput createOutput(String name) throws IOException {
     ensureOpen();
-    initWriter();
     return writer.createOutput(name);
   }
   
@@ -302,17 +302,8 @@ public abstract class CompoundFileDirect
     throw new UnsupportedOperationException();
   }
   
-  private final void initWriter() {
-    assert openForWrite;
-    assert entries == SENTINEL;
-    if (writer == null) {
-      writer = new CompoundFileWriter(directory, fileName);
-    }
-  }
-
   @Override
   public void touchFile(String name) throws IOException {
   }
-
  
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java?rev=1143775&r1=1143774&r2=1143775&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
Thu Jul  7 11:47:14 2011
@@ -135,10 +135,7 @@ final class CompoundFileWriter {
     IOException priorException = null;
     IndexOutput entryTableOut = null;
     try {
-      if (entries.isEmpty()) {
-        throw new IllegalStateException("CFS has no entries");
-      }
-      
+      initDataOut();
       if (!pendingEntries.isEmpty() || outputTaken.get()) {
         throw new IllegalStateException("CFS has pending open files");
       }

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java?rev=1143775&r1=1143774&r2=1143775&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
Thu Jul  7 11:47:14 2011
@@ -19,7 +19,6 @@ package org.apache.lucene.store;
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Collections;
 
 public class MockCompoundFileDirectoryWrapper extends CompoundFileDirectory {
   private final MockDirectoryWrapper parent;
@@ -31,11 +30,7 @@ public class MockCompoundFileDirectoryWr
     this.name = name;
     this.parent = parent;
     this.delegate = delegate;
-    if (forWrite) {
-      super.initForWrite();
-    } else {
-      super.initForRead(Collections.<String,FileEntry>emptyMap());
-    }
+    // don't initialize here since we delegate everything - if not initialized a direct call
will cause an assert to fail!
     parent.addFileHandle(this, name, !forWrite);
   }
   
@@ -51,12 +46,8 @@ public class MockCompoundFileDirectoryWr
 
   @Override
   public synchronized void close() throws IOException {
-    try {
-      delegate.close();
-      parent.removeOpenFile(this, name);
-    } finally {
-      super.close();
-    }
+    delegate.close();
+    parent.removeOpenFile(this, name);
   }
 
   @Override

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java?rev=1143775&r1=1143774&r2=1143775&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
Thu Jul  7 11:47:14 2011
@@ -21,13 +21,13 @@ import java.io.IOException;
 import java.io.File;
 
 import org.apache.lucene.util.LuceneTestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
 
 import org.apache.lucene.store.CompoundFileDirectory;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.store.MockDirectoryWrapper.Failure;
 import org.apache.lucene.store.SimpleFSDirectory;
 import org.apache.lucene.store._TestHelper;
 import org.apache.lucene.util._TestUtil;
@@ -35,27 +35,8 @@ import org.apache.lucene.util._TestUtil;
 
 public class TestCompoundFile extends LuceneTestCase
 {
-    /** Main for running test case by itself. */
-    public static void main(String args[]) {
-        TestRunner.run (new TestSuite(TestCompoundFile.class));
-//        TestRunner.run (new TestCompoundFile("testSingleFile"));
-//        TestRunner.run (new TestCompoundFile("testTwoFiles"));
-//        TestRunner.run (new TestCompoundFile("testRandomFiles"));
-//        TestRunner.run (new TestCompoundFile("testClonedStreamsClosing"));
-//        TestRunner.run (new TestCompoundFile("testReadAfterClose"));
-//        TestRunner.run (new TestCompoundFile("testRandomAccess"));
-//        TestRunner.run (new TestCompoundFile("testRandomAccessClones"));
-//        TestRunner.run (new TestCompoundFile("testFileNotFound"));
-//        TestRunner.run (new TestCompoundFile("testReadPastEOF"));
-
-//        TestRunner.run (new TestCompoundFile("testIWCreate"));
-
-    }
-
-
     private Directory dir;
 
-
     @Override
     public void setUp() throws Exception {
        super.setUp();
@@ -717,5 +698,16 @@ public class TestCompoundFile extends Lu
     cfr.close();
     newDir.close();
   }
+  
+  public void testEmptyCFS() throws IOException {
+    Directory newDir = newDirectory();
+    CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
+    csw.close();
 
+    CompoundFileDirectory csr = newDir.openCompoundInput("d.cfs", 1024);
+    assertEquals(0, csr.listAll().length);
+    csr.close();
+
+    newDir.close();
+  }
 }



Mime
View raw message