mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-24 21:13:50 +00:00
added a test case that checks DistanceCache size limitation
This commit is contained in:
1 parent
6ccd510c79
commit
5fd68c922c
2 files changed
+14
-3
No files matched your search
@@ -917,7 +917,14 @@ public class TrackTest {
|
||||
final Duration raceDuration = Duration.ONE_HOUR.times(48);
|
||||
final Speed speed = new KnotSpeedImpl(12);
|
||||
final Distance distancePerSample = speed.travel(fixTime, fixTime.plus(samplingInterval));
|
||||
DynamicGPSFixTrack<Object, GPSFix> track = new DynamicGPSFixTrackImpl<Object>(new Object(), /* millisecondsOverWhichToAverage */ 30000l);
|
||||
final DistanceCache distanceCache = new DistanceCache("test-DistanceCache");
|
||||
DynamicGPSFixTrack<Object, GPSFix> track = new DynamicGPSFixTrackImpl<Object>(new Object(), /* millisecondsOverWhichToAverage */ 30000l) {
|
||||
private static final long serialVersionUID = -7277196393160609503L;
|
||||
@Override
|
||||
protected DistanceCache getDistanceCache() {
|
||||
return distanceCache;
|
||||
}
|
||||
};
|
||||
while (fixTime.before(start.plus(raceDuration))) {
|
||||
for (int i=0; i<transmissionInterval.divide(samplingInterval); i++) {
|
||||
// produce a bulk of fixes
|
||||
@@ -935,7 +942,7 @@ public class TrackTest {
|
||||
queryTime = queryTime.plus(queryInterval);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
assertTrue(distanceCache.size() <= DistanceCache.MAX_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-1
@@ -71,7 +71,7 @@ import com.sap.sse.util.impl.ArrayListNavigableSet;
|
||||
* @author Axel Uhl (D043530)
|
||||
*/
|
||||
public class DistanceCache {
|
||||
private static final int MAX_SIZE = 100;
|
||||
public static final int MAX_SIZE = 100;
|
||||
|
||||
private final NavigableSet<Util.Pair<TimePoint, NavigableSet<Util.Pair<TimePoint, Distance>>>> distanceCache;
|
||||
|
||||
@@ -122,6 +122,10 @@ public class DistanceCache {
|
||||
};
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return lruCache.size();
|
||||
}
|
||||
|
||||
private void removeCacheEntry(TimePoint from, TimePoint to) {
|
||||
assert lock.getWriteHoldCount() == 1; // we can be sure we are alone here; this only happens when adding a new entry, holding the write lock
|
||||
Util.Pair<TimePoint, NavigableSet<Util.Pair<TimePoint, Distance>>> entryForTo = distanceCache.floor(createDummy(to));
|
||||
|
||||
Reference in new issue
Block a user