test which verifies the dates in each file are monotonically increasing
This commit is contained in:
@@ -34,7 +34,6 @@ class PdbWriter implements AutoCloseable {
|
||||
}
|
||||
|
||||
public void write(final Entry entry) throws WriteException {
|
||||
// System.out.println(entry);
|
||||
write(entry.getEpochMilli(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -81,6 +80,14 @@ class PdbWriter implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeEntry(final PdbFile pdbFile, final Entry... entries) throws IOException {
|
||||
try (PdbWriter writer = new PdbWriter(pdbFile)) {
|
||||
for (final Entry entry : entries) {
|
||||
writer.write(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
outputStream.flush();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.time.ZoneOffset;
|
||||
|
||||
import org.lucares.ludb.FieldType;
|
||||
import org.lucares.ludb.H2DB;
|
||||
import org.lucares.pdb.api.Entry;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
@@ -70,4 +71,47 @@ public class TagsToFilesTest {
|
||||
Assert.assertEquals(fileForDay1, existingFileForDay1);
|
||||
}
|
||||
}
|
||||
|
||||
public void testNewFileIfDateIsTooOld() throws Exception {
|
||||
|
||||
try (H2DB db = new H2DB(new File(dataDirectory.toFile(), "lu.db"))) {
|
||||
db.createField(Fields.DATE_OFFSET, FieldType.STRING);
|
||||
|
||||
final TagsToFile tagsToFile = new TagsToFile(dataDirectory, db);
|
||||
|
||||
final OffsetDateTime afternoon = DateUtils.getDate(2016, 1, 1, 13, 1, 1);
|
||||
final OffsetDateTime morning = DateUtils.getDate(2016, 1, 1, 12, 1, 1);
|
||||
|
||||
final Tags tags = Tags.create("myKey", "myValue");
|
||||
|
||||
final PdbFile fileAfternoon = tagsToFile.getFile(afternoon, tags);
|
||||
PdbWriter.writeEntry(fileAfternoon, new Entry(afternoon, 1, tags));
|
||||
|
||||
final PdbFile fileMorning = tagsToFile.getFile(morning, tags);
|
||||
|
||||
Assert.assertNotEquals(fileAfternoon, fileMorning);
|
||||
}
|
||||
}
|
||||
|
||||
public void testIdenticalDatesGoIntoSameFile() throws Exception {
|
||||
|
||||
try (H2DB db = new H2DB(new File(dataDirectory.toFile(), "lu.db"))) {
|
||||
db.createField(Fields.DATE_OFFSET, FieldType.STRING);
|
||||
|
||||
final TagsToFile tagsToFile = new TagsToFile(dataDirectory, db);
|
||||
|
||||
final OffsetDateTime timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1);
|
||||
|
||||
final Tags tags = Tags.create("myKey", "myValue");
|
||||
|
||||
final PdbFile fileA = tagsToFile.getFile(timestamp, tags);
|
||||
PdbWriter.writeEntry(fileA, new Entry(timestamp, 1, tags));
|
||||
|
||||
final PdbFile fileB = tagsToFile.getFile(timestamp, tags);
|
||||
PdbWriter.writeEntry(fileA, new Entry(timestamp, 2, tags));
|
||||
|
||||
Assert.assertEquals(fileA, fileB);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user