mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 06:06:11 +00:00
added failing test case for moving a waypoint forward in a course, causing temporary duplicates, violating CourseImpl's invariant; see bug 1113
This commit is contained in:
@@ -16,6 +16,7 @@ import java.util.Set;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.Leg;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.base.impl.BoatClassImpl;
|
||||
@@ -30,6 +31,8 @@ import com.sap.sailing.domain.tracking.TrackedLeg;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicTrackedRaceImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
public class CourseTest {
|
||||
@Test
|
||||
public void testEmptyCourse() {
|
||||
@@ -158,6 +161,24 @@ public class CourseTest {
|
||||
assertEquals(2, course.getIndexOfWaypoint(wp2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMovingWaypointFoward() throws PatchFailedException {
|
||||
List<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
final WaypointImpl wp1 = new WaypointImpl(new MarkImpl("Test Mark 1"));
|
||||
waypoints.add(wp1);
|
||||
final WaypointImpl wp2 = new WaypointImpl(new MarkImpl("Test Mark 2"));
|
||||
waypoints.add(wp2);
|
||||
final WaypointImpl wp3 = new WaypointImpl(new MarkImpl("Test Mark 3"));
|
||||
waypoints.add(wp3);
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(3, Util.size(course.getWaypoints()));
|
||||
assertEquals(2, Util.size(course.getLegs()));
|
||||
assertWaypointIndexes(course);
|
||||
course.update(Arrays.asList(wp2.getMarks().iterator().next(), wp3.getMarks().iterator().next(), wp1.getMarks().iterator().next()),
|
||||
DomainFactory.INSTANCE);
|
||||
assertWaypointIndexes(course);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWaypointFromCourseWithThreeWaypoints() {
|
||||
List<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
|
||||
@@ -74,7 +74,7 @@ public interface Course extends Named {
|
||||
* to the registered {@link CourseListener}s as if {@link #addWaypoint(int, Waypoint)} and {@link #removeWaypoint(int)}
|
||||
* had been used.
|
||||
*/
|
||||
void update(List<ControlPoint> newControlPoints, DomainFactory baseDomainFactory) throws PatchFailedException;
|
||||
void update(List<? extends ControlPoint> newControlPoints, DomainFactory baseDomainFactory) throws PatchFailedException;
|
||||
|
||||
Iterable<Leg> getLegsAdjacentTo(Mark mark);
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.ControlPoint;
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.CourseListener;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.Leg;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.common.impl.NamedImpl;
|
||||
import com.sap.sailing.util.CourseAsWaypointList;
|
||||
@@ -65,6 +65,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
assert this.waypoints.size() == waypointIndexes.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,6 +141,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
logger.info("Waypoint " + waypointToAdd + " added to course '" + getName() + "', before notifying listeners");
|
||||
notifyListenersWaypointAdded(zeroBasedPosition, waypointToAdd);
|
||||
logger.info("Waypoint " + waypointToAdd + " added to course '" + getName() + "', after notifying listeners");
|
||||
assert waypoints.size() == waypointIndexes.size();
|
||||
} finally {
|
||||
LockUtil.unlockAfterWrite(lock);
|
||||
}
|
||||
@@ -177,6 +179,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
logger.info("Waypoint " + removedWaypoint + " removed from course '" + getName() + "', before notifying listeners");
|
||||
notifyListenersWaypointRemoved(zeroBasedPosition, removedWaypoint);
|
||||
logger.info("Waypoint " + removedWaypoint + " removed from course '" + getName() + "', after notifying listeners");
|
||||
assert waypoints.size() == waypointIndexes.size();
|
||||
} finally {
|
||||
LockUtil.unlockAfterWrite(lock);
|
||||
}
|
||||
@@ -375,7 +378,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(List<ControlPoint> newControlPoints, DomainFactory baseDomainFactory) throws PatchFailedException {
|
||||
public void update(List<? extends ControlPoint> newControlPoints, DomainFactory baseDomainFactory) throws PatchFailedException {
|
||||
LockUtil.lockForWrite(lock);
|
||||
try {
|
||||
Iterable<Waypoint> courseWaypoints = getWaypoints();
|
||||
@@ -409,6 +412,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
if (!patch.isEmpty()) {
|
||||
logger.info("applying course update " + patch + " to course " + this);
|
||||
CourseAsWaypointList courseAsWaypointList = new CourseAsWaypointList(this);
|
||||
// FIXME issue: if the patch contains "forward moves" it may first insert the additional duplicates at the end, then remove them at the beginning, leading to duplicate waypoints in the course which is not supported
|
||||
patch.applyToInPlace(courseAsWaypointList);
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console -clean"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dexpedition.udp.port=2010 -Xmx6000m -Dhttp.proxyHost=proxy.wdf.sap.corp -Dhttp.proxyPort=8080 -Djetty.home=${project_loc:com.sap.sailing.server}/../target/configuration/jetty -Djava.util.logging.config.file=${project_loc:com.sap.sailing.server}/../target/configuration/logging_debug.properties -Dkiwo.results=${project_loc:com.sap.sailing.kiworesultimport.test}/resources -XX:+UseMembar"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dexpedition.udp.port=2010 -Xmx6000m -Dhttp.proxyHost=proxy.wdf.sap.corp -Dhttp.proxyPort=8080 -Djetty.home=${project_loc:com.sap.sailing.server}/../target/configuration/jetty -Djava.util.logging.config.file=${project_loc:com.sap.sailing.server}/../target/configuration/logging_debug.properties -Dkiwo.results=${project_loc:com.sap.sailing.kiworesultimport.test}/resources -XX:+UseMembar"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc}"/>
|
||||
<stringAttribute key="pde.version" value="3.3"/>
|
||||
<booleanAttribute key="show_selected_only" value="false"/>
|
||||
|
||||
Reference in New Issue
Block a user