Skip to content

Commit 0f2f48c

Browse files
committed
fix: java 17 for kalix action example
1 parent be8e5b4 commit 0f2f48c

File tree

9 files changed

+47
-32
lines changed

9 files changed

+47
-32
lines changed

samples/spring-eventsourced-customer-registry/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>com.example</groupId>
@@ -11,7 +12,7 @@
1112
<properties>
1213

1314
<!-- TODO Update to your own Docker repository or Docker Hub scope -->
14-
<dockerImage>my-docker-repo/${project.artifactId}</dockerImage>
15+
<dockerImage>aludwiko/${project.artifactId}</dockerImage>
1516
<dockerTag>${project.version}-${build.timestamp}</dockerTag>
1617
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
1718
<mainClass>customer.Main</mainClass>
@@ -307,12 +308,12 @@
307308
<dependency>
308309
<groupId>io.kalix</groupId>
309310
<artifactId>kalix-spring-sdk</artifactId>
310-
<version>${kalix-sdk.version}</version>
311+
<version>1.0.8-14-fedc8579-dev-SNAPSHOT</version>
311312
</dependency>
312313
<dependency>
313314
<groupId>io.kalix</groupId>
314315
<artifactId>kalix-spring-sdk-testkit</artifactId>
315-
<version>${kalix-sdk.version}</version>
316+
<version>1.0.8-14-fedc8579-dev-SNAPSHOT</version>
316317
<scope>test</scope>
317318
</dependency>
318319

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33

44
import com.fasterxml.jackson.annotation.JsonSubTypes;
55
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.annotation.JsonTypeName;
67

78
import static customer.api.CustomerEvent.*;
89

910
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
10-
@JsonSubTypes(
11-
{
12-
@JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"),
13-
@JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"),
14-
@JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed")
15-
})
11+
//@JsonSubTypes(
12+
// {
13+
// @JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"),
14+
// @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"),
15+
// @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed")
16+
// })
1617
public sealed interface CustomerEvent {
1718

19+
@JsonTypeName("customer-created")
1820
record CustomerCreated(String email, String name, Address address) implements CustomerEvent {
1921
}
2022

23+
@JsonTypeName("name-changed")
2124
record NameChanged(String newName) implements CustomerEvent {
2225
}
2326

27+
@JsonTypeName("address-changed")
2428
record AddressChanged(Address address) implements CustomerEvent {
2529
}
2630
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package customer.api;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class JacksonTest {
8+
9+
@Test
10+
public void testCustomerAddressChange() throws JsonProcessingException {
11+
CustomerEvent.CustomerCreated customerCreated = new CustomerEvent.CustomerCreated("email", "name", new Address("street", "some city"));
12+
ObjectMapper mapper = new ObjectMapper();
13+
String valueAsString = mapper.writeValueAsString(customerCreated);
14+
System.out.println(valueAsString);
15+
16+
CustomerEvent customerEvent = mapper.readValue(valueAsString, CustomerEvent.class);
17+
18+
System.out.println(customerEvent);
19+
}
20+
}

samples/spring-fibonacci-action/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
1717
<mainClass>com.example.Main</mainClass>
1818

19-
<jdk.target>11</jdk.target>
19+
<jdk.target>17</jdk.target>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121

2222
<kalix-sdk.version>1.0.8</kalix-sdk.version>
@@ -123,7 +123,7 @@
123123
<name>${dockerImage}:%l</name>
124124
<build>
125125
<!-- Base Docker image which contains jre-->
126-
<from>docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot</from>
126+
<from>docker.io/library/eclipse-temurin:${jdk.target}-alpine</from>
127127
<createImageOptions>
128128
<platform>linux/amd64</platform>
129129
</createImageOptions>

samples/spring-fibonacci-action/src/it/java/com/example/fibonacci/FibonacciActionIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ public class FibonacciActionIntegrationTest extends KalixIntegrationTestKitSuppo
3030
private WebClient webClient;
3131

3232
@Test
33-
public void calculateNextNumber() throws Exception {
33+
public void calculateNextNumber() {
3434

3535
Mono<Number> response =
3636
webClient.get()
3737
.uri("/fibonacci/5/next")
3838
.retrieve().bodyToMono(Number.class);
3939

40-
long next = response.block(Duration.of(5, SECONDS)).value;
40+
long next = response.block(Duration.of(5, SECONDS)).value();
4141
Assertions.assertEquals(8, next);
4242

4343
}
4444

4545
@Test
46-
public void calculateNextNumberWithLimitedFibo() throws Exception {
46+
public void calculateNextNumberWithLimitedFibo() {
4747

4848
Mono<Number> response =
4949
webClient.get()
5050
.uri("/limitedfibonacci/5/next")
5151
.retrieve().bodyToMono(Number.class);
5252

53-
long next = response.block(Duration.of(5, SECONDS)).value;
53+
long next = response.block(Duration.of(5, SECONDS)).value();
5454
Assertions.assertEquals(8, next);
5555

5656
}
5757

5858
@Test
59-
public void wrongNumberReturnsError() throws Exception {
59+
public void wrongNumberReturnsError() {
6060
try {
6161

6262

samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/FibonacciAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Effect<Number> nextNumber(@PathVariable Long number) {
2828

2929
@PostMapping("/next")
3030
public Effect<Number> nextNumber(@RequestBody Number number) {
31-
long num = number.value;
31+
long num = number.value();
3232
if (isFibonacci(num)) {
3333
return effects().reply(new Number(nextFib(num)));
3434
} else {

samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/LimitedFibonacciAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public Effect<Number> nextNumber(@PathVariable Long number) {
3737

3838
@PostMapping("/next")
3939
public Effect<Number> nextNumber(@RequestBody Number number) {
40-
if (number.value < 0 || number.value > 10000) {
40+
if (number.value() < 0 || number.value() > 10000) {
4141
return effects().error("Only numbers between 0 and 10k are allowed", Status.Code.INVALID_ARGUMENT);
4242
} else {
43-
logger.info("Executing POST call to real /fibonacci = " + number.value);
43+
logger.info("Executing POST call to real /fibonacci = " + number.value());
4444
var serviceCall = kalixClient.post("/fibonacci/next", number, Number.class).execute();
4545

4646
return effects().asyncReply(serviceCall);
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
package com.example.fibonacci;
2-
3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
52

6-
public class Number {
7-
8-
public final long value;
9-
10-
@JsonCreator
11-
public Number(@JsonProperty("value") long value) {
12-
this.value = value;
13-
}
3+
public record Number(long value) {
144
}

samples/spring-fibonacci-action/src/test/java/com/example/fibonacci/FibonacciActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void testNextFib() {
1414
ActionTestkit<FibonacciAction> testkit = ActionTestkit.of(FibonacciAction::new);
1515
ActionResult<Number> result = testkit.call(a -> a.nextNumber(3L));
1616
assertTrue(result.isReply());
17-
assertEquals(5L, result.getReply().value);
17+
assertEquals(5L, result.getReply().value());
1818
}
1919

2020
@Test

0 commit comments

Comments
 (0)