File tree Expand file tree Collapse file tree 6 files changed +19
-13
lines changed
app/src/test/java/dev/keva/app
main/java/dev/keva/core/server Expand file tree Collapse file tree 6 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 11package dev .keva .app ;
22
3- import dev .keva .app .Application ;
43import lombok .val ;
54import org .junit .jupiter .api .Test ;
65import redis .clients .jedis .Jedis ;
Original file line number Diff line number Diff line change 2020import lombok .extern .slf4j .Slf4j ;
2121
2222import java .lang .reflect .InvocationTargetException ;
23+ import java .util .concurrent .CompletableFuture ;
2324import java .util .concurrent .TimeUnit ;
2425
2526@ Slf4j
2627@ Component
2728@ ComponentScan ("dev.keva.core" )
2829public class KevaServer implements Server {
30+ private final CompletableFuture <Void > ready = new CompletableFuture <>();
31+
2932 private static final String KEVA_BANNER = "\n " +
3033 " _ __ ___ __ __ _ \n " +
3134 " | |/ / | __| \\ \\ / / /_\\ \n " +
@@ -115,18 +118,27 @@ public void run() {
115118 stopwatch .elapsed (TimeUnit .MILLISECONDS ));
116119 log .info ("Ready to accept connections" );
117120
121+ ready .complete (null );
122+
118123 channel = sync .channel ();
119124 channel .closeFuture ().sync ();
120125 } catch (InterruptedException e ) {
121126 log .error ("Failed to start server: " , e );
122127 Thread .currentThread ().interrupt ();
123128 } catch (Exception e ) {
124129 log .error ("Failed to start server: " , e );
130+ // Release err future
131+ ready .completeExceptionally (e );
125132 } finally {
126133 stopwatch .stop ();
127134 }
128135 }
129136
137+ @ Override
138+ public void await () {
139+ this .ready .join ();
140+ }
141+
130142 @ Override
131143 public void clear () {
132144 database .flush ();
Original file line number Diff line number Diff line change 33public interface Server extends Runnable {
44 void run ();
55
6+ void await ();
7+
68 void shutdown ();
79
810 void clear ();
Original file line number Diff line number Diff line change 1111import org .junit .jupiter .api .BeforeEach ;
1212import redis .clients .jedis .Jedis ;
1313
14- import java .util .concurrent .TimeUnit ;
15-
1614@ Slf4j
1715public class BaseCommandTest {
1816 protected static final String host = "localhost" ;
@@ -21,7 +19,7 @@ public class BaseCommandTest {
2119 protected static Server server ;
2220
2321 @ BeforeAll
24- static void startServer () throws Exception {
22+ static void startServer () {
2523 val config = KevaConfig .builder ()
2624 .persistence (false )
2725 .aof (false )
@@ -41,7 +39,7 @@ static void startServer() throws Exception {
4139 }).start ();
4240
4341 // Wait for server to start
44- TimeUnit . SECONDS . sleep ( 2 );
42+ server . await ( );
4543
4644 jedis = new Jedis (host , port );
4745 jedis .auth ("keva-auth" );
Original file line number Diff line number Diff line change @@ -41,8 +41,7 @@ Server startServer(int port) throws Exception {
4141 }
4242 }).start ();
4343
44- // Wait for server to start
45- TimeUnit .SECONDS .sleep (2 );
44+ server .await ();
4645 return server ;
4746 }
4847
@@ -74,8 +73,7 @@ void sync(int port) throws InterruptedException {
7473 fail (e );
7574 }
7675 jedis .disconnect ();
77- // Wait for the interval to run
78- TimeUnit .SECONDS .sleep (4 );
76+
7977 try {
8078 stop (server );
8179 } catch (Exception e ) {
Original file line number Diff line number Diff line change 77import org .junit .jupiter .api .Timeout ;
88import redis .clients .jedis .Jedis ;
99
10- import java .util .concurrent .TimeUnit ;
11-
1210import static dev .keva .core .utils .PortUtil .getAvailablePort ;
1311import static org .junit .jupiter .api .Assertions .assertEquals ;
1412import static org .junit .jupiter .api .Assertions .fail ;
@@ -35,8 +33,7 @@ Server startServer(int port) throws Exception {
3533 }
3634 }).start ();
3735
38- // Wait for server to start
39- TimeUnit .SECONDS .sleep (2 );
36+ server .await ();
4037 return server ;
4138 }
4239
You can’t perform that action at this time.
0 commit comments