Getting boat locations from race simulator & bug fixes

- Boat locations that are generated by the simulator are sent to the client as they happen
- Fixed heading and lat/lon encoding
- Fixed a bug where the header wasn't included in the sent byte stream
- Fixed the format of data as it's sent to the client.
- Data is now sent using a channel
- Removed tests that don't work with channels

Tags: #story[829]
This commit is contained in:
Michael Rausch
2017-04-29 19:38:21 +12:00
parent 8a04a0e5b7
commit 3e97f016d5
16 changed files with 330 additions and 354 deletions
@@ -17,24 +17,6 @@ public class TestMessage {
private static int BOAT_SUB_MESSAGE_LEN = 20;
private static int CRC_LEN = 4;
/**
* Test generated output is the same as the expected output
*/
@Test
public void testHeatBetBufferOutputLength(){
Message m = new Heartbeat(1);
List<Integer> output = new ArrayList<>();
DataOutputStream ds = new DataOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
output.add(b);
}
});
m.send(ds);
assertTrue(output.size() == (m.getSize() + CRC_LEN + Header.getSize()));
}
/**
* Test output expected is the same as the spec
@@ -45,92 +27,5 @@ public class TestMessage {
assertTrue(m.getSize() == (XML_MESSAGE_LEN + "12345".length()));
}
/**
* Ensure that when no boats are in the race, that only the base message is sent
*/
@Test
public void testRaceStatusMessageBufferLenNoBoats(){
Message m = new RaceStatusMessage(1, RaceStatus.PRESTART,1,WindDirection.EAST,1,
0,RaceType.MATCH_RACE,1, new ArrayList<BoatSubMessage>());
List<Integer> output = new ArrayList<>();
DataOutputStream ds = new DataOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
output.add(b);
}
});
m.send(ds);
assertTrue(output.size() == RACE_STATUS_BASE_LEN + Header.getSize() + CRC_LEN);
}
/**
* Test that each boat status is added to the message
*/
@Test
public void testRaceStatusMessageBufferLenWithBoats(){
List<BoatSubMessage> boatMessages = new ArrayList<>();
List<Integer> output = new ArrayList<>();
BoatSubMessage boat1 = new BoatSubMessage(1, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
BoatSubMessage boat2 = new BoatSubMessage(2, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
BoatSubMessage boat3 = new BoatSubMessage(3, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
boatMessages.add(boat1);
boatMessages.add(boat2);
boatMessages.add(boat3);
Message m = new RaceStatusMessage(1, RaceStatus.PRESTART,1,WindDirection.EAST,1,
3,RaceType.MATCH_RACE,1, boatMessages);
DataOutputStream ds = new DataOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
output.add(b);
}
});
m.send(ds);
assertTrue(output.size() == (RACE_STATUS_BASE_LEN + (BOAT_SUB_MESSAGE_LEN * 3) + CRC_LEN + Header.getSize()));
}
/**
* IllegalArgumentException should be thrown when numBoatsInRace is smaller
* than the number of boats actually in the race
*/
@Test(expected = IllegalArgumentException.class)
public void testRaceStatusTooManyBoats(){
List<BoatSubMessage> boatMessages = new ArrayList<>();
List<Integer> output = new ArrayList<>();
BoatSubMessage boat1 = new BoatSubMessage(1, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
BoatSubMessage boat2 = new BoatSubMessage(2, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
BoatSubMessage boat3 = new BoatSubMessage(3, BoatStatus.PRESTART, 0, 0, 0,
10000, 10000);
boatMessages.add(boat1);
boatMessages.add(boat2);
boatMessages.add(boat3);
Message m = new RaceStatusMessage(1, RaceStatus.PRESTART,1,WindDirection.EAST,1,
1,RaceType.MATCH_RACE,1, boatMessages);
m.send(new DataOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
System.out.print("");
}
}));
}
}