added test for delta clock at mark

This commit is contained in:
Axel Uhl committed 2011-11-04 16:15:42 +01:00
1 parent 05e1dcdcd4
commit d870388e65
4 files changed
+22 -4

No files matched your search

@@ -10,6 +10,7 @@ import java.net.UnknownHostException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
@@ -32,7 +33,7 @@ import com.sap.sailing.util.Util;
import com.sap.sailing.util.Util.Pair; import com.sap.sailing.util.Util.Pair;
import com.sap.sailing.util.Util.Triple; import com.sap.sailing.util.Util.Triple;
@Ignore("This test doesn't work as long as the server doesn't play an actual race") //@Ignore("This test doesn't work as long as the server doesn't play an actual race")
public class SwissTimingSailMasterLiveTest implements SailMasterListener { public class SwissTimingSailMasterLiveTest implements SailMasterListener {
private int rpdCounter; private int rpdCounter;
private SailMasterConnector connector; private SailMasterConnector connector;
@@ -107,6 +108,16 @@ public class SwissTimingSailMasterLiveTest implements SailMasterListener {
assertNotNull(currentBoatSpeed); assertNotNull(currentBoatSpeed);
} }
} }
@Test
public void testGetDeltaClockAtMark() throws UnknownHostException, IOException, InterruptedException, NumberFormatException, ParseException {
Iterable<Race> races = connector.getRaces();
Race race = races.iterator().next();
Map<Integer, Pair<TimePoint, String>> deltaClockAtMark = connector.getDeltaClockAtMark(race.getRaceID());
for (int i=0; i<7; i++) {
assertTrue(deltaClockAtMark.keySet().contains(i));
}
}
@Override @Override
public void receivedRacePositionData(String raceID, RaceStatus status, TimePoint timePoint, TimePoint startTime, public void receivedRacePositionData(String raceID, RaceStatus status, TimePoint timePoint, TimePoint startTime,
@@ -28,5 +28,10 @@ public class CompetitorImpl implements Competitor {
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String toString() {
return name+"/"+boatID;
}
} }
@@ -63,7 +63,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
private final String host; private final String host;
private final int port; private final int port;
private Socket socket; private Socket socket;
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); private final DateFormat dateFormat;
private final Set<SailMasterListener> listeners; private final Set<SailMasterListener> listeners;
private final Thread receiverThread; private final Thread receiverThread;
private boolean stopped; private boolean stopped;
@@ -72,6 +72,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public SailMasterConnectorImpl(String host, int port) { public SailMasterConnectorImpl(String host, int port) {
super(); super();
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
this.host = host; this.host = host;
this.port = port; this.port = port;
this.listeners = new HashSet<SailMasterListener>(); this.listeners = new HashSet<SailMasterListener>();
@@ -387,7 +388,8 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {
String[] markTimeDetail = sections[3+i].split(";"); String[] markTimeDetail = sections[3+i].split(";");
result.put(Integer.valueOf(markTimeDetail[0]), new Pair<TimePoint, String>( result.put(Integer.valueOf(markTimeDetail[0]), new Pair<TimePoint, String>(
new MillisecondsTimePoint(dateFormat.parse(prefixTimeWithISOToday(markTimeDetail[1]))), markTimeDetail[2])); markTimeDetail.length <= 1 ? null : new MillisecondsTimePoint(dateFormat.parse(prefixTimeWithISOToday(markTimeDetail[1]))),
markTimeDetail.length <= 2 ? null : markTimeDetail[2]));
} }
return result; return result;
} }
@@ -20,7 +20,7 @@ public class SailMasterTransceiver {
* Sends the string message to the output stream <code>os</code>, using the cp1252 character set * Sends the string message to the output stream <code>os</code>, using the cp1252 character set
* for encoding and framing the message with the <code>STX</code> and <code>ETX</code> bytes. * for encoding and framing the message with the <code>STX</code> and <code>ETX</code> bytes.
*/ */
public void sendMessage(String message, OutputStream os) throws IOException { public synchronized void sendMessage(String message, OutputStream os) throws IOException {
os.write(STX); os.write(STX);
os.write(message.getBytes(Charset.forName("cp1252"))); os.write(message.getBytes(Charset.forName("cp1252")));
os.write(ETX); os.write(ETX);