mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 02:52:22 +00:00
introduced MillisecondsTimePoint.approximateNow() and used where now() is too expensive; re-typed now() to TimePoint
This commit is contained in:
1 parent
27338ad216
commit
78ff26a17e
26 files changed
+88
-66
No files matched your search
+1
-1
@@ -35,7 +35,7 @@ import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class BarbadosResultImportTest {
|
||||
private static final MillisecondsTimePoint NOW = MillisecondsTimePoint.now();
|
||||
private static final TimePoint NOW = MillisecondsTimePoint.now();
|
||||
private static final String SAMPLE_INPUT_NAME_EMPTY_RESULTS = "RESULTS-505Barbados.xlsx";
|
||||
private static final String SAMPLE_INPUT_NAME_SOME_RESULTS = "RESULTS2.xlsx";
|
||||
private static final String RESOURCES = "resources/";
|
||||
|
||||
+3
-3
@@ -64,7 +64,7 @@ public class RaceResultOfCompetitorWithContext implements HasRaceResultOfCompeti
|
||||
@Override
|
||||
public double getRelativeRank() {
|
||||
Leaderboard leaderboard = getLeaderboard();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
double competitorCount = Util.size(leaderboard.getCompetitors());
|
||||
double points = leaderboard.getNetPoints(competitor, raceColumn, now);
|
||||
double relativeLowPoints = leaderboard.getScoringScheme().isHigherBetter() ?
|
||||
@@ -166,7 +166,7 @@ public class RaceResultOfCompetitorWithContext implements HasRaceResultOfCompeti
|
||||
@Override
|
||||
public Boolean isPodiumFinish() {
|
||||
Leaderboard leaderboard = getLeaderboard();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
double points = leaderboard.getNetPoints(competitor, raceColumn, now);
|
||||
if (leaderboard.getScoringScheme().isHigherBetter()) {
|
||||
double competitorCount = Util.size(leaderboard.getCompetitors());
|
||||
@@ -179,7 +179,7 @@ public class RaceResultOfCompetitorWithContext implements HasRaceResultOfCompeti
|
||||
@Override
|
||||
public Boolean isWin() {
|
||||
Leaderboard leaderboard = getLeaderboard();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
double points = leaderboard.getNetPoints(competitor, raceColumn, now);
|
||||
if (leaderboard.getScoringScheme().isHigherBetter()) {
|
||||
double competitorCount = Util.size(leaderboard.getCompetitors());
|
||||
|
||||
+2
-2
@@ -97,7 +97,7 @@ public class DependentStartTimeFinderTest {
|
||||
assertEquals(cAfterB, result.getStartTimeDiff());
|
||||
assertEquals(expectedDependingOnRaces, result.getRacesDependingOn());
|
||||
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
raceLogA.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, new MillisecondsTimePoint(5000)));
|
||||
|
||||
finder = new StartTimeFinder(raceLogResolver, raceLogB);
|
||||
@@ -156,7 +156,7 @@ public class DependentStartTimeFinderTest {
|
||||
assertEquals(aAfterC, finder.analyze().getStartTimeDiff());
|
||||
|
||||
// Check that all resolve correctly after changing some element in cycle
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
raceLogB.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, new MillisecondsTimePoint(5000)));
|
||||
|
||||
// now A -> C -> B
|
||||
|
||||
+3
-3
@@ -102,7 +102,7 @@ public class DependentRaceStateTest {
|
||||
raceLogB.add(new RaceLogDependentStartTimeEventImpl(nowMock, author, nowMock, "12", null, 12,
|
||||
new SimpleRaceLogIdentifierImpl("A", "", ""), new MillisecondsDurationImpl(5000)));
|
||||
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
raceLogA.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, new MillisecondsTimePoint(5000)));
|
||||
|
||||
verify(listenerC, times(3)).onStartTimeChanged(stateC);
|
||||
@@ -124,7 +124,7 @@ public class DependentRaceStateTest {
|
||||
bTime[0] = state.getStartTime();
|
||||
}
|
||||
});
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
raceLogA.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, now));
|
||||
assertEquals(now.plus(delta), bTime[0]);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class DependentRaceStateTest {
|
||||
raceLogB.add(new RaceLogDependentStartTimeEventImpl(nowMock, author, nowMock, "12", null, 12,
|
||||
new SimpleRaceLogIdentifierImpl("A", "", ""), new MillisecondsDurationImpl(5000)));
|
||||
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
raceLogA.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, new MillisecondsTimePoint(5000)));
|
||||
|
||||
raceLogB.add(new RaceLogStartTimeEventImpl(now, author, now, "12", null, 12, new MillisecondsTimePoint(20000)));
|
||||
|
||||
+1
-1
@@ -432,7 +432,7 @@ public class RaceLogTest {
|
||||
RaceLog raceLog = new RaceLogImpl("RaceLogTest", "test-identifier");
|
||||
UUID client1Id = UUID.randomUUID();
|
||||
UUID client2Id = UUID.randomUUID();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
RaceLogStartTimeEvent startTimeEvent1 = RaceLogEventFactory.INSTANCE.createStartTimeEvent(now, author, 1, now.plus(1));
|
||||
Iterable<RaceLogEvent> empty = raceLog.add(startTimeEvent1, client1Id);
|
||||
assertTrue(Util.isEmpty(empty));
|
||||
|
||||
+2
-1
@@ -13,12 +13,13 @@ import com.sap.sailing.domain.common.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.leaderboard.caching.LeaderboardDTOCalculationReuseCache;
|
||||
import com.sap.sailing.domain.tracking.GPSFixTrack;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class LeaderboardDTOCalculationReuseCacheTest {
|
||||
@Test
|
||||
public void testNullWindCaching() {
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
final LeaderboardDTOCalculationReuseCache cache = new LeaderboardDTOCalculationReuseCache(now);
|
||||
final Competitor competitor = mock(Competitor.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ThresholdBasedResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.tractracadapter.ReceiverType;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.tractrac.model.lib.api.event.CreateModelException;
|
||||
@@ -43,7 +44,7 @@ public class LeaderboardForKielWeekTest extends OnlineTracTracBasedTest {
|
||||
public void leaderboardWithOneRaceTest() throws URISyntaxException, NoWindException, IOException, InterruptedException, SubscriberInitializationException, CreateModelException {
|
||||
leaderboard = new FlexibleLeaderboardImpl("Kiel Week 2011 505s", new ThresholdBasedResultDiscardingRuleImpl(new int[] { 3, 6 }),
|
||||
new LowPoint(), null);
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
loadRace("event_20110609_KielerWoch-505_Race_2.txt", "event_20110609_KielerWoch-505_Race_2.mtb"); // 505 Race 2
|
||||
Competitor kevin = getCompetitorByName("Kevin");
|
||||
RaceColumn column = leaderboard.addRace(getTrackedRace(), "Test Race 1", /* medalRace */false);
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest {
|
||||
leaderboard.addRaceColumn(columnName, /* medalRace */ true);
|
||||
leaderboard.addRace(testRaces.iterator().next(), columnName, /* medalRace */false);
|
||||
final Set<String> emptySet = Collections.emptySet();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
final TrackedRegattaRegistry trackedRegattaRegistry = new TrackedRegattaRegistry() {
|
||||
@Override
|
||||
public DynamicTrackedRegatta getOrCreateTrackedRegatta(Regatta regatta) {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class LineAnalysisTest extends TrackBasedTest {
|
||||
private MillisecondsTimePoint now;
|
||||
private TimePoint now;
|
||||
private DynamicTrackedRace trackedRace;
|
||||
|
||||
@Before
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class StarbordSideOfStartLineRecognitionTest {
|
||||
private MillisecondsTimePoint now;
|
||||
private TimePoint now;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.sap.sailing.domain.common.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.common.tracking.impl.GPSFixMovingImpl;
|
||||
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
|
||||
import com.sap.sse.common.Color;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@ public class TackTest extends StoredTrackBasedTestWithTrackedRace {
|
||||
@Test
|
||||
public void testStarboardTack() throws NoWindException {
|
||||
DynamicGPSFixTrack<Competitor, GPSFixMoving> hassosTrack = getTrackedRace().getTrack(competitor);
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
hassosTrack.addGPSFix(new GPSFixMovingImpl(new DegreePosition(54.4680424, 10.234451), now,
|
||||
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(45))));
|
||||
assertEquals(Tack.PORT, getTrackedRace().getTack(competitor, now));
|
||||
@@ -65,7 +66,7 @@ public class TackTest extends StoredTrackBasedTestWithTrackedRace {
|
||||
@Test
|
||||
public void testPortTack() throws NoWindException {
|
||||
DynamicGPSFixTrack<Competitor, GPSFixMoving> hassosTrack = getTrackedRace().getTrack(competitor);
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
hassosTrack.addGPSFix(new GPSFixMovingImpl(new DegreePosition(54.4680424, 10.234451), now,
|
||||
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(270))));
|
||||
assertEquals(Tack.STARBOARD, getTrackedRace().getTack(competitor, now));
|
||||
@@ -74,7 +75,7 @@ public class TackTest extends StoredTrackBasedTestWithTrackedRace {
|
||||
@Test
|
||||
public void testStarboardTackForZeroDifference() throws NoWindException {
|
||||
DynamicGPSFixTrack<Competitor, GPSFixMoving> hassosTrack = getTrackedRace().getTrack(competitor);
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
hassosTrack.addGPSFix(new GPSFixMovingImpl(new DegreePosition(54.4680424, 10.234451), now,
|
||||
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(180))));
|
||||
assertEquals(Tack.PORT, getTrackedRace().getTack(competitor, now));
|
||||
|
||||
@@ -758,7 +758,7 @@ public class TrackTest {
|
||||
Bearing bearing = new DegreeBearingImpl(123);
|
||||
Speed speed = new KnotSpeedImpl(7);
|
||||
Position p = new DegreePosition(0, 0);
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint start = now;
|
||||
final int steps = 10;
|
||||
TimePoint next = null;
|
||||
@@ -858,7 +858,7 @@ public class TrackTest {
|
||||
Bearing bearing = new DegreeBearingImpl(123);
|
||||
Speed speed = new KnotSpeedImpl(7);
|
||||
Position p = new DegreePosition(0, 0);
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint start = now;
|
||||
final int steps = 10;
|
||||
TimePoint next = null;
|
||||
@@ -916,7 +916,7 @@ public class TrackTest {
|
||||
Bearing bearing = new DegreeBearingImpl(123);
|
||||
Speed speed = new KnotSpeedImpl(7);
|
||||
Position p = new DegreePosition(0, 0);
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint start = now;
|
||||
final int steps = 10;
|
||||
TimePoint next = null;
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ public class TrackedRaceCenterTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleAverage() {
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
Position mark1Pos = new DegreePosition(10, 10);
|
||||
mark1Track.add(new GPSFixImpl(mark1Pos, now));
|
||||
Position mark2Pos = new DegreePosition(20, 10);
|
||||
@@ -85,7 +85,7 @@ public class TrackedRaceCenterTest {
|
||||
DynamicGPSFixTrackImpl<Mark> mark3Track = new DynamicGPSFixTrackImpl<Mark>(mark3, /* millisecondsOverWhichToAverage */ 10);
|
||||
when(trackedRace.getOrCreateTrack(mark3)).thenReturn(mark3Track);
|
||||
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
Position mark1Pos = new DegreePosition(0, 0);
|
||||
mark1Track.add(new GPSFixImpl(mark1Pos, now));
|
||||
Position mark2Pos = new DegreePosition(0, 10);
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class WindEstimationLockingUnderLoadTest {
|
||||
} else {
|
||||
double directionInDegrees = 360*Math.random();
|
||||
double confidence = Math.random();
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
result = new WindWithConfidenceImpl<TimePoint>(new WindImpl(new DegreePosition(49, 8), now, new KnotSpeedWithBearingImpl(speedInKnots, new DegreeBearingImpl(directionInDegrees))),
|
||||
confidence, now, /* useSpeed */ true);
|
||||
}
|
||||
|
||||
+8
-8
@@ -137,7 +137,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testCombinedWindTrack() throws NoWindException {
|
||||
initRace(4, new int[] { 1, 1, 2, 2 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 315);
|
||||
setBearingForCompetitor(competitors.get(1), now, 45); // on the same tack, should give no read-out
|
||||
setBearingForCompetitor(competitors.get(2), now, 135);
|
||||
@@ -253,7 +253,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForSimpleTracks() throws NoWindException {
|
||||
initRace(2, new int[] { 1, 1 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 50);
|
||||
Wind estimatedWindDirection = getTrackedRace().getEstimatedWindDirection(now);
|
||||
@@ -263,7 +263,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForSimpleTracksWithOneAncientFixToBeSuppressedByLowConfidence() throws NoWindException {
|
||||
initRace(3, new int[] { 1, 1, 1 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 50);
|
||||
setBearingForCompetitor(competitors.get(2), new MillisecondsTimePoint(0), 100); // this shouldn't disturb the estimation because it's too old
|
||||
@@ -275,7 +275,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
public void testWindEstimationForSimpleTracksWithOneFixNearMarkPassingToBeSuppressedByLowConfidence() throws NoWindException {
|
||||
TimePoint markPassingTimePoint = new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime());
|
||||
initRace(3, new int[] { 1, 1, 1 }, markPassingTimePoint);
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 50);
|
||||
setBearingForCompetitor(competitors.get(2), markPassingTimePoint, 100); // this shouldn't disturb the estimation because it's too old
|
||||
@@ -286,7 +286,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForTwoBoatsOnSameTack() throws NoWindException {
|
||||
initRace(2, new int[] { 1, 1 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 330); // on the same tack, should give no read-out
|
||||
Wind nullWind = getTrackedRace().getEstimatedWindDirection(now);
|
||||
@@ -298,7 +298,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForFourBoatsOnSameTack() throws NoWindException {
|
||||
initRace(4, new int[] { 1, 1, 2, 2 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 330); // on the same tack, should give no read-out
|
||||
setBearingForCompetitor(competitors.get(2), now, 135);
|
||||
@@ -312,7 +312,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForFourBoatsWithUpwindOnSameTack() throws NoWindException {
|
||||
initRace(4, new int[] { 1, 1, 2, 2 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 320);
|
||||
setBearingForCompetitor(competitors.get(1), now, 330); // on the same tack, should give no read-out
|
||||
setBearingForCompetitor(competitors.get(2), now, 135);
|
||||
@@ -324,7 +324,7 @@ public class WindEstimationOnConstructedTracksTest extends StoredTrackBasedTest
|
||||
@Test
|
||||
public void testWindEstimationForFourBoats() throws NoWindException {
|
||||
initRace(4, new int[] { 1, 1, 2, 2 }, new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 23).getTime()));
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
setBearingForCompetitor(competitors.get(0), now, 315);
|
||||
setBearingForCompetitor(competitors.get(1), now, 45); // on the same tack, should give no read-out
|
||||
setBearingForCompetitor(competitors.get(2), now, 135);
|
||||
|
||||
+1
-1
@@ -279,7 +279,7 @@ public class LiveLeaderboardUpdater implements Runnable {
|
||||
+ leaderboard.getName());
|
||||
// interrupt the current thread if not producing a single result within the overall timeout
|
||||
while (true) {
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
final Long delayToLiveInMillis = getLeaderboard().getDelayToLiveInMillis();
|
||||
TimePoint timePoint = delayToLiveInMillis == null ? now : now.minus(delayToLiveInMillis);
|
||||
synchronized (this) {
|
||||
|
||||
+1
-1
@@ -1148,7 +1148,7 @@ public abstract class AbstractSimpleLeaderboardImpl implements Leaderboard, Race
|
||||
|
||||
@Override
|
||||
public TimePoint getNowMinusDelay() {
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
final Long delayToLiveInMillis = getDelayToLiveInMillis();
|
||||
TimePoint timePoint = delayToLiveInMillis == null ? now : now.minus(delayToLiveInMillis);
|
||||
return timePoint;
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ import com.sap.sailing.gwt.ui.shared.dispatch.Action;
|
||||
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
|
||||
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
|
||||
import com.sap.sailing.gwt.ui.shared.general.EventState;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sse.common.media.MediaTagConstants;
|
||||
import com.sap.sse.common.media.VideoDescriptor;
|
||||
@@ -32,7 +33,7 @@ public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOv
|
||||
@Override
|
||||
@GwtIncompatible
|
||||
public ResultWithTTL<EventOverviewStageDTO> execute(DispatchContext context) {
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
Event event = context.getRacingEventService().getEvent(eventId);
|
||||
EventState state = HomeServiceUtil.calculateEventState(event);
|
||||
long ttl = 1000 * 60 * 5;
|
||||
@@ -49,7 +50,7 @@ public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOv
|
||||
}
|
||||
|
||||
@GwtIncompatible
|
||||
public EventOverviewStageContentDTO getStageContent(DispatchContext context, Event event, EventState state, MillisecondsTimePoint now) {
|
||||
public EventOverviewStageContentDTO getStageContent(DispatchContext context, Event event, EventState state, TimePoint now) {
|
||||
// Simple solution:
|
||||
// P1: Show the best matching video if available
|
||||
// P2: Show Countdown for upcoming events
|
||||
|
||||
+2
-1
@@ -38,6 +38,7 @@ import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRank;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sse.common.Color;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
@@ -104,7 +105,7 @@ public class TestStoringAndRetrievingLeaderboards extends AbstractMongoDBTest {
|
||||
FlexibleLeaderboardImpl leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboard.getScoreCorrection().setComment("Humba");
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
leaderboard.getScoreCorrection().setTimePointOfLastCorrectionsValidity(now);
|
||||
new MongoObjectFactoryImpl(db).storeLeaderboard(leaderboard);
|
||||
Leaderboard loadedLeaderboard = new DomainObjectFactoryImpl(db, DomainFactory.INSTANCE).loadLeaderboard(leaderboardName, /* regattaRegistry */ null);
|
||||
|
||||
+4
-4
@@ -383,7 +383,7 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
|
||||
return Response.status(Status.BAD_REQUEST).entity("Invalid JSON body in request")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
}
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
String competitorId = (String) requestObject.get(DeviceMappingConstants.JSON_COMPETITOR_ID_AS_STRING);
|
||||
String deviceUuid = (String) requestObject.get(DeviceMappingConstants.JSON_DEVICE_UUID);
|
||||
Long fromMillis = (Long) requestObject.get(DeviceMappingConstants.JSON_FROM_MILLIS);
|
||||
@@ -452,7 +452,7 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
|
||||
AbstractLogEventAuthor author = new LogEventAuthorImpl(AbstractLogEventAuthor.NAME_COMPATIBILITY,
|
||||
AbstractLogEventAuthor.PRIORITY_COMPATIBILITY);
|
||||
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
|
||||
logger.fine("Post issued to " + this.getClass().getName());
|
||||
Object requestBody;
|
||||
@@ -590,7 +590,7 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
|
||||
}
|
||||
JSONArray array = new JSONArray();
|
||||
for (Mark mark : marks) {
|
||||
final MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
final TimePoint now = MillisecondsTimePoint.now();
|
||||
Position lastKnownPosition = getService().getMarkPosition(mark,
|
||||
(LeaderboardThatHasRegattaLike) leaderboard, now,
|
||||
/* raceLog==null means use all race logs */ null);
|
||||
@@ -660,7 +660,7 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
|
||||
return Response.status(Status.NOT_FOUND).entity("Could not find a mark with ID '" + markId + "'.")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
}
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
Position lastKnownPosition = getService().getMarkPosition(mark,
|
||||
(LeaderboardThatHasRegattaLike) leaderboard, now,
|
||||
/* raceLog==null means use all race logs */ null);
|
||||
|
||||
+2
-1
@@ -42,6 +42,7 @@ import com.sap.sailing.server.operationaltransformation.AddColumnToLeaderboard;
|
||||
import com.sap.sailing.server.operationaltransformation.AddColumnToSeries;
|
||||
import com.sap.sailing.server.operationaltransformation.CreateRegattaLeaderboard;
|
||||
import com.sap.sailing.server.operationaltransformation.RenameLeaderboard;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
@@ -218,7 +219,7 @@ public class RaceLogReplicationTest extends AbstractLogReplicationTest<RaceLog,
|
||||
addAndValidateEventIds(masterLog, replicaLog);
|
||||
|
||||
final Series series = masterRegatta.getSeries().iterator().next();
|
||||
final MillisecondsTimePoint approximateRaceStatusEventCreationTimePoint = MillisecondsTimePoint.now();
|
||||
final TimePoint approximateRaceStatusEventCreationTimePoint = MillisecondsTimePoint.now();
|
||||
final RaceLogRaceStatusEvent raceStatusEvent = RaceLogEventFactory.INSTANCE.createRaceStatusEvent(approximateRaceStatusEventCreationTimePoint, author, 42,
|
||||
RaceLogRaceStatus.UNKNOWN);
|
||||
addEventToDB(series.getRaceColumnByName(raceColumnName).getRaceLogIdentifier(series.getFleetByName(fleetName)), raceStatusEvent, regattaName, raceColumnName, fleetName);
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ public class TrackRaceReplicationTest extends AbstractServerReplicationTest {
|
||||
TrackedRace replicaTrackedRace = replica.getTrackedRace(raceIdentifier);
|
||||
assertEquals(masterTrackedRace.getStartOfTracking(), replicaTrackedRace.getStartOfTracking());
|
||||
assertEquals(masterTrackedRace.getEndOfTracking(), replicaTrackedRace.getEndOfTracking());
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
assertFalse(now.equals(replicaTrackedRace.getStartOfRace()));
|
||||
((DynamicTrackedRace) masterTrackedRace).setStartTimeReceived(now);
|
||||
Thread.sleep(1000);
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.sap.sailing.domain.abstractlog.race.impl.RaceLogStartTimeEventImpl;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.server.operationaltransformation.racelog.RaceLogEventWithTransformationSupport;
|
||||
import com.sap.sailing.server.operationaltransformation.racelog.RaceLogStartTimeEventWithTransformationSupport;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sse.operationaltransformation.OperationalTransformer;
|
||||
@@ -136,7 +137,7 @@ public class RaceLogOperationalTransformationTest {
|
||||
public void testConflictingApplyServerWins() {
|
||||
Calendar cServer = new GregorianCalendar(2013, 6, 7, 13, 59, 33);
|
||||
final MillisecondsTimePoint startTimeServer = new MillisecondsTimePoint(cServer.getTime());
|
||||
final MillisecondsTimePoint createdAt = MillisecondsTimePoint.now();
|
||||
final TimePoint createdAt = MillisecondsTimePoint.now();
|
||||
{
|
||||
RaceLogStartTimeEvent startTimeEventServer = new RaceLogStartTimeEventImpl(createdAt,
|
||||
author, startTimeServer, UUID.randomUUID(), Collections.<Competitor> emptyList(), /* pass ID */1,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.sap.sse.common.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import com.sap.sse.common.TimePoint;
|
||||
|
||||
|
||||
public class MillisecondsTimePoint extends AbstractTimePoint {
|
||||
@@ -8,7 +12,33 @@ public class MillisecondsTimePoint extends AbstractTimePoint {
|
||||
private long millis;
|
||||
private Date date;
|
||||
|
||||
public static MillisecondsTimePoint now() {
|
||||
private static TimePoint timePointNoOlderThanOneSecond;
|
||||
|
||||
static {
|
||||
timePointNoOlderThanOneSecond = MillisecondsTimePoint.now();
|
||||
new Timer("LockUtil timestamp generator", /* isDaemon */ true).schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
timePointNoOlderThanOneSecond = MillisecondsTimePoint.now();
|
||||
}
|
||||
}, /* delay 0 means immediate execution */ 0l, /* period 1s */ 1000l);
|
||||
}
|
||||
|
||||
/**
|
||||
* A time point that is approximately the current time, up to one second late. Obtaining a time point
|
||||
* this way is much less expensive than using {@link #now()} which really generates a new time point
|
||||
* upon each invocation and as such does not qualify for high-frequency operations, particularly when
|
||||
* the timer is used for some human time-based timeout of several seconds.
|
||||
*/
|
||||
public static TimePoint approximateNow() {
|
||||
return timePointNoOlderThanOneSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* A time point as exact as {@link System#currentTimeMillis()}
|
||||
*/
|
||||
public static TimePoint now() {
|
||||
return new MillisecondsTimePoint(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -61,12 +61,12 @@ public class RabbitOutputStream extends OutputStream {
|
||||
while (!closed) {
|
||||
synchronized (RabbitOutputStream.this) {
|
||||
if (timeLastDataHasBeenReceived != null) {
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
TimePoint approximateNow = MillisecondsTimePoint.approximateNow();
|
||||
// FIXME the timing should better be managed by a Timer instance with delays based on last send and wake-up / test time point
|
||||
if (timeLastDataHasBeenReceived.until(now).compareTo(DURATION_AFTER_TO_SYNC_DATA_TO_CHANNEL_AS_MILLIS) > 0) {
|
||||
if (timeLastDataHasBeenReceived.until(approximateNow).compareTo(DURATION_AFTER_TO_SYNC_DATA_TO_CHANNEL_AS_MILLIS) > 0) {
|
||||
try {
|
||||
sendBuffer();
|
||||
timeLastDataHasBeenReceived = MillisecondsTimePoint.now(); // reset time to avoid unnecessary write attempt
|
||||
timeLastDataHasBeenReceived = MillisecondsTimePoint.approximateNow(); // reset time to avoid unnecessary write attempt
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.INFO, "Exception trying to send message. Aborting.", e);
|
||||
break;
|
||||
@@ -103,7 +103,7 @@ public class RabbitOutputStream extends OutputStream {
|
||||
if (count == streamBuffer.length) {
|
||||
sendBuffer();
|
||||
}
|
||||
timeLastDataHasBeenReceived = MillisecondsTimePoint.now();
|
||||
timeLastDataHasBeenReceived = MillisecondsTimePoint.approximateNow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -56,19 +54,6 @@ public class LockUtil {
|
||||
private static final Logger logger = Logger.getLogger(Util.class.getName());
|
||||
private static final Map<NamedReentrantReadWriteLock, TimePoint> lastTimeWriteLockWasObtained = new ConcurrentWeakHashMap<NamedReentrantReadWriteLock, TimePoint>();
|
||||
|
||||
private static TimePoint timePointNoOlderThanOneSecond;
|
||||
|
||||
static {
|
||||
timePointNoOlderThanOneSecond = MillisecondsTimePoint.now();
|
||||
new Timer("LockUtil timestamp generator", /* isDaemon */ true).schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
timePointNoOlderThanOneSecond = MillisecondsTimePoint.now();
|
||||
}
|
||||
}, /* delay 0 means immediate execution */ 0l, /* period 1s */ 1000l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells how many other threads propagated which held lock to the key thread. During propagation, a lock is
|
||||
* considered held if it is really locked by the propagating thread or if the propagating thread received it itself
|
||||
@@ -102,7 +87,7 @@ public class LockUtil {
|
||||
|
||||
public static void lockForWrite(NamedReentrantReadWriteLock lock) {
|
||||
acquireLockVirtuallyOrActually(lock, lock.writeLock(), ReadOrWrite.WRITE);
|
||||
lastTimeWriteLockWasObtained.put(lock, timePointNoOlderThanOneSecond);
|
||||
lastTimeWriteLockWasObtained.put(lock, MillisecondsTimePoint.approximateNow());
|
||||
}
|
||||
|
||||
private static void acquireLockVirtuallyOrActually(NamedReentrantReadWriteLock lock, final Lock readOrWriteLock, final ReadOrWrite readOrWrite) {
|
||||
@@ -166,7 +151,7 @@ public class LockUtil {
|
||||
+ " to be unlocked but no time recorded for when it was last obtained.\n"
|
||||
+ "This is where the lock interaction happened:\n" + getCurrentStackTrace());
|
||||
} else {
|
||||
TimePoint now = timePointNoOlderThanOneSecond;
|
||||
TimePoint now = MillisecondsTimePoint.approximateNow();
|
||||
final Duration heldWriteLockForMillis = timePointWriteLockWasObtained.until(now);
|
||||
if (heldWriteLockForMillis.compareTo(Duration.ONE_SECOND.times(10)) > 0) {
|
||||
String stackTrace = getCurrentStackTrace();
|
||||
|
||||
Reference in new issue
Block a user