You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/10/02 13:50:22 UTC
svn commit: r1392861 - in /lucene/dev/branches/lucene4456/lucene:
core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java
test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
Author: rmuir
Date: Tue Oct 2 11:50:21 2012
New Revision: 1392861
URL: http://svn.apache.org/viewvc?rev=1392861&view=rev
Log:
LUCENE-4456: add a test that MDW actually detects and fails on unref'd files
Added:
lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java (with props)
Modified:
lucene/dev/branches/lucene4456/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
Added: lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java?rev=1392861&view=auto
==============================================================================
--- lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java (added)
+++ lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfUnreferencedFiles.java Tue Oct 2 11:50:21 2012
@@ -0,0 +1,56 @@
+package org.apache.lucene.util.junitcompat;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.junitcompat.TestFailIfDirectoryNotClosed.Nested1;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// LUCENE-4456: Test that we fail if there are unreferenced files
+public class TestFailIfUnreferencedFiles extends WithNestedTests {
+ public TestFailIfUnreferencedFiles() {
+ super(true);
+ }
+
+ public static class Nested1 extends WithNestedTests.AbstractNestedTest {
+ public void testDummy() throws Exception {
+ Directory dir = newMockDirectory();
+ IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
+ iw.addDocument(new Document());
+ iw.close();
+ IndexOutput output = dir.createOutput("TEST_THE_TESTER_FILE_NEVER_DELETED_ON_CRASH", IOContext.DEFAULT);
+ output.writeString("i am unreferenced!");
+ output.close();
+ dir.close();
+ }
+ }
+
+ @Test
+ public void testFailIfUnreferencedFiles() {
+ Result r = JUnitCore.runClasses(Nested1.class);
+ Assert.assertEquals(1, r.getFailureCount());
+ }
+}
Modified: lucene/dev/branches/lucene4456/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4456/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1392861&r1=1392860&r2=1392861&view=diff
==============================================================================
--- lucene/dev/branches/lucene4456/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/lucene4456/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Tue Oct 2 11:50:21 2012
@@ -214,7 +214,7 @@ public class MockDirectoryWrapper extend
String name = it.next();
int damage = randomState.nextInt(5);
String action = null;
- if (damage == 0) {
+ if (damage == 0 && !name.equals("TEST_THE_TESTER_FILE_NEVER_DELETED_ON_CRASH")) {
action = "deleted";
deleteFile(name, true);
} else if (damage == 1) {