use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class CqenginePerformanceTest method readIterator.
private void readIterator(final IndexedCollection<Content> table) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
int count = 0;
final Iterator<Content> iterator = table.iterator();
try {
while (true) {
final FDate value = iterator.next().getValue();
// if (prevValue != null) {
// Assertions.checkTrue(prevValue.isBefore(value));
// }
prevValue = value;
count++;
}
} catch (final NoSuchElementException e) {
// end reached
}
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 CqenginePerformanceTest method readOrdered.
private void readOrdered(final IndexedCollection<Content> table) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
int count = 0;
try (ResultSet<Content> result = table.retrieve(QueryFactory.all(Content.class), QueryFactory.queryOptions(QueryFactory.orderBy(QueryFactory.ascending(Content.KEY))))) {
final Iterator<Content> iterator = result.iterator();
try {
while (true) {
final FDate value = iterator.next().getValue();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
} catch (final NoSuchElementException e) {
// end reached
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("ReadsOrdered", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("ReadsOrderedFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ChronicleMapPerformanceTest method readGet.
private void readGet(final ChronicleMap<Long, Long> table) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
for (int i = 0; i < values.size(); i++) {
try {
final FDate value = new FDate(table.get(values.get(i).millisValue()));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
} catch (final NoSuchElementException e) {
break;
}
}
if (loopCheck.check()) {
printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ChronicleMapPerformanceTest method testChronicleMapPerformance.
@Test
public void testChronicleMapPerformance() throws IOException, InterruptedException {
final File directory = new File(ContextProperties.getCacheDirectory(), ChronicleMapPerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdir(directory);
final Instant writesStart = new Instant();
final ChronicleMapBuilder<Long, Long> mapBuilder = ChronicleMapBuilder.of(Long.class, Long.class).name("testChronicleMapPerformance").constantKeySizeBySample(FDate.MAX_DATE.millisValue()).constantValueSizeBySample(FDate.MAX_DATE.millisValue()).entries(VALUES);
// final ChronicleMap<Long, Long> map = mapBuilder.create();
final ChronicleMap<Long, Long> map = mapBuilder.createPersistedTo(new File(directory, "testChronicleMapPerformance"));
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
int i = 0;
for (final FDate date : newValues()) {
map.put(date.millisValue(), date.millisValue());
i++;
if (i % FLUSH_INTERVAL == 0) {
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
}
}
printProgress("WritesFinished", writesStart, VALUES, VALUES);
readIterator(map);
readGet(map);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ATimeSeriesDBTest method testGetPreviousAndNext.
// CHECKSTYLE:ON
@Test
public void testGetPreviousAndNext() throws IncompleteUpdateFoundException {
final String key = "asdf";
final ATimeSeriesDB<String, FDate> table = new ATimeSeriesDB<String, FDate>("testGetPrevious") {
@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 = 2000; i <= 2010; i++) {
dates.add(FDateBuilder.newDate(i));
}
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) {
}
@Override
public Percent getProgress() {
return null;
}
}.update();
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getPreviousValue(key, dates.get(dates.size() - 1), i);
final FDate expectedValue = dates.get(dates.size() - i - 1);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getPreviousValue(key, FDate.MAX_DATE, i);
final FDate expectedValue = dates.get(dates.size() - i - 1);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getPreviousValue(key, FDate.MIN_DATE, i);
final FDate expectedValue = dates.get(0);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getNextValue(key, dates.get(0), i);
final FDate expectedValue = dates.get(i);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getNextValue(key, FDate.MIN_DATE, i);
final FDate expectedValue = dates.get(i);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 1; i < dates.size(); i++) {
final FDate value = table.getNextValue(key, FDate.MAX_DATE, i);
final FDate expectedValue = dates.get(dates.size() - 1);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
}
Aggregations