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 2014/07/29 15:21:27 UTC

svn commit: r1614340 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java

Author: rmuir
Date: Tue Jul 29 13:21:27 2014
New Revision: 1614340

URL: http://svn.apache.org/r1614340
Log:
LUCENE-5849: try to stress slicing better in BaseDirectoryTestCase

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java?rev=1614340&r1=1614339&r2=1614340&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java Tue Jul 29 13:21:27 2014
@@ -914,5 +914,52 @@ public abstract class BaseDirectoryTestC
     input.close();
     dir.close();
   }
+  
+  /** try to stress slices of slices */
+  public void testSliceOfSlice() throws Exception {
+    Directory dir = getDirectory(createTempDir("sliceOfSlice"));
+    IndexOutput output = dir.createOutput("bytes", newIOContext(random()));
+    int num = TestUtil.nextInt(random(), 50, 2500);
+    byte bytes[] = new byte[num];
+    random().nextBytes(bytes);
+    for (int i = 0; i < bytes.length; i++) {
+      output.writeByte(bytes[i]);
+    }
+    output.close();
+    
+    IndexInput input = dir.openInput("bytes", newIOContext(random()));
+    // seek to a random spot shouldnt impact slicing.
+    input.seek(TestUtil.nextLong(random(), 0, input.length()));
+    for (int i = 0; i < num; i += 16) {
+      IndexInput slice1 = input.slice("slice1", i, num-i);
+      assertEquals(0, slice1.getFilePointer());
+      assertEquals(num-i, slice1.length());
+      
+      // seek to a random spot shouldnt impact slicing.
+      slice1.seek(TestUtil.nextLong(random(), 0, slice1.length()));
+      for (int j = 0; j < slice1.length(); j += 16) {
+        IndexInput slice2 = slice1.slice("slice2", j, num-i-j);
+        assertEquals(0, slice2.getFilePointer());
+        assertEquals(num-i-j, slice2.length());
+        byte data[] = new byte[num];
+        System.arraycopy(bytes, 0, data, 0, i+j);
+        if (random().nextBoolean()) {
+          // read the bytes for this slice-of-slice
+          slice2.readBytes(data, i+j, num-i-j);
+        } else {
+          // seek to a random spot in between, read some, seek back and read the rest
+          long seek = TestUtil.nextLong(random(), 0, slice2.length());
+          slice2.seek(seek);
+          slice2.readBytes(data, (int)(i+j+seek), (int)(num-i-j-seek));
+          slice2.seek(0);
+          slice2.readBytes(data, i+j, (int)seek);
+        }
+        assertArrayEquals(bytes, data);
+      }
+    }
+    
+    input.close();
+    dir.close();
+  }
 }