/** * Generates reference serial data for testing. * * @return */ public static Map<String, Object> generateTestSerialData() { Map<String, Object> serial = new LinkedHashMap<String, Object>(); serial.put("id", ID); serial.put("owner", PLAYER.getName()); serial.put("timestamp", TIMESTAMP); serial.put("parent", PARENT_ID); serial.put("status", "open"); // In the real world, Bukkit has deserialized this automatically serial.put("items", ITEMS); return serial; }
@Test public void test() throws InterruptedException { final TestAuthenticationManager am = new TestAuthenticationManager(null, null); final TestServerStateManager sm = new TestServerStateManager(null); GoBoard board = new GoBoard(10); try { board.makeMove(new BoardLocation(1, 0), StoneColor.BLACK); board.makeMove(new BoardLocation(2, 2), StoneColor.WHITE); board.makeMove(new BoardLocation(1, 1), StoneColor.BLACK); } catch (IllegalMoveException e) { // TODO Auto-generated catch block e.printStackTrace(); } sm.addUnfinishedGame( new UnfinishedGame( "TestGameReconnect", board, MessageFactory.createClientInfo("TestPlayer0", MessageProtocol.TYPE_MACHINE), MessageFactory.createClientInfo("TestPlayer1", MessageProtocol.TYPE_MACHINE), 60, 0)); final GameServer server = new GameServer( "edu.berkeley.cs.cs162.Test.one-game-server-test.db", 100, 5, new PrintStream(System.out), am, sm); Thread t = new Thread() { public void run() { try { server.waitForConnectionsOnPort(TEST_PORT, InetAddress.getByName("localhost")); } catch (UnknownHostException e) { throw new AssertionError(e); } } }; t.start(); while (!server.isReady()) { Thread.sleep(10); // waits until server is ready; } ReaderWriterLock lock = new ReaderWriterLock(); List<Thread> threads = new ArrayList<Thread>(); AtomicInteger sharedCount = new AtomicInteger(0); for (int i = 0; i < NUM_PLAYERS; i++) { List<Message> moves = Arrays.asList( MessageFactory.createGetMoveStatusOkMessage( MessageProtocol.MOVE_PASS, MessageFactory.createLocationInfo(0, 0))); System.out.println(">>>> STARTING TestPlayer" + i + "."); threads.add( TestPlayer.runInstance( "TestPlayer" + i, MessageProtocol.TYPE_MACHINE, moves, TEST_PORT, lock, sharedCount)); } for (Thread thread : threads) { thread.join(); } assertEquals(sharedCount.get(), NUM_PLAYERS); Thread.sleep(100); System.out.println("Auth:"); System.out.println(am.baos.toString()); System.out.println("State:"); // String stateString = sm.baos.toString(); System.out.println(sm.baos.toString()); }