public TemporaryFolder temp = new TemporaryFolder();
@Test
public void testBuildNamespaceRecordFile() throws IOException {
recfile = temp.newFile("ns.rec");
final NamespaceRecordFile record = new NamespaceRecordFile(recfile,
RecordMode.READ_WRITE,
new NamespaceRecord(14));
assertThat(record, is(notNullValue()));
// write namespace records
final int enc = 4;
for (int i = 0, n = 20000; i < n; i++) {
final String val = randomValue(10);
final NamespaceEntry entry = new NamespaceEntry(computeHash64(val),
enc, val);
// write entry to record file
try {
record.append(entry);
} catch (IOException e) {
e.printStackTrace();
fail("Did not expect IOException when writing record.");
}
assertThat(record.getRecordCount(), is((long) i + 1));
}
// read namespace records
// TODO assert the entry data
NamespaceEntry entry5000 = record.readEntry(5000);
assertThat(entry5000, is(notNullValue()));
NamespaceEntry entry10000 = record.readEntry(10000);
assertThat(entry10000, is(notNullValue()));
NamespaceEntry entry15000 = record.readEntry(15000);
assertThat(entry15000, is(notNullValue()));
// iterate namespace records
Iterator<byte[]> nsit = record.iterator();
int count = 0;
while (nsit.hasNext()) {
byte[] recbytes = nsit.next();
assertThat(recbytes, is(notNullValue()));
assertThat(recbytes.length, is(14));