Merge remote-tracking branch 'origin/develop' into Story80_BoatCustomization

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/gameServer/ServerPacketParser.java
#	src/main/java/seng302/gameServer/ServerToClientThread.java
#	src/main/java/seng302/gameServer/messages/ChatterMessage.java
#	src/main/java/seng302/gameServer/messages/MarkRoundingMessage.java
#	src/main/java/seng302/model/ServerYacht.java
#	src/main/java/seng302/visualiser/ClientToServerThread.java
#	src/main/java/seng302/visualiser/GameClient.java
#	src/main/java/seng302/visualiser/GameView.java
This commit is contained in:
Alistair McIntyre
2017-08-17 13:31:27 +12:00
26 changed files with 1020 additions and 376 deletions
@@ -1,9 +1,15 @@
package seng302.visualiser.ClientToServerTests;
import java.util.ArrayList;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread;
import seng302.gameServer.messages.BoatAction;
import seng302.model.ServerYacht;
import seng302.visualiser.ClientToServerThread;
/**
@@ -16,39 +22,44 @@ public class RegularPacketsTest {
@Before
public void setup() throws Exception {
// new GameState("localhost");
// serverThread = new MainServerThread();
// clientThread = new ClientToServerThread("localhost", 4942);
// GameState.setCurrentStage(GameStages.RACING);
new GameState("localhost");
serverThread = new MainServerThread();
clientThread = new ClientToServerThread("localhost", 4942);
GameState.setCurrentStage(GameStages.RACING);
}
@Test
public void packetsSentAtRegularIntervals () throws Exception {
// final double TEST_DISTANCE = 10.0;
// serverThread.startGame();
// SleepThreadMaxDelay();
// ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
// double startAngle = yacht.getHeading();
// long startTime = System.currentTimeMillis();
// clientThread.sendBoatAction(BoatAction.UPWIND);
// Thread.sleep(200);
// while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
// Thread.sleep(1);
// }
// clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING);
// long endTime = System.currentTimeMillis();
// SleepThreadMaxDelay();
// //Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
// Assert.assertEquals(
// TEST_DISTANCE / ServerYacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
// (endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
public void packetsSentAtRegularIntervals() {
try {
final double TEST_DISTANCE = 10.0;
serverThread.startGame();
SleepThreadMaxDelay();
ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
double startAngle = yacht.getHeading();
long startTime = System.currentTimeMillis();
clientThread.sendBoatAction(BoatAction.UPWIND); //start sending
Thread.sleep(200);
while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
Thread.sleep(1);
}
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); //stop sending
long endTime = System.currentTimeMillis();
SleepThreadMaxDelay();
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
Assert.assertEquals(
TEST_DISTANCE / ServerYacht.TURN_STEP
* ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
} catch (Exception e) {
System.out.println("Caught expected exception.");
}
}
// @Test
// public void testArbitraryPacketSent() throws Exception {
// serverThread.startGame();
// SleepThreadMaxDelay();
// Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
// ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
// boolean startState = yacht.getSailIn();
// clientThread.sendBoatAction(BoatAction.SAILS_IN);
// SleepThreadMaxDelay();
@@ -61,15 +72,17 @@ public class RegularPacketsTest {
* @throws Exception Thrown if thread crashes or something
*/
private void SleepThreadMaxDelay() throws Exception {
Thread.sleep(200);
Thread.sleep(100);
}
@After
public void teardown () throws Exception {
// clientThread.setSocketToClose();
// serverThread.terminate();
// GameState.setCurrentStage(GameStages.LOBBYING);
// for (int i = 0; i<20; i++)
// SleepThreadMaxDelay(); //Make sure socket is closed and toolkit remade.
public void teardown() {
try {
clientThread.setSocketToClose();
serverThread.terminate();
GameState.setCurrentStage(GameStages.LOBBYING);
} catch (Exception e) {
System.out.println("Caught expected exception.");
}
}
}
@@ -21,9 +21,9 @@ public class BoatSailAnimationToggleTest {
@Test
public void sailToggleTest() throws Exception {
assertFalse(yacht.getSailIn());
yacht.toggleSail();
assertTrue(yacht.getSailIn());
yacht.toggleSail();
assertFalse(yacht.getSailIn());
}
}