lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r935522 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/SnapshotDeletionPolicy.java test/org/apache/lucene/TestSnapshotDeletionPolicy.java test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
Date Mon, 19 Apr 2010 10:54:21 GMT
Author: shaie
Date: Mon Apr 19 10:54:20 2010
New Revision: 935522

URL: http://svn.apache.org/viewvc?rev=935522&view=rev
Log:
LUCENE-2397: SnapshotDeletionPolicy.snapshot() throws NPE if no commits happened

Added:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
      - copied, changed from r935454, lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java
Removed:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java
Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java?rev=935522&r1=935521&r2=935522&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java Mon
Apr 19 10:54:20 2010
@@ -71,6 +71,10 @@ public class SnapshotDeletionPolicy impl
    *  consume an extra 1X of your total index size, until
    *  you release the snapshot. */
   public synchronized IndexCommit snapshot() {
+    if (lastCommit == null) {
+      throw new IllegalStateException("no index commits to snapshot !");
+    }
+    
     if (snapshot == null)
       snapshot = lastCommit.getSegmentsFileName();
     else

Copied: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
(from r935454, lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java?p2=lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java&p1=lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java&r1=935454&r2=935522&rev=935522&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
Mon Apr 19 10:54:20 2010
@@ -1,6 +1,4 @@
-package org.apache.lucene;
-// Intentionally not in org.apache.lucene.index, to assert
-// that we do not require any package private access.
+package org.apache.lucene.index;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,6 +17,8 @@ package org.apache.lucene;
  * limitations under the License.
  */
 
+import static org.junit.Assert.*;
+
 import java.util.Collection;
 import java.io.File;
 import java.io.IOException;
@@ -34,21 +34,22 @@ import org.apache.lucene.index.IndexComm
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.TestIndexWriter;
 import org.apache.lucene.index.SnapshotDeletionPolicy;
+import org.apache.lucene.util.LuceneTestCaseJ4;
 import org.apache.lucene.util.ThreadInterruptedException;
-import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
+import org.junit.Test;
 
 //
 // This was developed for Lucene In Action,
 // http://lucenebook.com
 //
 
-public class TestSnapshotDeletionPolicy extends LuceneTestCase {
+public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
   
   public static final String INDEX_PATH = "test.snapshots";
 
+  @Test
   public void testSnapshotDeletionPolicy() throws Exception {
     File dir = _TestUtil.getTempDir(INDEX_PATH);
     try {
@@ -64,6 +65,7 @@ public class TestSnapshotDeletionPolicy 
     dir2.close();
   }
 
+  @Test
   public void testReuseAcrossWriters() throws Exception {
     Directory dir = new MockRAMDirectory();
 
@@ -235,5 +237,13 @@ public class TestSnapshotDeletionPolicy 
       input.close();
     }
   }
+  
+  @Test(expected=IllegalStateException.class)
+  public void testNoCommits() throws Exception {
+    // Tests that if there were no commits when snapshot() is called, then
+    // IllegalStateException is thrown rather than NPE.
+    SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
+    sdp.snapshot();
+  }
+  
 }
-



Mime
View raw message