Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: java 17 for spring samples and maven archetypes #1156

Merged
merged 13 commits into from
Oct 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>${package}.Main</mainClass>

<jdk.target>11</jdk.target>
<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<kalix-sdk.version>@project.version@</kalix-sdk.version>
Expand Down Expand Up @@ -122,7 +122,7 @@
<name>${D}{dockerImage}:%l</name>
<build>
<!-- Base Docker image which contains jre-->
<from>docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot</from>
<from>docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine</from>
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>${package}.Main</mainClass>

<jdk.target>11</jdk.target>
<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<kalix-sdk.version>@project.version@</kalix-sdk.version>
Expand Down Expand Up @@ -122,7 +122,7 @@
<name>${D}{dockerImage}:%l</name>
<build>
<!-- Base Docker image which contains jre-->
<from>docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot</from>
<from>docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine</from>
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>${package}.Main</mainClass>

<jdk.target>11</jdk.target>
<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<kalix-sdk.version>@project.version@</kalix-sdk.version>
Expand Down Expand Up @@ -91,7 +91,7 @@
<name>${dockerImage}:%l</name>
<build>
<!-- Base Docker image which contains jre-->
<from>docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot</from>
<from>docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine</from>
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down
6 changes: 3 additions & 3 deletions samples/spring-eventsourced-counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ With both the proxy and your application running, once you have defined endpoint

- increase (or create) a counter named `hello` with value `10`
```shell
curl -i -XPOST localhost:9000/counter/hello/increase/10
curl -XPOST localhost:9000/counter/hello/increase/10
```

- retrieve the value of a counter named `hello`
```shell
curl -i -XGET localhost:9000/counter/hello
curl -XGET localhost:9000/counter/hello
```

- multiply existing counter named `hello` by value `5`
```shell
curl -i -XPOST localhost:9000/counter/hello/multiply/5
curl -XPOST localhost:9000/counter/hello/multiply/5
```

### Deploy
Expand Down
4 changes: 2 additions & 2 deletions samples/spring-eventsourced-counter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>com.example.Main</mainClass>

<jdk.target>11</jdk.target>
<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<kalix-sdk.version>1.0.8</kalix-sdk.version>
Expand Down Expand Up @@ -91,7 +91,7 @@
<name>${dockerImage}:%l</name>
<build>
<!-- Base Docker image which contains jre-->
<from>docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot</from>
<from>docker.io/library/eclipse-temurin:${jdk.target}-alpine</from>
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import static com.example.CounterEvent.ValueIncreased;
import static com.example.CounterEvent.ValueMultiplied;

