use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ATimeSeriesDBTest method testGetPreviousAndNextSkipFile.
@Test
public void testGetPreviousAndNextSkipFile() throws IncompleteUpdateFoundException {
final String key = "asdf";
final ATimeSeriesDB<String, FDate> table = new ATimeSeriesDB<String, FDate>("testGetPreviousSkipFile") {
@Override
protected ISerde<FDate> newValueSerde() {
return new TypeDelegateSerde<FDate>(FDate.class);
}
@Override
protected Integer newValueFixedLength() {
return null;
}
@Override
protected String innerHashKeyToString(final String key) {
return key;
}
@Override
protected FDate extractEndTime(final FDate value) {
return value;
}
@Override
protected File getBaseDirectory() {
return ContextProperties.TEMP_DIRECTORY;
}
};
final List<FDate> dates = new ArrayList<>();
for (int i = 0; i < 100_000; i++) {
dates.add(new FDate(i));
}
final MutableInt segments = new MutableInt();
new ATimeSeriesUpdater<String, FDate>(key, table) {
@Override
protected ICloseableIterable<? extends FDate> getSource(final FDate updateFrom) {
return WrapperCloseableIterable.maybeWrap(dates);
}
@Override
protected void onUpdateFinished(final Instant updateStart) {
}
@Override
protected void onUpdateStart() {
}
@Override
protected FDate extractEndTime(final FDate element) {
return element;
}
@Override
protected void onFlush(final int flushIndex, final ATimeSeriesUpdater<String, FDate>.UpdateProgress updateProgress) {
segments.increment();
}
@Override
public Percent getProgress() {
return null;
}
}.update();
Assertions.assertThat(segments.intValue()).isEqualByComparingTo(10);
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(dates.size() - i - 1);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getPreviousValue(key, dates.get(dates.size() - 1), i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(dates.size() - i - 1);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getPreviousValue(key, FDate.MAX_DATE, i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(0);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getPreviousValue(key, FDate.MIN_DATE, i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(i);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getNextValue(key, dates.get(0), i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(i);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getNextValue(key, FDate.MIN_DATE, i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
for (int i = 0; i < dates.size(); i += ATimeSeriesUpdater.BATCH_FLUSH_INTERVAL) {
final FDate expectedValue = dates.get(dates.size() - 1);
final long expectedIndex = expectedValue.millisValue();
final FDate value = table.getNextValue(key, FDate.MAX_DATE, i);
final long valueIndex = value.millisValue();
Assertions.checkEquals(valueIndex, expectedIndex, i + ": expected [" + expectedIndex + "] got [" + valueIndex + "]");
}
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class TimeseriesDBPerformanceTest method readGetLatest.
private void readGetLatest(final ATimeSeriesDB<String, FDate> table, final String suffix, final long countReads) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
for (long reads = 1; reads <= countReads; reads++) {
FDate prevValue = null;
for (int i = 0; i < values.size(); i++) {
try {
final FDate value = table.getLatestValue(HASH_KEY, values.get(i));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
} catch (final NoSuchElementException e) {
break;
}
}
if (loopCheck.check()) {
printProgress("GetLatests" + suffix, readsStart, VALUES * reads, VALUES * countReads);
}
}
printProgress("GetLatests" + suffix + "Finished", readsStart, VALUES * countReads, VALUES * countReads);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class HsqldbPerformanceTest method readIterator.
private void readIterator(final Connection conn) throws Exception {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Instant readsStart = new Instant();
final Statement select = conn.createStatement();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
int count = 0;
try (ResultSet results = select.executeQuery("SELECT value FROM abc ORDER BY KEY ASC")) {
while (results.next()) {
final FDate value = new FDate(results.getLong(1));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class HsqldbPerformanceTest method testHsqldbPerformance.
@Test
public void testHsqldbPerformance() throws Exception {
final File directory = new File(ContextProperties.getCacheDirectory(), HsqldbPerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdirParent(directory);
final Instant writesStart = new Instant();
int i = 0;
Class.forName("org.hsqldb.jdbc.JDBCDriver");
final Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + directory.getAbsolutePath(), "SA", "");
final Statement create = conn.createStatement();
create.execute("DROP TABLE abc IF EXISTS");
create.execute("CREATE TABLE abc (key BIGINT, value BIGINT, PRIMARY KEY(key))");
create.execute("CREATE UNIQUE INDEX idx_abc on abc (key)");
create.close();
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Statement tx = conn.createStatement();
tx.execute("START TRANSACTION");
final PreparedStatement insert = conn.prepareStatement("INSERT INTO abc VALUES (?,?)");
boolean batch = false;
for (final FDate date : newValues()) {
final long value = date.longValue(FTimeUnit.MILLISECONDS);
insert.setLong(1, value);
insert.setLong(2, value);
insert.addBatch();
i++;
batch = true;
if (i % FLUSH_INTERVAL == 0) {
insert.executeBatch();
batch = false;
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
}
}
if (batch) {
insert.executeBatch();
}
insert.close();
tx.execute("COMMIT");
printProgress("WritesFinished", writesStart, VALUES, VALUES);
tx.close();
readIterator(conn);
readGet(conn);
readGetLatest(conn);
final Statement drop = conn.createStatement();
drop.execute("drop table abc");
drop.close();
Files.deleteNative(directory);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class SqlitePerformanceTest method testSQLitePerformance.
@Test
public void testSQLitePerformance() throws Exception {
final File directory = new File(ContextProperties.getCacheDirectory(), SqlitePerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdirParent(directory);
final Instant writesStart = new Instant();
int i = 0;
Class.forName("org.sqlite.JDBC");
final Connection conn = DriverManager.getConnection("jdbc:sqlite:" + directory.getAbsolutePath());
final Statement create = conn.createStatement();
create.execute("DROP TABLE IF EXISTS abc");
create.execute("CREATE TABLE abc (key LONG, value LONG, PRIMARY KEY(key))");
create.execute("CREATE UNIQUE INDEX idx_abc on abc (key)");
create.close();
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Statement tx = conn.createStatement();
tx.execute("BEGIN TRANSACTION");
final PreparedStatement insert = conn.prepareStatement("INSERT INTO abc VALUES (?,?)");
for (final FDate date : newValues()) {
final long value = date.longValue(FTimeUnit.MILLISECONDS);
insert.setLong(1, value);
insert.setLong(2, value);
insert.addBatch();
i++;
if (i % FLUSH_INTERVAL == 0) {
insert.executeBatch();
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
}
}
insert.executeBatch();
insert.close();
tx.execute("COMMIT");
printProgress("WritesFinished", writesStart, VALUES, VALUES);
tx.close();
readIterator(conn);
readGet(conn);
readGetLatest(conn);
final Statement drop = conn.createStatement();
drop.execute("drop table abc");
drop.close();
Files.deleteNative(directory);
}
Aggregations