| 1 |
|
package org.apache.lucene; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import org.apache.lucene.store.Directory; |
| 20 |
|
import org.apache.lucene.store.IndexInput; |
| 21 |
|
import org.apache.lucene.store.IndexOutput; |
| 22 |
|
import org.apache.lucene.store.FSDirectory; |
| 23 |
|
import org.apache.lucene.store.RAMDirectory; |
| 24 |
|
|
| 25 |
|
import java.util.Date; |
| 26 |
|
import java.util.Random; |
| 27 |
|
|
|
|
|
| 0% |
Uncovered Elements: 94 (94) |
Complexity: 17 |
Complexity Density: 0.27 |
|
| 28 |
|
class StoreTest { |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 29 |
0
|
public static void main(String[] args) {... |
| 30 |
0
|
try { |
| 31 |
0
|
test(1000, true, true); |
| 32 |
|
} catch (Exception e) { |
| 33 |
0
|
e.printStackTrace(); |
| 34 |
|
} |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 89 (89) |
Complexity: 15 |
Complexity Density: 0.25 |
|
| 37 |
0
|
public static void test(int count, boolean ram, boolean buffered)... |
| 38 |
|
throws Exception { |
| 39 |
0
|
Random gen = new Random(1251971); |
| 40 |
0
|
int i; |
| 41 |
|
|
| 42 |
0
|
Date veryStart = new Date(); |
| 43 |
0
|
Date start = new Date(); |
| 44 |
|
|
| 45 |
0
|
Directory store; |
| 46 |
0
|
if (ram) |
| 47 |
0
|
store = new RAMDirectory(); |
| 48 |
|
else |
| 49 |
0
|
store = FSDirectory.getDirectory("test.store", true); |
| 50 |
|
|
| 51 |
0
|
final int LENGTH_MASK = 0xFFF; |
| 52 |
|
|
| 53 |
0
|
final byte[] buffer = new byte[LENGTH_MASK]; |
| 54 |
|
|
| 55 |
0
|
for (i = 0; i < count; i++) { |
| 56 |
0
|
String name = i + ".dat"; |
| 57 |
0
|
int length = gen.nextInt() & LENGTH_MASK; |
| 58 |
0
|
byte b = (byte)(gen.nextInt() & 0x7F); |
| 59 |
|
|
| 60 |
|
|
| 61 |
0
|
IndexOutput file = store.createOutput(name); |
| 62 |
|
|
| 63 |
0
|
if (buffered) { |
| 64 |
0
|
for (int j = 0; j < length; j++) |
| 65 |
0
|
buffer[j] = b; |
| 66 |
0
|
file.writeBytes(buffer, length); |
| 67 |
|
} else { |
| 68 |
0
|
for (int j = 0; j < length; j++) |
| 69 |
0
|
file.writeByte(b); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
0
|
file.close(); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
0
|
store.close(); |
| 76 |
|
|
| 77 |
0
|
Date end = new Date(); |
| 78 |
|
|
| 79 |
0
|
System.out.print(end.getTime() - start.getTime()); |
| 80 |
0
|
System.out.println(" total milliseconds to create"); |
| 81 |
|
|
| 82 |
0
|
gen = new Random(1251971); |
| 83 |
0
|
start = new Date(); |
| 84 |
|
|
| 85 |
0
|
if (!ram) |
| 86 |
0
|
store = FSDirectory.getDirectory("test.store", false); |
| 87 |
|
|
| 88 |
0
|
for (i = 0; i < count; i++) { |
| 89 |
0
|
String name = i + ".dat"; |
| 90 |
0
|
int length = gen.nextInt() & LENGTH_MASK; |
| 91 |
0
|
byte b = (byte)(gen.nextInt() & 0x7F); |
| 92 |
|
|
| 93 |
|
|
| 94 |
0
|
IndexInput file = store.openInput(name); |
| 95 |
|
|
| 96 |
0
|
if (file.length() != length) |
| 97 |
0
|
throw new Exception("length incorrect"); |
| 98 |
|
|
| 99 |
0
|
byte[] content = new byte[length]; |
| 100 |
0
|
if (buffered) { |
| 101 |
0
|
file.readBytes(content, 0, length); |
| 102 |
|
|
| 103 |
0
|
for (int j = 0; j < length; j++) |
| 104 |
0
|
if (content[j] != b) |
| 105 |
0
|
throw new Exception("contents incorrect"); |
| 106 |
|
} else { |
| 107 |
0
|
for (int j = 0; j < length; j++) |
| 108 |
0
|
if (file.readByte() != b) |
| 109 |
0
|
throw new Exception("contents incorrect"); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
0
|
file.close(); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
0
|
end = new Date(); |
| 116 |
|
|
| 117 |
0
|
System.out.print(end.getTime() - start.getTime()); |
| 118 |
0
|
System.out.println(" total milliseconds to read"); |
| 119 |
|
|
| 120 |
0
|
gen = new Random(1251971); |
| 121 |
0
|
start = new Date(); |
| 122 |
|
|
| 123 |
0
|
for (i = 0; i < count; i++) { |
| 124 |
0
|
String name = i + ".dat"; |
| 125 |
|
|
| 126 |
0
|
store.deleteFile(name); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
0
|
end = new Date(); |
| 130 |
|
|
| 131 |
0
|
System.out.print(end.getTime() - start.getTime()); |
| 132 |
0
|
System.out.println(" total milliseconds to delete"); |
| 133 |
|
|
| 134 |
0
|
System.out.print(end.getTime() - veryStart.getTime()); |
| 135 |
0
|
System.out.println(" total milliseconds"); |
| 136 |
|
|
| 137 |
0
|
store.close(); |
| 138 |
|
} |
| 139 |
|
} |