Added empty data sources, to be used by VisualiserRace.
Created FrameRateTracker which can be used to track framerate. Updated RequestToJoinEnum and JoinAcceptanceEnum to match the agreed connection API. Added AssignPlayerBoat message, which is used internally on the client to assign the player a source ID once they have connected. Fixed some race conditions in the MessageRouter. Updated ConnectionAcceptor.CheckClientConnection to wait slightly longer before removing connection (there was a slight race condition before). Race no longer has a reference to LatestMessages. LatestMessages no longer has specific messages types in it. Created RaceState class, which contains the state that is shared between VisualiserRaceState and MockRaceState (currently only used on visualiser). Split VisualiserRace into VisualiserRaceState and VisualiserRaceService. Added the VisualiserRace commands (BoatLocatonCommand, RaceStatusCommand, etc...). Slightly increased the preferred width of race.fxml table columns. issues #27 #37 #35 #story[1095]
This commit is contained in:
@@ -29,13 +29,12 @@ public class MockRaceTest {
|
||||
RaceDataSource raceDataSource = RaceXMLReaderTest.createRaceDataSource();
|
||||
RegattaDataSource regattaDataSource = RegattaXMLReaderTest.createRegattaDataSource();
|
||||
|
||||
LatestMessages latestMessages = new LatestMessages();
|
||||
|
||||
Polars polars = PolarParserTest.createPolars();
|
||||
|
||||
WindGenerator windGenerator = new ConstantWindGenerator(Bearing.fromDegrees(230), 10);
|
||||
|
||||
MockRace mockRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, latestMessages, polars, Constants.RaceTimeScale, windGenerator);
|
||||
MockRace mockRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, polars, Constants.RaceTimeScale, windGenerator);
|
||||
|
||||
|
||||
return mockRace;
|
||||
|
||||
@@ -8,16 +8,11 @@ import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Boat;
|
||||
import shared.model.Race;
|
||||
import visualiser.model.VisualiserRace;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
||||
+2
-19
@@ -64,7 +64,7 @@ public class JoinAcceptanceDecoderTest {
|
||||
*/
|
||||
@Test
|
||||
public void joinSuccessSourceIDTest() throws Exception {
|
||||
responseTypeTest(JoinAcceptanceEnum.JOIN_SUCCESSFUL, 12345);
|
||||
responseTypeTest(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, 12345);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,26 +73,9 @@ public class JoinAcceptanceDecoderTest {
|
||||
*/
|
||||
@Test
|
||||
public void joinSuccessNoSourceIDTest() throws Exception {
|
||||
responseTypeTest(JoinAcceptanceEnum.JOIN_SUCCESSFUL, 0);
|
||||
responseTypeTest(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a participants full message can be encoded and decoded correctly.
|
||||
* @throws Exception if test fails.
|
||||
*/
|
||||
@Test
|
||||
public void participantFullTest() throws Exception {
|
||||
responseTypeTest(JoinAcceptanceEnum.RACE_PARTICIPANTS_FULL, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a ghosts full message can be encoded and decoded correctly.
|
||||
* @throws Exception if test fails.
|
||||
*/
|
||||
@Test
|
||||
public void ghostFullTest() throws Exception {
|
||||
responseTypeTest(JoinAcceptanceEnum.GHOST_PARTICIPANTS_FULL, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a server full message can be encoded and decoded correctly.
|
||||
|
||||
+21
-14
@@ -7,13 +7,15 @@ import network.Messages.Enums.RequestToJoinEnum;
|
||||
import network.Messages.JoinAcceptance;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import visualiser.Commands.ConnectionToServerCommands.JoinSuccessfulCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.RaceParticipantsFullCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.JoinSuccessParticipantCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.JoinFailureCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.ServerFullCommand;
|
||||
import visualiser.enums.ConnectionToServerState;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -50,7 +52,7 @@ public class ConnectionToServerParticipantTest {
|
||||
public void expectRequestSent() throws Exception {
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.REQUEST_SENT, connectionToServer.getConnectionState());
|
||||
}
|
||||
@@ -64,9 +66,14 @@ public class ConnectionToServerParticipantTest {
|
||||
public void interruptTimedOut() throws Exception {
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
|
||||
//Disable logging as we know this will log but we don't care.
|
||||
Logger.getGlobal().setLevel(Level.OFF);
|
||||
connectionToServerThread.interrupt();
|
||||
Logger.getGlobal().setLevel(null);
|
||||
|
||||
connectionToServerThread.join();
|
||||
|
||||
assertEquals(ConnectionToServerState.TIMED_OUT, connectionToServer.getConnectionState());
|
||||
@@ -80,20 +87,20 @@ public class ConnectionToServerParticipantTest {
|
||||
@Test
|
||||
public void sendJoinSuccessCommand() throws Exception {
|
||||
int sourceID = 123;
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.JOIN_SUCCESSFUL, sourceID);
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, sourceID);
|
||||
|
||||
Command command = new JoinSuccessfulCommand(joinAcceptance, connectionToServer);
|
||||
Command command = new JoinSuccessParticipantCommand(joinAcceptance, connectionToServer);
|
||||
|
||||
incomingCommands.put(command);
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.CONNECTED, connectionToServer.getConnectionState());
|
||||
assertTrue(connectionToServer.getJoinAcceptance() != null);
|
||||
assertEquals(sourceID, connectionToServer.getJoinAcceptance().getSourceID());
|
||||
assertNotEquals(0, connectionToServer.getJoinAcceptance().getSourceID());
|
||||
assertEquals(JoinAcceptanceEnum.JOIN_SUCCESSFUL, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
assertEquals(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
|
||||
|
||||
}
|
||||
@@ -104,21 +111,21 @@ public class ConnectionToServerParticipantTest {
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
@Test
|
||||
public void sendRaceParticipantsFullCommand() throws Exception {
|
||||
public void sendJoinFailureCommand() throws Exception {
|
||||
int sourceID = 0;
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.RACE_PARTICIPANTS_FULL, sourceID);
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.JOIN_FAILURE, sourceID);
|
||||
|
||||
Command command = new RaceParticipantsFullCommand(joinAcceptance, connectionToServer);
|
||||
Command command = new JoinFailureCommand(joinAcceptance, connectionToServer);
|
||||
|
||||
incomingCommands.put(command);
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.DECLINED, connectionToServer.getConnectionState());
|
||||
assertTrue(connectionToServer.getJoinAcceptance() != null);
|
||||
assertEquals(sourceID, connectionToServer.getJoinAcceptance().getSourceID());
|
||||
assertEquals(JoinAcceptanceEnum.RACE_PARTICIPANTS_FULL, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
assertEquals(JoinAcceptanceEnum.JOIN_FAILURE, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +143,7 @@ public class ConnectionToServerParticipantTest {
|
||||
incomingCommands.put(command);
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.DECLINED, connectionToServer.getConnectionState());
|
||||
assertTrue(connectionToServer.getJoinAcceptance() != null);
|
||||
|
||||
+7
-8
@@ -7,8 +7,7 @@ import network.Messages.Enums.RequestToJoinEnum;
|
||||
import network.Messages.JoinAcceptance;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import visualiser.Commands.ConnectionToServerCommands.JoinSuccessfulCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.RaceParticipantsFullCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.JoinSuccessParticipantCommand;
|
||||
import visualiser.Commands.ConnectionToServerCommands.ServerFullCommand;
|
||||
import visualiser.enums.ConnectionToServerState;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class ConnectionToServerSpectatorTest {
|
||||
public void expectRequestSent() throws Exception {
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.REQUEST_SENT, connectionToServer.getConnectionState());
|
||||
}
|
||||
@@ -63,19 +62,19 @@ public class ConnectionToServerSpectatorTest {
|
||||
@Test
|
||||
public void sendJoinSuccessCommand() throws Exception {
|
||||
int sourceID = 0;
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.JOIN_SUCCESSFUL, sourceID);
|
||||
JoinAcceptance joinAcceptance = new JoinAcceptance(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, sourceID);
|
||||
|
||||
Command command = new JoinSuccessfulCommand(joinAcceptance, connectionToServer);
|
||||
Command command = new JoinSuccessParticipantCommand(joinAcceptance, connectionToServer);
|
||||
|
||||
incomingCommands.put(command);
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.CONNECTED, connectionToServer.getConnectionState());
|
||||
assertTrue(connectionToServer.getJoinAcceptance() != null);
|
||||
assertEquals(sourceID, connectionToServer.getJoinAcceptance().getSourceID());
|
||||
assertEquals(JoinAcceptanceEnum.JOIN_SUCCESSFUL, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
assertEquals(JoinAcceptanceEnum.JOIN_SUCCESSFUL_PARTICIPANT, connectionToServer.getJoinAcceptance().getAcceptanceType());
|
||||
|
||||
|
||||
}
|
||||
@@ -95,7 +94,7 @@ public class ConnectionToServerSpectatorTest {
|
||||
incomingCommands.put(command);
|
||||
|
||||
//Need to wait for connection thread to execute commands.
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(250);
|
||||
|
||||
assertEquals(ConnectionToServerState.DECLINED, connectionToServer.getConnectionState());
|
||||
assertTrue(connectionToServer.getJoinAcceptance() != null);
|
||||
|
||||
Reference in New Issue
Block a user