lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1626796 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
Date Mon, 22 Sep 2014 14:49:40 GMT
Author: rmuir
Date: Mon Sep 22 14:49:40 2014
New Revision: 1626796

URL: http://svn.apache.org/r1626796
Log:
LUCENE-5969: improve this test, we cant uncomment the assert until we fix 5.0 codec

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java?rev=1626796&r1=1626795&r2=1626796&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
Mon Sep 22 14:49:40 2014
@@ -18,12 +18,16 @@ package org.apache.lucene.index;
  */
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.TextField;
 import org.apache.lucene.store.CompoundFileDirectory;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
@@ -48,16 +52,22 @@ public class TestAllFilesHaveCodecHeader
     conf.setCodec(TestUtil.getDefaultCodec());
     RandomIndexWriter riw = new RandomIndexWriter(random(), dir, conf);
     Document doc = new Document();
-    // these fields should sometimes get term vectors, etc
-    Field idField = newStringField("id", "", Field.Store.NO);
-    Field bodyField = newTextField("body", "", Field.Store.NO);
+    Field idField = newStringField("id", "", Field.Store.YES);
+    Field bodyField = newTextField("body", "", Field.Store.YES);
+    FieldType vectorsType = new FieldType(TextField.TYPE_STORED);
+    vectorsType.setStoreTermVectors(true);
+    vectorsType.setStoreTermVectorPositions(true);
+    Field vectorsField = new Field("vectors", "", vectorsType);
     Field dvField = new NumericDocValuesField("dv", 5);
     doc.add(idField);
     doc.add(bodyField);
+    doc.add(vectorsField);
     doc.add(dvField);
     for (int i = 0; i < 100; i++) {
       idField.setStringValue(Integer.toString(i));
       bodyField.setStringValue(TestUtil.randomUnicodeString(random()));
+      dvField.setLongValue(random().nextInt(5));
+      vectorsField.setStringValue(TestUtil.randomUnicodeString(random()));
       riw.addDocument(doc);
       if (random().nextInt(7) == 0) {
         riw.commit();
@@ -68,18 +78,18 @@ public class TestAllFilesHaveCodecHeader
       // }
     }
     riw.close();
-    checkHeaders(dir);
+    checkHeaders(dir, new HashMap<String,String>());
     dir.close();
   }
   
-  private void checkHeaders(Directory dir) throws IOException {
+  private void checkHeaders(Directory dir, Map<String,String> namesToExtensions) throws
IOException {
     for (String file : dir.listAll()) {
       if (file.equals(IndexWriter.WRITE_LOCK_NAME)) {
         continue; // write.lock has no header, thats ok
       }
       if (file.endsWith(IndexFileNames.COMPOUND_FILE_EXTENSION)) {
         CompoundFileDirectory cfsDir = new CompoundFileDirectory(dir, file, newIOContext(random()),
false);
-        checkHeaders(cfsDir); // recurse into cfs
+        checkHeaders(cfsDir, namesToExtensions); // recurse into cfs
         cfsDir.close();
       }
       IndexInput in = null;
@@ -88,6 +98,18 @@ public class TestAllFilesHaveCodecHeader
         in = dir.openInput(file, newIOContext(random()));
         int val = in.readInt();
         assertEquals(file + " has no codec header, instead found: " + val, CodecUtil.CODEC_MAGIC,
val);
+        String codecName = in.readString();
+        assertFalse(codecName.isEmpty());
+        String extension = IndexFileNames.getExtension(file);
+        if (extension == null) {
+          assertTrue(file.startsWith(IndexFileNames.SEGMENTS));
+          extension = "<segments> (not a real extension, designates segments file)";
+        }
+        String previous = namesToExtensions.put(codecName, extension);
+        if (previous != null && !previous.equals(extension)) {
+          //TODO: not yet 
+          // fail("extensions " + previous + " and " + extension + " share same codecName
" + codecName);
+        }
         success = true;
       } finally {
         if (success) {



Mime
View raw message