Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../img/srcFileCovDistChart0.png 86% of files have more coverage
64   139   17   32
28   89   0.27   2
2     8.5  
1    
 
  StoreTest       Line # 28 64 17 0% 0.0
 
No Tests
 
1    package org.apache.lucene;
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 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   
 
28    class StoreTest {
 
29  0 toggle 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   
 
37  0 toggle 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    //System.out.println("filling " + name + " with " + length + " of " + b);
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    //System.out.println("reading " + name + " with " + length + " of " + b);
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    // check the buffer
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    //System.out.println("deleting " + name);
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    }