@Entity(entityKey = "id", entityType = "counter")
@RequestMapping("/counter/{id}")
public class Counter extends EventSourcedEntity<Integer> {
Expand Down Expand Up @@ -58,12 +61,12 @@ public Effect<String> multiply(@PathVariable Integer value) {

@EventHandler
public Integer handleIncrease(ValueIncreased value) {
return currentState() + value.value;
return currentState() + value.value();
}

@EventHandler
public Integer handleMultiply(ValueMultiplied value) {
return currentState() * value.value;
return currentState() * value.value();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

public sealed interface CounterEvent {
aludwiko marked this conversation as resolved.
Show resolved Hide resolved

record ValueIncreased(int value) implements CounterEvent {
}

record ValueMultiplied(int value) implements CounterEvent {
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import kalix.javasdk.testkit.EventSourcedResult;
import kalix.springsdk.testkit.EventSourcedTestKit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static com.example.CounterEvent.ValueIncreased;
import static com.example.CounterEvent.ValueMultiplied;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down
13 changes: 7 additions & 6 deletions samples/spring-eventsourced-customer-registry/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
Expand All @@ -11,12 +12,12 @@
<properties>

<!-- TODO Update to your own Docker repository or Docker Hub scope -->
<dockerImage>my-docker-repo/${project.artifactId}</dockerImage>
<dockerImage>aludwiko/${project.artifactId}</dockerImage>
aludwiko marked this conversation as resolved.
Show resolved Hide resolved
aludwiko marked this conversation as resolved.
Show resolved Hide resolved
<dockerTag>${project.version}-${build.timestamp}</dockerTag>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>customer.Main</mainClass>

<jdk.target>11</jdk.target>
<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<kalix-sdk.version>1.0.8</kalix-sdk.version>
Expand Down Expand Up @@ -123,7 +124,7 @@
<name>${dockerImage}:%l</name>
<build>
<!-- Base Docker image which contains jre-->
<from>docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot</from>
<from>docker.io/library/eclipse-temurin:${jdk.target}-alpine</from>
aludwiko marked this conversation as resolved.
Show resolved Hide resolved
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down Expand Up @@ -307,12 +308,12 @@
<dependency>
<groupId>io.kalix</groupId>
<artifactId>kalix-spring-sdk</artifactId>
<version>${kalix-sdk.version}</version>
<version>1.0.8-14-fedc8579-dev-SNAPSHOT</version>
aludwiko marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.kalix</groupId>
<artifactId>kalix-spring-sdk-testkit</artifactId>
<version>${kalix-sdk.version}</version>
<version>1.0.8-14-fedc8579-dev-SNAPSHOT</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CustomerIntegrationTest extends KalixIntegrationTestKitSupport {
private Duration timeout = Duration.of(5, SECONDS);

@Test
public void create() throws InterruptedException {
public void create() {
String id = UUID.randomUUID().toString();
Customer customer = new Customer(id, "foo@example.com", "Johanna", null);

Expand All @@ -47,11 +47,11 @@ public void create() throws InterruptedException {
.block(timeout);

Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
Assertions.assertEquals("Johanna", getCustomerById(id).name);
Assertions.assertEquals("Johanna", getCustomerById(id).name());
}

@Test
public void changeName() throws InterruptedException {
public void changeName() {
String id = UUID.randomUUID().toString();
Customer customer = new Customer(id, "foo@example.com", "Johanna", null);

Expand All @@ -74,11 +74,11 @@ public void changeName() throws InterruptedException {


Assertions.assertEquals(HttpStatus.OK, resUpdate.getStatusCode());
Assertions.assertEquals("Katarina", getCustomerById(id).name);
Assertions.assertEquals("Katarina", getCustomerById(id).name());
}

@Test
public void changeAddress() throws InterruptedException {
public void changeAddress() {
String id = UUID.randomUUID().toString();
Customer customer = new Customer(id, "foo@example.com", "Johanna", null);

Expand All @@ -103,12 +103,12 @@ public void changeAddress() throws InterruptedException {


Assertions.assertEquals(HttpStatus.OK, resUpdate.getStatusCode());
Assertions.assertEquals("Elm st. 5", getCustomerById(id).address.street);
Assertions.assertEquals("Elm st. 5", getCustomerById(id).address().street());
}


@Test
public void findByName() throws Exception {
public void findByName() {
String id = UUID.randomUUID().toString();
Customer customer = new Customer(id, "foo@example.com", "Foo", null);
ResponseEntity<String> response =
Expand All @@ -131,13 +131,13 @@ public void findByName() throws Exception {
.retrieve()
.bodyToMono(CustomerView.class)
.block(timeout)
.name,
.name(),
new IsEqual("Foo")
);
}

@Test
public void findByEmail() throws Exception {
public void findByEmail() {
String id = UUID.randomUUID().toString();
Customer customer = new Customer(id, "bar@example.com", "Bar", null);
ResponseEntity<String> response =
Expand All @@ -160,7 +160,7 @@ public void findByEmail() throws Exception {
.retrieve()
.bodyToMono(CustomerView.class)
.block(timeout)
.name,
.name(),
new IsEqual("Bar")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,4 @@
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Address {
public String street;
public String city;

@JsonCreator
public Address(@JsonProperty("street") String street, @JsonProperty("city") String city) {
this.street = street;
this.city = city;
}
}
public record Address(String street, String city) {}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,7 @@
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Customer {
public String customerId;
public String email;
public String name;
public Address address;

// TODO: remove JsonCreator and JsonProperty
// this should not be needed and it's not when running the application
// however, the integration tests seems to need it.
// Probably related to how the compiler is configured for the tests?
@JsonCreator
public Customer(@JsonProperty("customerId") String customerId,
@JsonProperty("email") String email,
@JsonProperty("name") String name,
@JsonProperty("address") Address address) {
this.customerId = customerId;
this.email = email;
this.name = name;
this.address = address;
}

public record Customer(String customerId, String email, String name, Address address) {

public Customer withName(String newName) {
return new Customer(customerId, email, newName, address);
Expand Down
Loading