fixed test cases that require 0 cache invalidation timeout

This commit is contained in:
Axel Uhl committed 2012-04-25 22:50:12 +02:00
1 parent 2b248df21e
commit d53c576b42
11 files changed
+34 -32

No files matched your search

@@ -74,7 +74,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
@Override
public void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource) {
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
windTrack.addListener(new MongoWindListener(trackedEvent, trackedRace, windSource, this, database));
}
@@ -79,12 +79,13 @@ public abstract class TrackBasedTest {
/* delay for wind estimation cache invalidation */ 0);
// in this simplified artificial course, the top mark is exactly north of the right leeward gate
DegreePosition topPosition = new DegreePosition(54.48, 10.24);
TimePoint afterTheRace = new MillisecondsTimePoint(timePointForFixes.asMillis() + 36000000); // 10h after the fix time
trackedRace.getOrCreateTrack(left).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.234451), new MillisecondsTimePoint(0)));
trackedRace.getOrCreateTrack(right).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.24), new MillisecondsTimePoint(0)));
trackedRace.getOrCreateTrack(windwardMark).addGPSFix(new GPSFixImpl(topPosition, new MillisecondsTimePoint(0)));
trackedRace.getOrCreateTrack(left).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.234451), MillisecondsTimePoint.now()));
trackedRace.getOrCreateTrack(right).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.24), MillisecondsTimePoint.now()));
trackedRace.getOrCreateTrack(windwardMark).addGPSFix(new GPSFixImpl(topPosition, MillisecondsTimePoint.now()));
trackedRace.getOrCreateTrack(left).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.234451), afterTheRace));
trackedRace.getOrCreateTrack(right).addGPSFix(new GPSFixImpl(new DegreePosition(54.4680424, 10.24), afterTheRace));
trackedRace.getOrCreateTrack(windwardMark).addGPSFix(new GPSFixImpl(topPosition, afterTheRace));
trackedRace.recordWind(new WindImpl(topPosition, timePointForFixes, new KnotSpeedWithBearingImpl(
/* speedInKnots */14.7, new DegreeBearingImpl(180))), new WindSourceImpl(WindSourceType.WEB));
return trackedRace;
@@ -116,7 +116,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
MillisecondsTimePoint now = new MillisecondsTimePoint(new GregorianCalendar(2012, 03, 14).getTime());
getTrackedRace().recordWind(new WindImpl(null, now, new KnotSpeedWithBearingImpl(/* speedInKnots */ 12, new DegreeBearingImpl(180.))),
new WindSourceImpl(WindSourceType.WEB));
// produces estimated bearing of 170deg; result should be averaged between 107 (estimation) and 180 (web) deg
// produces estimated bearing of 170deg; result should be averaged between 170 (estimation) and 180 (web) deg
setBearingForCompetitor(competitors.get(0), now, 305);
setBearingForCompetitor(competitors.get(1), now, 35);
WindWithConfidence<Pair<Position, TimePoint>> combinedWindDirectionMinClusterSizeOne = getTrackedRace()
@@ -155,7 +155,7 @@ public class MockedTrackedRace implements DynamicTrackedRace {
}
@Override
public WindTrack getOrCreateWindTrack(WindSource windSource) {
public WindTrack getOrCreateWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) {
// TODO Auto-generated method stub
return null;
}
@@ -209,7 +209,7 @@ public interface TrackedRace extends Serializable {
*/
Iterable<WindSource> getWindSources();
WindTrack getOrCreateWindTrack(WindSource windSource);
WindTrack getOrCreateWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation);
/**
* Waits until {@link #getUpdateCount()} is after <code>sinceUpdate</code>.
@@ -1,7 +1,7 @@
package com.sap.sailing.domain.tracking;
/**
* Receives wind information and forwards it to a {@link TrackedRace}'s {@link TrackedRace#getOrCreateWindTrack(WindSource) wind
* Receives wind information and forwards it to a {@link TrackedRace}'s {@link TrackedRace#getOrCreateWindTrack(WindSource, long) wind
* track}.
*
* @author Axel Uhl (D043530)
@@ -77,7 +77,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
for (WindSource windSource : getWindSources()) {
getOrCreateWindTrack(windSource).addListener(this);
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).addListener(this);
}
}
@@ -118,7 +118,8 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
public void setMillisecondsOverWhichToAverageWind(long millisecondsOverWhichToAverageWind) {
this.millisecondsOverWhichToAverageWind = millisecondsOverWhichToAverageWind;
for (WindSource windSource : getWindSources()) {
getOrCreateWindTrack(windSource).setMillisecondsOverWhichToAverage(millisecondsOverWhichToAverageWind);
getOrCreateWindTrack(windSource, millisecondsOverWhichToAverageWind/2).
setMillisecondsOverWhichToAverage(millisecondsOverWhichToAverageWind);
}
updated(MillisecondsTimePoint.now());
}
@@ -370,21 +371,21 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
* In addition to calling the super class implementation, adds this tracked race as a listener for the wind track.
*/
@Override
protected WindTrack createWindTrack(WindSource windSource) {
WindTrack result = super.createWindTrack(windSource);
protected WindTrack createWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) {
WindTrack result = super.createWindTrack(windSource, delayForWindEstimationCacheInvalidation);
result.addListener(this);
return result;
}
@Override
public synchronized void recordWind(Wind wind, WindSource windSource) {
getOrCreateWindTrack(windSource).add(wind);
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).add(wind);
updated(null); // wind events shouldn't advance race time
}
@Override
public synchronized void removeWind(Wind wind, WindSource windSource) {
getOrCreateWindTrack(windSource).remove(wind);
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).remove(wind);
updated(wind.getTimePoint());
}
@@ -435,7 +436,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
public long getMillisecondsOverWhichToAverageWind() {
long result = 0; // default in case there is no competitor
for (WindSource windSource : getWindSources()) {
WindTrack someTrack = getOrCreateWindTrack(windSource);
WindTrack someTrack = getOrCreateWindTrack(windSource, 0);
result = someTrack.getMillisecondsOverWhichToAverageWind();
}
return result;
@@ -246,9 +246,9 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
// one "WEB" track for manual or REST-based wind reception; other wind tracks may be added as fixes are received
// for them.
WindSource courseBasedWindSource = new WindSourceImpl(WindSourceType.COURSE_BASED);
windTracks.put(courseBasedWindSource, getOrCreateWindTrack(courseBasedWindSource));
windTracks.put(courseBasedWindSource, getOrCreateWindTrack(courseBasedWindSource, delayForWindEstimationCacheInvalidation));
WindSource trackBasedWindSource = new WindSourceImpl(WindSourceType.TRACK_BASED_ESTIMATION);
windTracks.put(trackBasedWindSource, getOrCreateWindTrack(trackBasedWindSource));
windTracks.put(trackBasedWindSource, getOrCreateWindTrack(trackBasedWindSource, delayForWindEstimationCacheInvalidation));
this.trackedEvent = trackedEvent;
competitorRankings = new HashMap<TimePoint, List<Competitor>>();
}
@@ -752,11 +752,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
* which will not be added to {@link #windTracks} and will not lead to the wind source being listed in
* {@link #getWindSources()} or {@link #getWindSources(WindSourceType)}. For all other wind sources, checks
* {@link #windTracks} for the respective source. If found, it's returned; otherwise the wind track is created
* through the {@link #windStore} using {@link #createWindTrack(WindSource)} and added to {@link #windTracks} before
* through the {@link #windStore} using {@link #createWindTrack(WindSource, long)} and added to {@link #windTracks} before
* being returned.
*/
@Override
public WindTrack getOrCreateWindTrack(WindSource windSource) {
public WindTrack getOrCreateWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) {
WindTrack result;
if (windSource.getType() == WindSourceType.COMBINED) {
result = new CombinedWindTrackImpl(this, WindSourceType.COMBINED.getBaseConfidence());
@@ -764,7 +764,7 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
synchronized (windTracks) {
result = windTracks.get(windSource);
if (result == null) {
result = createWindTrack(windSource);
result = createWindTrack(windSource, delayForWindEstimationCacheInvalidation);
windTracks.put(windSource, result);
}
}
@@ -777,9 +777,9 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
* averaging interval is set according to the averaging interval set for all other wind sources, or the default if
* no other wind source exists yet.
*/
protected WindTrack createWindTrack(WindSource windSource) {
protected WindTrack createWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) {
return windStore.getWindTrack(trackedEvent, this, windSource, millisecondsOverWhichToAverageWind,
getMillisecondsOverWhichToAverageWind() / 2);
delayForWindEstimationCacheInvalidation);
}
@Override
@@ -824,7 +824,7 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
for (WindSource windSource : getWindSources()) {
// TODO consider parallelizing
if (!Util.contains(windSourcesToExclude, windSource)) {
WindTrack track = getOrCreateWindTrack(windSource);
WindTrack track = getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2);
WindWithConfidence<Pair<Position, TimePoint>> windWithConfidence = track.getAveragedWindWithConfidence(
p, at);
if (windWithConfidence != null) {
@@ -610,7 +610,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
for (WindSource windSource : windSourcesToDeliver) {
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack.getMillisecondsOverWhichToAverageWind();
Iterator<Wind> windIter = windTrack.getFixesIterator(from, /* inclusive */true);
while (windIter.hasNext()) {
@@ -705,7 +705,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
TimePoint fromTimePoint = new MillisecondsTimePoint(from);
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
windTrackInfoDTOs.put(windSource, windTrackInfoDTO);
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack
.getMillisecondsOverWhichToAverageWind();
@@ -757,7 +757,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
if (windSourceTypeNames == null || windSourceTypeNames.contains(windSource.getType().name())) {
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
windTrackInfoDTOs.put(windSource, windTrackInfoDTO);
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack
.getMillisecondsOverWhichToAverageWind();
@@ -895,7 +895,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
trackedLegOfCompetitor.getLeg()).getLegType(fix.getTimePoint());
GPSFixDTO fixDTO = createGPSFixDTO(fix, fix.getSpeed(), createWindDTOFromAlreadyAveraged(trackedRace.getWind(fix.getPosition(),
toTimePointExcluding), trackedRace
.getOrCreateWindTrack(windSource)), tack, legType, /* extrapolate */
.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), tack, legType, /* extrapolate */
false);
fixesForCompetitor.add(fixDTO);
if (fixIter.hasNext()) {
@@ -915,7 +915,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
createSpeedWithBearingDTO(speedWithBearing),
createWindDTOFromAlreadyAveraged(trackedRace.getWind(position,
toTimePointExcluding), trackedRace
.getOrCreateWindTrack(windSource)), /* extrapolated */
.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), /* extrapolated */
tack2, legType2, true);
fixesForCompetitor.add(extrapolated);
}
@@ -1588,7 +1588,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
trackedLegOfCompetitor.getLeg()).getLegType(fix.getTimePoint());
GPSFixDTO fixDTO = createGPSFixDTO(fix, speedWithBearing, createWindDTOFromAlreadyAveraged(trackedRace.getWind(
fix.getPosition(), fix.getTimePoint()),
trackedRace.getOrCreateWindTrack(windSource)), tack, legType, /* extrapolated */false);
trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), tack, legType, /* extrapolated */false);
gpsFixDouglasList.add(fixDTO);
}
result.put(competitorDTO, gpsFixDouglasList);
@@ -91,7 +91,7 @@ public class TestStoringAndRetrievingWindTracksTest extends AbstractTracTracLive
Mongo myFirstMongo = newMongo();
DB firstDatabase = myFirstMongo.getDB(dbConfiguration.getDatabaseName());
new MongoObjectFactoryImpl(firstDatabase).addWindTrackDumper(trackedEvent, trackedRace, windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
Position pos = new DegreePosition(54, 9);
TimePoint timePoint = MillisecondsTimePoint.now();
for (double bearingDeg = 123.4; bearingDeg<140; bearingDeg += 1.1) {
@@ -262,7 +262,7 @@ public class AdminApp extends Servlet {
JSONObject jsonWindTracks = new JSONObject();
for (WindSource windSource : trackedRace.getWindSources()) {
JSONArray jsonWindArray = new JSONArray();
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
synchronized (windTrack) {
Iterator<Wind> windIter = windTrack.getFixesIterator(from, /* inclusive */true);
while (windIter.hasNext()) {
@@ -370,7 +370,7 @@ public class AdminApp extends Servlet {
try {
final DynamicTrackedRace trackedRace = getService().getOrCreateTrackedEvent(event)
.getTrackedRace(race);
WindTrack windTrack = trackedRace.getOrCreateWindTrack(trackedRace.getWindSources(windSourceType).iterator().next());
WindTrack windTrack = trackedRace.getOrCreateWindTrack(trackedRace.getWindSources(windSourceType).iterator().next(), delayForWindEstimationCacheInvalidation);
TimePoint timePoint = getTimePoint(req, PARAM_NAME_TIME, PARAM_NAME_TIME_MILLIS,
MillisecondsTimePoint.now());
Wind wind = windTrack.getLastFixAtOrBefore(timePoint);