@@ -126,172 +126,4 @@ void testGetSetRAM() throws IOException {
126126 assertEquals (16 , server .getRAM ().join ().getRam ());
127127 server .setRAM (ram .getRam ()).join ();
128128 }
129-
130- @ Test
131- void testGetPlayerLists () throws IOException {
132- List <String > lists = server .getPlayerLists ().join ();
133- assertNotNull (lists );
134- assertFalse (lists .isEmpty (), "Expected at least one player list, got none" );
135-
136- for (String name : lists ) {
137- assertNotNull (name );
138- PlayerList list = server .getPlayerList (name );
139- assertNotNull (list );
140- assertNotNull (list .getName ());
141- assertNotNull (list .getEntries ());
142- }
143- }
144-
145- @ Test
146- void testRemoveSubscribersWithoutWebsocket () {
147- server .removeStatusSubscriber ((oldServer , newServer ) -> {
148- });
149- server .removeConsoleSubscriber (x -> {
150- });
151- server .removeHeapSubscriber (x -> {
152- });
153- server .removeStatsSubscriber (x -> {
154- });
155- server .removeTickSubscriber (x -> {
156- });
157- }
158-
159- /**
160- * Perform a series of tests that require the server to be online
161- */
162- @ Test
163- void testStartServer () throws IOException , ExecutionException , InterruptedException , TimeoutException {
164- server .fetch ().join ();
165-
166- startServer ();
167- testHeapSubscriber ();
168- testStatsSubscriber ();
169- testTickSubscriber ();
170- testExecuteCommand ();
171- restartServer ();
172- stopServer ();
173-
174- assertNull (server .getWebSocket ());
175- }
176-
177- void testHeapSubscriber () throws ExecutionException , InterruptedException , TimeoutException {
178- CompletableFuture <HeapUsage > heapFuture = new CompletableFuture <>();
179- HeapSubscriber heapSubscriber = heapFuture ::complete ;
180-
181- server .addHeapSubscriber (heapSubscriber );
182- HeapUsage heapUsage = heapFuture .get (1 , TimeUnit .MINUTES );
183- server .removeHeapSubscriber (heapSubscriber );
184-
185- assertNotNull (heapUsage );
186- assertTrue (heapUsage .getUsage () > 0 , "Expected heap usage to be greater than 0" );
187- }
188-
189- void testStatsSubscriber () throws ExecutionException , InterruptedException , TimeoutException {
190- CompletableFuture <StatsData > statsFuture = new CompletableFuture <>();
191- StatsSubscriber statsSubscriber = statsFuture ::complete ;
192-
193- server .addStatsSubscriber (statsSubscriber );
194- StatsData stats = statsFuture .get (1 , TimeUnit .MINUTES );
195- server .removeStatsSubscriber (statsSubscriber );
196-
197- assertNotNull (stats );
198- assertTrue (stats .getMemory ().getUsage () > 0 , "Expected memory usage to be greater than 0" );
199- assertTrue (stats .getMemory ().getPercent () > 0 , "Expected memory usage to be greater than 0%" );
200- assertTrue (stats .getMemory ().getPercent () < 100 , "Expected memory usage to be less than 100%" );
201- }
202-
203- void testTickSubscriber () throws ExecutionException , InterruptedException , TimeoutException {
204- CompletableFuture <TickData > tickFuture = new CompletableFuture <>();
205- TickSubscriber tickSubscriber = tickFuture ::complete ;
206-
207- server .addTickSubscriber (tickSubscriber );
208- TickData tick = tickFuture .get (1 , TimeUnit .MINUTES );
209- server .removeTickSubscriber (tickSubscriber );
210-
211- assertNotNull (tick );
212- assertTrue (tick .getAverageTickTime () > 0 , "Expected tick time to be greater than 0" );
213- assertTrue (tick .calculateTPS () > 0 , "Expected tps to be greater than 0" );
214- assertTrue (tick .calculateTPS () <= 20 , "Expected memory usage to be greater than 0%" );
215- }
216-
217- void testExecuteCommand () throws IOException , ExecutionException , InterruptedException , TimeoutException {
218- var flagA = new FlagSubscriber ();
219- var flagB = new FlagSubscriber ();
220-
221- server .addConsoleSubscriber (flagA );
222- server .addConsoleSubscriber (flagB );
223-
224- server .executeCommand ("say " + flagA .value ).join ();
225-
226- Server serverWithoutWS = client .getServer (TEST_SERVER_ID );
227- serverWithoutWS .executeCommand ("say " + flagB .value ).join ();
228-
229- flagA .future .get (10 , TimeUnit .SECONDS );
230- flagB .future .get (10 , TimeUnit .SECONDS );
231-
232- server .removeConsoleSubscriber (flagA );
233- server .removeConsoleSubscriber (flagB );
234- }
235-
236- void startServer () throws IOException , ExecutionException , InterruptedException , TimeoutException {
237- assertTrue (server .hasStatus (ServerStatus .GROUP_OFFLINE ));
238-
239- AtomicBoolean receivedStatusUpdate = new AtomicBoolean (false );
240- var statusSubscriber = new ServerStatusSubscriber () {
241- @ Override
242- public void handleStatusUpdate (Server oldServer , Server newServer ) {
243- receivedStatusUpdate .set (true );
244- assertSame (server , newServer );
245- }
246- };
247- server .addStatusSubscriber (statusSubscriber );
248-
249- server .start ().join ();
250- server .waitForStatus (ServerStatus .ONLINE ).get (3 , TimeUnit .MINUTES );
251- assertEquals (ServerStatus .ONLINE , server .getStatus ());
252-
253- server .removeStatusSubscriber (statusSubscriber );
254- assertTrue (receivedStatusUpdate .get ());
255- }
256-
257- void restartServer () throws IOException , ExecutionException , InterruptedException , TimeoutException {
258- assertEquals (ServerStatus .ONLINE , server .getStatus ());
259-
260- var restartingFuture = server .waitForStatus (ServerStatus .RESTARTING );
261- assertNotNull (server .getWebSocket ());
262- server .getWebSocket ().waitForReady ().get (1 , TimeUnit .MINUTES );
263-
264- server .restart ().join ();
265- restartingFuture .get (1 , TimeUnit .MINUTES );
266- assertEquals (ServerStatus .RESTARTING , server .getStatus ());
267-
268-
269- server .waitForStatus (ServerStatus .ONLINE ).get (3 , TimeUnit .MINUTES );
270- assertEquals (ServerStatus .ONLINE , server .getStatus ());
271- }
272-
273- void stopServer () throws IOException , ExecutionException , InterruptedException , TimeoutException {
274- assertFalse (server .hasStatus (ServerStatus .GROUP_OFFLINE ));
275- assertFalse (server .hasStatus (ServerStatus .GROUP_STOPPING ));
276-
277- server .stop ().join ();
278- server .waitForStatus (ServerStatus .GROUP_OFFLINE ).get (3 , TimeUnit .MINUTES );
279- assertTrue (server .hasStatus (ServerStatus .GROUP_OFFLINE ), "Expected server to be offline or crashed" );
280- }
281-
282- private static class FlagSubscriber implements ConsoleSubscriber {
283- final String value ;
284- final CompletableFuture <Void > future = new CompletableFuture <>();
285-
286- public FlagSubscriber () {
287- this .value = "exaroton-api-tests-" + new Random ().nextInt ();
288- }
289-
290- @ Override
291- public void handleLine (String message ) {
292- if (message .contains (value )) {
293- future .complete (null );
294- }
295- }
296- }
297129}
0 commit comments