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
4 changes: 2 additions & 2 deletions samples/spring-customer-registry-views-quickstart/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>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 +123,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 @@ -46,7 +46,7 @@ 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
Expand All @@ -73,7 +73,7 @@ public void changeName() throws InterruptedException {


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

@Test
Expand Down Expand Up @@ -102,7 +102,7 @@ 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());
}


Expand Down Expand Up @@ -131,7 +131,7 @@ public void findByName() throws Exception {
.retrieve()
.bodyToMono(Customer.class)
.block(timeout)
.name,
.name(),
new IsEqual("Foo")
);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public void findByEmail() throws Exception {
.retrieve()
.bodyToMono(Customer.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,5 @@
* 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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,13 @@
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public record Customer(String customerId, String email, String name, Address address) {

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 Customer withName(String newName){
return new Customer(customerId, email, newName, address);
}


public Customer withAddress(Address newAddress){
return new Customer(customerId, email, name, newAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ public ValueEntity.Effect<Customer> getCustomer() {

@PostMapping("/changeName/{newName}")
public Effect<String> changeName(@PathVariable String newName) {
Customer customer = currentState();
customer.name = newName;
return effects().updateState(customer).thenReply("OK");
Customer updatedCustomer = currentState().withName(newName);
return effects().updateState(updatedCustomer).thenReply("OK");
}

@PostMapping("/changeAddress")
public Effect<String> changeAddress(@RequestBody Address newAddress) {
Customer customer = currentState();
customer.address = newAddress;
return effects().updateState(customer).thenReply("OK");
Customer updatedCustomer = currentState().withAddress(newAddress);
return effects().updateState(updatedCustomer).thenReply("OK");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void testCustomerNameChange() {
{
ValueEntityResult<String> result = testKit.call(e -> e.changeName("FooBar"));
assertEquals("OK", result.getReply());
assertEquals("FooBar", testKit.getState().name);
assertEquals("FooBar", testKit.getState().name());
}

}
Expand All @@ -43,8 +43,8 @@ public void testCustomerAddressChange() {
Address newAddress = new Address("Sesame Street", "Sesame City");
ValueEntityResult<String> result = testKit.call(e -> e.changeAddress(newAddress));
assertEquals("OK", result.getReply());
assertEquals("Sesame Street", testKit.getState().address.street);
assertEquals("Sesame City", testKit.getState().address.city);
assertEquals("Sesame Street", testKit.getState().address().street());
assertEquals("Sesame City", testKit.getState().address().city());
}

}
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 {

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
7 changes: 4 additions & 3 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 @@ -16,7 +17,7 @@
<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>
<createImageOptions>
<platform>linux/amd64</platform>
</createImageOptions>
Expand Down
Loading