|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TestCompoundFile | Line # 36 | 297 | 40 | 97.4% |
0.973913
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| (10) | |||
| Result | |||
|
0.24927536
|
org.apache.lucene.index.TestCompoundFile.testRandomFiles
org.apache.lucene.index.TestCompoundFile.testRandomFiles
|
1 PASS | |
|
0.21449275
|
org.apache.lucene.index.TestCompoundFile.testClonedStreamsClosing
org.apache.lucene.index.TestCompoundFile.testClonedStreamsClosing
|
1 PASS | |
|
0.20869565
|
org.apache.lucene.index.TestCompoundFile.testTwoFiles
org.apache.lucene.index.TestCompoundFile.testTwoFiles
|
1 PASS | |
|
0.2057971
|
org.apache.lucene.index.TestCompoundFile.testRandomAccessClones
org.apache.lucene.index.TestCompoundFile.testRandomAccessClones
|
1 PASS | |
|
0.2057971
|
org.apache.lucene.index.TestCompoundFile.testRandomAccess
org.apache.lucene.index.TestCompoundFile.testRandomAccess
|
1 PASS | |
|
0.2
|
org.apache.lucene.index.TestCompoundFile.testSingleFile
org.apache.lucene.index.TestCompoundFile.testSingleFile
|
1 PASS | |
|
0.08695652
|
org.apache.lucene.index.TestCompoundFile.testReadPastEOF
org.apache.lucene.index.TestCompoundFile.testReadPastEOF
|
1 PASS | |
|
0.06376812
|
org.apache.lucene.index.TestCompoundFile.testFileNotFound
org.apache.lucene.index.TestCompoundFile.testFileNotFound
|
1 PASS | |
|
0.046376813
|
org.apache.lucene.index.TestCompoundFile.testReadAfterClose
org.apache.lucene.index.TestCompoundFile.testReadAfterClose
|
1 PASS | |
|
0.034782607
|
org.apache.lucene.index.TestCompoundFile.testLargeWrites
org.apache.lucene.index.TestCompoundFile.testLargeWrites
|
1 PASS | |
| 1 | package org.apache.lucene.index; | |
| 2 | ||
| 3 | /** | |
| 4 | * Copyright 2004 The Apache Software Foundation | |
| 5 | * | |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | * you may not use this file except in compliance with the License. | |
| 8 | * You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, software | |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 15 | * See the License for the specific language governing permissions and | |
| 16 | * limitations under the License. | |
| 17 | */ | |
| 18 | ||
| 19 | import java.io.IOException; | |
| 20 | import java.io.File; | |
| 21 | ||
| 22 | import junit.framework.TestCase; | |
| 23 | import junit.framework.TestSuite; | |
| 24 | import junit.textui.TestRunner; | |
| 25 | import org.apache.lucene.store.IndexOutput; | |
| 26 | import org.apache.lucene.store.Directory; | |
| 27 | import org.apache.lucene.store.IndexInput; | |
| 28 | import org.apache.lucene.store.FSDirectory; | |
| 29 | import org.apache.lucene.store._TestHelper; | |
| 30 | ||
| 31 | ||
| 32 | /** | |
| 33 | * @author dmitrys@earthlink.net | |
| 34 | * @version $Id: TestCompoundFile.java 382499 2006-03-02 20:16:49Z cutting $ | |
| 35 | */ | |
| 36 | public class TestCompoundFile extends TestCase | |
| 37 | { | |
| 38 | /** Main for running test case by itself. */ | |
| 39 | 0 |
public static void main(String args[]) { |
| 40 | 0 | TestRunner.run (new TestSuite(TestCompoundFile.class)); |
| 41 | // TestRunner.run (new TestCompoundFile("testSingleFile")); | |
| 42 | // TestRunner.run (new TestCompoundFile("testTwoFiles")); | |
| 43 | // TestRunner.run (new TestCompoundFile("testRandomFiles")); | |
| 44 | // TestRunner.run (new TestCompoundFile("testClonedStreamsClosing")); | |
| 45 | // TestRunner.run (new TestCompoundFile("testReadAfterClose")); | |
| 46 | // TestRunner.run (new TestCompoundFile("testRandomAccess")); | |
| 47 | // TestRunner.run (new TestCompoundFile("testRandomAccessClones")); | |
| 48 | // TestRunner.run (new TestCompoundFile("testFileNotFound")); | |
| 49 | // TestRunner.run (new TestCompoundFile("testReadPastEOF")); | |
| 50 | ||
| 51 | // TestRunner.run (new TestCompoundFile("testIWCreate")); | |
| 52 | ||
| 53 | } | |
| 54 | ||
| 55 | ||
| 56 | private Directory dir; | |
| 57 | ||
| 58 | ||
| 59 | 10 |
public void setUp() throws IOException { |
| 60 | //dir = new RAMDirectory(); | |
| 61 | 10 | dir = FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"), true); |
| 62 | } | |
| 63 | ||
| 64 | ||
| 65 | /** Creates a file of the specified size with random data. */ | |
| 66 | 14 |
private void createRandomFile(Directory dir, String name, int size) |
| 67 | throws IOException | |
| 68 | { | |
| 69 | 14 | IndexOutput os = dir.createOutput(name); |
| 70 | 1036614 | for (int i=0; i<size; i++) { |
| 71 | 1036600 | byte b = (byte) (Math.random() * 256); |
| 72 | 1036600 | os.writeByte(b); |
| 73 | } | |
| 74 | 14 | os.close(); |
| 75 | } | |
| 76 | ||
| 77 | /** Creates a file of the specified size with sequential data. The first | |
| 78 | * byte is written as the start byte provided. All subsequent bytes are | |
| 79 | * computed as start + offset where offset is the number of the byte. | |
| 80 | */ | |
| 81 | 106 |
private void createSequenceFile(Directory dir, |
| 82 | String name, | |
| 83 | byte start, | |
| 84 | int size) | |
| 85 | throws IOException | |
| 86 | { | |
| 87 | 106 | IndexOutput os = dir.createOutput(name); |
| 88 | 200346 | for (int i=0; i < size; i++) { |
| 89 | 200240 | os.writeByte(start); |
| 90 | 200240 | start ++; |
| 91 | } | |
| 92 | 106 | os.close(); |
| 93 | } | |
| 94 | ||
| 95 | ||
| 96 | 78 |
private void assertSameStreams(String msg, |
| 97 | IndexInput expected, | |
| 98 | IndexInput test) | |
| 99 | throws IOException | |
| 100 | { | |
| 101 | 78 | assertNotNull(msg + " null expected", expected); |
| 102 | 78 | assertNotNull(msg + " null test", test); |
| 103 | 78 | assertEquals(msg + " length", expected.length(), test.length()); |
| 104 | 78 | assertEquals(msg + " position", expected.getFilePointer(), |
| 105 | test.getFilePointer()); | |
| 106 | ||
| 107 | 78 | byte expectedBuffer[] = new byte[512]; |
| 108 | 78 | byte testBuffer[] = new byte[expectedBuffer.length]; |
| 109 | ||
| 110 | 78 | long remainder = expected.length() - expected.getFilePointer(); |
| 111 | 5208 | while(remainder > 0) { |
| 112 | 5130 | int readLen = (int) Math.min(remainder, expectedBuffer.length); |
| 113 | 5130 | expected.readBytes(expectedBuffer, 0, readLen); |
| 114 | 5130 | test.readBytes(testBuffer, 0, readLen); |
| 115 | 5130 | assertEqualArrays(msg + ", remainder " + remainder, expectedBuffer, |
| 116 | testBuffer, 0, readLen); | |
| 117 | 5130 | remainder -= readLen; |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | ||
| 122 | 102 |
private void assertSameStreams(String msg, |
| 123 | IndexInput expected, | |
| 124 | IndexInput actual, | |
| 125 | long seekTo) | |
| 126 | throws IOException | |
| 127 | { | |