| 1 |
|
package org.apache.lucene.store; |
| 2 |
|
|
| 3 |
|
import java.io.IOException; |
| 4 |
|
|
| 5 |
|
import junit.framework.TestCase; |
| 6 |
|
|
|
|
|
| 94.7% |
Uncovered Elements: 3 (57) |
Complexity: 13 |
Complexity Density: 0.32 |
|
| 7 |
|
public class TestBufferedIndexInput extends TestCase { |
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 12 |
1
|
public void testReadByte() throws Exception {... |
| 13 |
1
|
MyBufferedIndexInput input = new MyBufferedIndexInput(); |
| 14 |
10241
|
for(int i=0; i<BufferedIndexInput.BUFFER_SIZE*10; i++){ |
| 15 |
10240
|
assertEquals(input.readByte(), byten(i)); |
| 16 |
|
} |
| 17 |
|
} |
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.29 |
1
PASS
|
|
| 23 |
1
|
public void testReadBytes() throws Exception {... |
| 24 |
1
|
MyBufferedIndexInput input = new MyBufferedIndexInput(); |
| 25 |
1
|
int pos=0; |
| 26 |
|
|
| 27 |
906
|
for(int size=1; size<BufferedIndexInput.BUFFER_SIZE*10; size=size+size/200+1){ |
| 28 |
905
|
checkReadBytes(input, size, pos); |
| 29 |
905
|
pos+=size; |
| 30 |
|
} |
| 31 |
|
|
| 32 |
1001
|
for(long i=0; i<1000; i++){ |
| 33 |
|
|
| 34 |
|
|
| 35 |
1000
|
int size1 = (int)( i%7 + 7*(i%5)+ 7*5*(i%3) + 5*5*3*(i%2)); |
| 36 |
1000
|
int size2 = (int)( i%11 + 11*(i%7)+ 11*7*(i%5) + 11*7*5*(i%3) + 11*7*5*3*(i%2) ); |
| 37 |
1000
|
int size = (i%3==0)?size2*10:size1; |
| 38 |
1000
|
checkReadBytes(input, size, pos); |
| 39 |
1000
|
pos+=size; |
| 40 |
|
} |
| 41 |
|
|
| 42 |
1025
|
for(int i=0; i<BufferedIndexInput.BUFFER_SIZE; i++){ |
| 43 |
1024
|
checkReadBytes(input, 7, pos); |
| 44 |
1024
|
pos+=7; |
| 45 |
|
} |
| 46 |
|
} |
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 47 |
2934
|
private void checkReadBytes(BufferedIndexInput input, int size, int pos) throws IOException{... |
| 48 |
|
|
| 49 |
|
|
| 50 |
2934
|
int offset = size % 10; |
| 51 |
2934
|
byte[] b = new byte[offset+size]; |
| 52 |
2934
|
input.readBytes(b, offset, size); |
| 53 |
4612392
|
for(int i=0; i<size; i++){ |
| 54 |
4609461
|
assertEquals(b[offset+i], byten(pos+i)); |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 4 |
Complexity Density: 0.24 |
1
PASS
|
|
| 61 |
1
|
public void testEOF() throws Exception {... |
| 62 |
1
|
MyBufferedIndexInput input = new MyBufferedIndexInput(1024); |
| 63 |
|
|
| 64 |
1
|
checkReadBytes(input, (int)input.length(), 0); |
| 65 |
|
|
| 66 |
|
|
| 67 |
1
|
int pos = (int)input.length()-10; |
| 68 |
1
|
input.seek(pos); |
| 69 |
1
|
checkReadBytes(input, 10, pos); |
| 70 |
1
|
input.seek(pos); |
| 71 |
1
|
try { |
| 72 |
1
|
checkReadBytes(input, 11, pos); |
| 73 |
0
|
fail("Block read past end of file"); |
| 74 |
|
} catch (IOException e) { |
| 75 |
|
|
| 76 |
|
} |
| 77 |
1
|
input.seek(pos); |
| 78 |
1
|
try { |
| 79 |
1
|
checkReadBytes(input, 50, pos); |
| 80 |
0
|
fail("Block read past end of file"); |
| 81 |
|
} catch (IOException e) { |
| 82 |
|
|
| 83 |
|
} |
| 84 |
1
|
input.seek(pos); |
| 85 |
1
|
try { |
| 86 |
1
|
checkReadBytes(input, 100000, pos); |
| 87 |
0
|
fail("Block read past end of file"); |
| 88 |
|
} catch (IOException e) { |
| 89 |
|
|
| 90 |
|
} |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
9239412
|
private static byte byten(long n){... |
| 96 |
9239412
|
return (byte)(n*n%256); |
| 97 |
|
} |
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 7 |
Complexity Density: 1 |
|
| 98 |
|
private static class MyBufferedIndexInput extends BufferedIndexInput { |
| 99 |
|
private long pos; |
| 100 |
|
private long len; |
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 101 |
3
|
public MyBufferedIndexInput(long len){... |
| 102 |
3
|
this.len = len; |
| 103 |
3
|
this.pos = 0; |
| 104 |
|
} |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
2
|
public MyBufferedIndexInput(){... |
| 106 |
|
|
| 107 |
2
|
this(Long.MAX_VALUE); |
| 108 |
|
} |
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 109 |
1192
|
protected void readInternal(byte[] b, int offset, int length) throws IOException {... |
| 110 |
4620903
|
for(int i=offset; i<offset+length; i++) |
| 111 |
4619711
|
b[i] = byten(pos++); |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 114 |
2
|
protected void seekInternal(long pos) throws IOException {... |
| 115 |
2
|
this.pos = pos; |
| 116 |
|
} |
| 117 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 118 |
0
|
public void close() throws IOException {... |
| 119 |
|
} |
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
1199
|
public long length() {... |
| 122 |
1199
|
return len; |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
} |