Skip to content

Commit afb137f

Browse files
committed
Fixed Ktor.lpfcpServer()
1 parent 95abfd2 commit afb137f

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ allprojects {
5555

5656
repositories {
5757
mavenCentral()
58+
mavenLocal() // For easier testing
5859
}
5960
}
6061

core/src/main/java/eth/likespro/lpfcp/LPFCP.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
package eth.likespro.lpfcp
1010

11-
import eth.likespro.commons.reflection.ObjectEncoding.decodeObject
1211
import eth.likespro.commons.models.EncodableResult
1312
import eth.likespro.commons.network.HTTPUtils.post
14-
import eth.likespro.commons.reflection.ReflectionUtils.boxed
13+
import eth.likespro.commons.reflection.ObjectEncoding.decodeObject
1514
import eth.likespro.commons.reflection.ReflectionUtils.getParametrizedType
1615
import org.json.JSONException
1716
import org.json.JSONObject

examples/calculator-java/.idea/vcs.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Ktor {
3232
* @param wait Specifies whether to block the current thread until the engine stops. Defaults to true.
3333
* @return The instance of the started NettyApplicationEngine.
3434
*/
35-
fun start(wait: Boolean): LPFCPServer = this.apply { embeddedServer.engine.start(wait) }
35+
fun start(wait: Boolean): LPFCPServer = this.apply { embeddedServer.start(wait) }
3636

3737
/**
3838
* Stops the Netty application engine with the specified grace period and timeout.

ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTests.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ class KtorTests {
4141
override fun divideSafely(a: Int, b: Int): Int? = if (b == 0) null else a / b
4242
}
4343

44+
val port = 8090
4445
var server: Ktor.LPFCPServer? = null
4546

4647
@JvmStatic
4748
@BeforeAll fun setupKtorServer() {
48-
server = lpfcpServer(calculator).start(wait = false)
49+
server = lpfcpServer(calculator, port).start(wait = false)
4950
}
5051

5152
@JvmStatic
@@ -65,43 +66,43 @@ class KtorTests {
6566

6667

6768
@Test fun ktorServer_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() {
68-
val processor = LPFCP.getProcessor<Calculator>(URI("http://localhost:8080/lpfcp"))
69+
val processor = LPFCP.getProcessor<Calculator>(URI("http://localhost:$port/lpfcp"))
6970
val response = processor.hello()
7071
assertEquals("Hello, World!", response)
7172
}
7273

7374
@Test fun ktorServer_withValidFunctionAndArgs_returnsSuccess() {
74-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
75+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
7576
val response = processor.add(3, 5)
7677
assertEquals(8, response)
7778
}
7879

7980
@Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionReturningNullAndArgs_returnsSuccess() {
80-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
81+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
8182
val response = processor.divideSafely(3, 0)
8283
assertEquals(null, response)
8384
}
8485

8586
@Test fun getProcessor_withLambda_proceedsRequest_withValidOverloadedFunctionAndArgs_returnsSuccess() {
86-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
87+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
8788
val response = processor.add("3", "5")
8889
assertEquals("35", response)
8990
}
9091

9192
@Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgs_returnsSuccess() {
92-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
93+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
9394
val response = processor.add(b = "5")
9495
assertEquals("15", response)
9596
}
9697

9798
@Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgsInReverseOrder_returnsSuccess() {
98-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
99+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
99100
val response = processor.add(b = "5", a = "4")
100101
assertEquals("45", response)
101102
}
102103

103104
@Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsArithmeticException() {
104-
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
105+
val processor = LPFCP.getProcessor<Calculator>("http://localhost:$port/lpfcp")
105106
assertEquals(
106107
ArithmeticException::class.java,
107108
assertThrows<WrappedException.Exception> { processor.divide(5, 0) }.wrappedException.exceptionClass

ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTestsJava.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eth.likespro.lpfcp.ktor;
22

3+
import eth.likespro.commons.models.WrappedException;
34
import eth.likespro.lpfcp.LPFCP;
45
import eth.likespro.lpfcp.LPFCPJava;
56
import org.junit.jupiter.api.AfterAll;
@@ -55,10 +56,11 @@ public Integer divideSafely(int a, int b) {
5556
}
5657

5758
public static CalculatorImpl calculator = new CalculatorImpl();
59+
public static Integer port = 8090;
5860
public static Ktor.LPFCPServer server;
5961

6062
@BeforeAll static void setupKtorServer() {
61-
server = Ktor.INSTANCE.lpfcpServer(calculator, 8080, false).start(false);
63+
server = Ktor.INSTANCE.lpfcpServer(calculator, port, WrappedException.DetailsConfiguration.Companion.getINCLUDE_ALL()).start(false);
6264
}
6365

6466
@AfterAll static void teardownKtorServer() {
@@ -76,13 +78,13 @@ public Integer divideSafely(int a, int b) {
7678

7779

7880
@Test public void ktorServer_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() throws URISyntaxException {
79-
Calculator processor = LPFCPJava.getProcessor(Calculator.class, new URI("http://localhost:8080/lpfcp"));
81+
Calculator processor = LPFCPJava.getProcessor(Calculator.class, new URI("http://localhost:" + port + "/lpfcp"));
8082
String response = processor.hello();
8183
assertEquals("Hello, World!", response);
8284
}
8385

8486
@Test public void ktorServer_withValidFunctionAndArgs_returnsSuccess() {
85-
Calculator processor = LPFCPJava.getProcessor(Calculator.class, "http://localhost:8080/lpfcp");
87+
Calculator processor = LPFCPJava.getProcessor(Calculator.class, "http://localhost:" + port + "/lpfcp");
8688
Integer response = processor.add(3, 5);
8789
assertEquals(8, response);
8890
}

0 commit comments

Comments
 (0)