|
2 | 2 |
|
3 | 3 | import com.sun.net.httpserver.HttpServer; |
4 | 4 | import net.hollowcube.apiserver.db.ApiDatabase; |
| 5 | +import net.hollowcube.ipc.session.GameServer; |
5 | 6 | import net.hollowcube.ipc.session.SessionClient; |
6 | 7 | import net.hollowcube.ipc.session.SessionServer; |
7 | 8 | import net.hollowcube.sqlgen.testing.TestDb; |
|
15 | 16 | import java.net.http.HttpClient; |
16 | 17 |
|
17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNull; |
18 | 20 |
|
19 | 21 | /// Sessions end to end, the same way as the head database: a real Postgres under the service, the |
20 | 22 | /// generated server over it, and the generated client talking to that over a real socket. |
@@ -61,4 +63,29 @@ insert into player_sessions (player_id, proxy_id, skin_texture, skin_signature, |
61 | 63 |
|
62 | 64 | assertEquals(3, sessions.onlinePlayers()); |
63 | 65 | } |
| 66 | + |
| 67 | + @Test |
| 68 | + void findHub_returnsAReadyHubWithItsProtocol() { |
| 69 | + TEST_DB.seed( |
| 70 | + """ |
| 71 | + insert into server_states (id, role, status, cluster_ip, protocol_version) values |
| 72 | + ('hub-starting', 'hub', 0, '10.0.0.1', 0), |
| 73 | + ('map-a', 'map', 1, '10.0.0.2', 777), |
| 74 | + ('hub-a', 'hub', 1, '10.0.0.3', 777)""" |
| 75 | + ); |
| 76 | + |
| 77 | + assertEquals(new GameServer("hub-a", "10.0.0.3", 777), sessions.findHub(null)); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + void findHub_skipsTheExcludedHub() { |
| 82 | + TEST_DB.seed( |
| 83 | + """ |
| 84 | + insert into server_states (id, role, status, cluster_ip) values |
| 85 | + ('hub-a', 'hub', 1, '10.0.0.3')""" |
| 86 | + ); |
| 87 | + |
| 88 | + assertNull(sessions.findHub("hub-a")); |
| 89 | + assertEquals(new GameServer("hub-a", "10.0.0.3", 0), sessions.findHub("hub-b")); |
| 90 | + } |
64 | 91 | } |
0 commit comments