From 80179802cb46967cc838f634d7f261281dbcda8c Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Thu, 6 Oct 2022 15:07:13 +0200 Subject: [PATCH 01/13] fix: testing java 17 for samples --- .../pom.xml | 4 +- .../customer/api/CustomerIntegrationTest.java | 20 +++++----- .../src/main/java/customer/api/Address.java | 14 +------ .../java/customer/api/AddressChanged.java | 15 ------- .../src/main/java/customer/api/Customer.java | 25 +----------- .../java/customer/api/CustomerCreated.java | 17 -------- .../java/customer/api/CustomerEntity.java | 13 ++++--- .../main/java/customer/api/CustomerEvent.java | 13 ++++++- .../main/java/customer/api/NameChanged.java | 14 ------- .../main/java/customer/view/CustomerView.java | 39 ++++++------------- .../java/customer/api/CustomerEntityTest.java | 7 ++-- 11 files changed, 49 insertions(+), 132 deletions(-) delete mode 100644 samples/spring-eventsourced-customer-registry/src/main/java/customer/api/AddressChanged.java delete mode 100644 samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerCreated.java delete mode 100644 samples/spring-eventsourced-customer-registry/src/main/java/customer/api/NameChanged.java diff --git a/samples/spring-eventsourced-customer-registry/pom.xml b/samples/spring-eventsourced-customer-registry/pom.xml index fd94004a5b..5c2264ec82 100644 --- a/samples/spring-eventsourced-customer-registry/pom.xml +++ b/samples/spring-eventsourced-customer-registry/pom.xml @@ -16,7 +16,7 @@ yyyyMMddHHmmss customer.Main - 11 + 17 UTF-8 1.0.8 @@ -123,7 +123,7 @@ ${dockerImage}:%l - docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${jdk.target}-alpine linux/amd64 diff --git a/samples/spring-eventsourced-customer-registry/src/it/java/customer/api/CustomerIntegrationTest.java b/samples/spring-eventsourced-customer-registry/src/it/java/customer/api/CustomerIntegrationTest.java index 01c6e5fc2d..3169dbf3bf 100644 --- a/samples/spring-eventsourced-customer-registry/src/it/java/customer/api/CustomerIntegrationTest.java +++ b/samples/spring-eventsourced-customer-registry/src/it/java/customer/api/CustomerIntegrationTest.java @@ -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); @@ -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); @@ -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); @@ -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 response = @@ -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 response = @@ -160,7 +160,7 @@ public void findByEmail() throws Exception { .retrieve() .bodyToMono(CustomerView.class) .block(timeout) - .name, + .name(), new IsEqual("Bar") ); } diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Address.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Address.java index 2edb2e73d9..fbee3c8080 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Address.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Address.java @@ -3,16 +3,4 @@ * Copyright (C) 2009-2022 Lightbend Inc. */ -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) {} diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/AddressChanged.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/AddressChanged.java deleted file mode 100644 index b03e124948..0000000000 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/AddressChanged.java +++ /dev/null @@ -1,15 +0,0 @@ -package customer.api; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AddressChanged implements CustomerEvent { - - final public Address address; - - - @JsonCreator - public AddressChanged(@JsonProperty Address address) { - this.address = address; - } -} diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Customer.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Customer.java index ce59838338..5476a6de3d 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Customer.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Customer.java @@ -3,30 +3,7 @@ * Copyright (C) 2009-2022 Lightbend Inc. */ -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); diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerCreated.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerCreated.java deleted file mode 100644 index 2865f859f8..0000000000 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerCreated.java +++ /dev/null @@ -1,17 +0,0 @@ -package customer.api; - -import com.fasterxml.jackson.annotation.JsonCreator; - -public class CustomerCreated implements CustomerEvent { - - final public String email; - final public String name; - final public Address address; - - @JsonCreator - public CustomerCreated(String email, String name, Address address) { - this.email = email; - this.name = name; - this.address = address;{} - } -} diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEntity.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEntity.java index 07c33dbe20..a286e36c82 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEntity.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEntity.java @@ -18,11 +18,12 @@ import kalix.javasdk.eventsourcedentity.EventSourcedEntity; import kalix.javasdk.eventsourcedentity.EventSourcedEntityContext; -import kalix.javasdk.valueentity.ValueEntity; import kalix.springsdk.annotations.Entity; import kalix.springsdk.annotations.EventHandler; import org.springframework.web.bind.annotation.*; +import static customer.api.CustomerEvent.*; + @Entity(entityKey = "id", entityType = "customer") @RequestMapping("/customer/{id}") public class CustomerEntity extends EventSourcedEntity { @@ -41,13 +42,13 @@ public Effect getCustomer() { @PostMapping("/create") public Effect create(@RequestBody Customer customer) { return effects() - .emitEvent(new CustomerCreated(customer.email, customer.name, customer.address)) + .emitEvent(new CustomerCreated(customer.email(), customer.name(), customer.address())) .thenReply(__ -> "OK"); } @EventHandler public Customer onEvent(CustomerCreated created) { - return new Customer(entityId, created.email, created.name, created.address); + return new Customer(entityId, created.email(), created.name(), created.address()); } @@ -61,7 +62,7 @@ public Effect changeName(@PathVariable String newName) { @EventHandler public Customer onEvent(NameChanged nameChanged) { - return currentState().withName(nameChanged.newName); + return currentState().withName(nameChanged.newName()); } @@ -73,7 +74,7 @@ public Effect changeAddress(@RequestBody Address newAddress) { } @EventHandler - public Customer onEvents(AddressChanged addressChanged){ - return currentState().withAddress(addressChanged.address); + public Customer onEvents(AddressChanged addressChanged) { + return currentState().withAddress(addressChanged.address()); } } diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java index e71b358edf..06894a61f2 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import static customer.api.CustomerEvent.*; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonSubTypes( { @@ -11,5 +13,14 @@ @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"), @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed") }) -public interface CustomerEvent { +public sealed interface CustomerEvent { + + record CustomerCreated(String email, String name, Address address) implements CustomerEvent { + } + + record NameChanged(String newName) implements CustomerEvent { + } + + record AddressChanged(Address address) implements CustomerEvent { + } } diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/NameChanged.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/NameChanged.java deleted file mode 100644 index 76ad15a08b..0000000000 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/NameChanged.java +++ /dev/null @@ -1,14 +0,0 @@ -package customer.api; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class NameChanged implements CustomerEvent { - - final public String newName; - - @JsonCreator - public NameChanged(@JsonProperty String newName) { - this.newName = newName; - } -} diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/view/CustomerView.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/view/CustomerView.java index c76186531a..24acda4be4 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/view/CustomerView.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/view/CustomerView.java @@ -1,30 +1,20 @@ package customer.view; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import customer.api.*; +import customer.api.Address; +import customer.api.CustomerEvent; import java.util.Optional; -public class CustomerView { - final public String email; - final public String name; - final public Address address; - - @JsonCreator - public CustomerView(@JsonProperty("email") String email, @JsonProperty("name") String name, @JsonProperty("address") Address address) { - this.email = email; - this.name = name; - this.address = address; - } +import static customer.api.CustomerEvent.*; +public record CustomerView(String email, String name, Address address) { public CustomerView withName(String newName) { - return new CustomerView( email, newName, address); + return new CustomerView(email, newName, address); } public CustomerView withAddress(Address newAddress) { - return new CustomerView( email, name, newAddress); + return new CustomerView(email, name, newAddress); } /** @@ -35,18 +25,15 @@ public static Optional onEvent(CustomerView state, CustomerEvent e if (state == null) { // the only event we can receive when state is null is the CustomerCreated - if (event instanceof CustomerCreated) { - CustomerCreated created = (CustomerCreated) event; - return Optional.of(new CustomerView(created.email, created.name, created.address)); + if (event instanceof CustomerCreated created) { + return Optional.of(new CustomerView(created.email(), created.name(), created.address())); } } else { // when not null, we can receive the other events - if (event instanceof NameChanged) { - NameChanged nameChanged = (NameChanged) event; - return Optional.of(state.withName(nameChanged.newName)); - } else if (event instanceof AddressChanged) { - AddressChanged addressChanged = (AddressChanged) event; - return Optional.of(state.withAddress(addressChanged.address)); + if (event instanceof NameChanged nameChanged) { + return Optional.of(state.withName(nameChanged.newName())); + } else if (event instanceof AddressChanged addressChanged) { + return Optional.of(state.withAddress(addressChanged.address())); } } @@ -54,6 +41,4 @@ public static Optional onEvent(CustomerView state, CustomerEvent e // That case won't happen as the delivery ordering is guaranteed, but we need to keep the compiler happy return Optional.empty(); } - - } diff --git a/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/CustomerEntityTest.java b/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/CustomerEntityTest.java index 37c8ffaeee..5a9678dcfd 100644 --- a/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/CustomerEntityTest.java +++ b/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/CustomerEntityTest.java @@ -4,6 +4,7 @@ import kalix.springsdk.testkit.EventSourcedTestKit; import org.junit.jupiter.api.Test; +import static customer.api.CustomerEvent.*; import static org.junit.jupiter.api.Assertions.assertEquals; public class CustomerEntityTest { @@ -25,7 +26,7 @@ public void testCustomerNameChange() { { EventSourcedResult result = testKit.call(e -> e.changeName("FooBar")); assertEquals("OK", result.getReply()); - assertEquals("FooBar", testKit.getState().name); + assertEquals("FooBar", testKit.getState().name()); result.getNextEventOfType(NameChanged.class); } @@ -45,8 +46,8 @@ public void testCustomerAddressChange() { Address newAddress = new Address("Sesame Street", "Sesame City"); EventSourcedResult 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()); result.getNextEventOfType(AddressChanged.class); } From be8e5b438d7904d496457a3441b6d1e53b74cbf6 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Thu, 6 Oct 2022 15:31:19 +0200 Subject: [PATCH 02/13] fix: java 17 for maven archetypes --- .../src/main/resources/archetype-resources/pom.xml | 4 ++-- .../src/main/resources/archetype-resources/pom.xml | 4 ++-- .../src/main/resources/archetype-resources/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml b/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml index b7ff0f9255..6218a056b8 100644 --- a/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml +++ b/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml @@ -17,7 +17,7 @@ yyyyMMddHHmmss ${package}.Main - 11 + 17 UTF-8 @project.version@ @@ -122,7 +122,7 @@ ${D}{dockerImage}:%l - docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine linux/amd64 diff --git a/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml b/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml index b7ff0f9255..6218a056b8 100644 --- a/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml +++ b/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml @@ -17,7 +17,7 @@ yyyyMMddHHmmss ${package}.Main - 11 + 17 UTF-8 @project.version@ @@ -122,7 +122,7 @@ ${D}{dockerImage}:%l - docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine linux/amd64 diff --git a/maven-java/kalix-spring-boot-archetype/src/main/resources/archetype-resources/pom.xml b/maven-java/kalix-spring-boot-archetype/src/main/resources/archetype-resources/pom.xml index fdc13f9a35..3e5b812540 100644 --- a/maven-java/kalix-spring-boot-archetype/src/main/resources/archetype-resources/pom.xml +++ b/maven-java/kalix-spring-boot-archetype/src/main/resources/archetype-resources/pom.xml @@ -16,7 +16,7 @@ yyyyMMddHHmmss ${package}.Main - 11 + 17 UTF-8 @project.version@ @@ -91,7 +91,7 @@ ${dockerImage}:%l - docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine linux/amd64 From 0f2f48cae941b4f89b0c170b62ee171a01c74a11 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Thu, 6 Oct 2022 16:37:43 +0200 Subject: [PATCH 03/13] fix: java 17 for kalix action example --- .../pom.xml | 9 +++++---- .../main/java/customer/api/CustomerEvent.java | 16 +++++++++------ .../test/java/customer/api/JacksonTest.java | 20 +++++++++++++++++++ samples/spring-fibonacci-action/pom.xml | 4 ++-- .../FibonacciActionIntegrationTest.java | 10 +++++----- .../example/fibonacci/FibonacciAction.java | 2 +- .../fibonacci/LimitedFibonacciAction.java | 4 ++-- .../java/com/example/fibonacci/Number.java | 12 +---------- .../fibonacci/FibonacciActionTest.java | 2 +- 9 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java diff --git a/samples/spring-eventsourced-customer-registry/pom.xml b/samples/spring-eventsourced-customer-registry/pom.xml index 5c2264ec82..8e8a007104 100644 --- a/samples/spring-eventsourced-customer-registry/pom.xml +++ b/samples/spring-eventsourced-customer-registry/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.example @@ -11,7 +12,7 @@ - my-docker-repo/${project.artifactId} + aludwiko/${project.artifactId} ${project.version}-${build.timestamp} yyyyMMddHHmmss customer.Main @@ -307,12 +308,12 @@ io.kalix kalix-spring-sdk - ${kalix-sdk.version} + 1.0.8-14-fedc8579-dev-SNAPSHOT io.kalix kalix-spring-sdk-testkit - ${kalix-sdk.version} + 1.0.8-14-fedc8579-dev-SNAPSHOT test diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java index 06894a61f2..7c75860fe4 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java @@ -3,24 +3,28 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; import static customer.api.CustomerEvent.*; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -@JsonSubTypes( - { - @JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"), - @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"), - @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed") - }) +//@JsonSubTypes( +// { +// @JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"), +// @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"), +// @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed") +// }) public sealed interface CustomerEvent { + @JsonTypeName("customer-created") record CustomerCreated(String email, String name, Address address) implements CustomerEvent { } + @JsonTypeName("name-changed") record NameChanged(String newName) implements CustomerEvent { } + @JsonTypeName("address-changed") record AddressChanged(Address address) implements CustomerEvent { } } diff --git a/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java b/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java new file mode 100644 index 0000000000..241fa3c3c2 --- /dev/null +++ b/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java @@ -0,0 +1,20 @@ +package customer.api; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +public class JacksonTest { + + @Test + public void testCustomerAddressChange() throws JsonProcessingException { + CustomerEvent.CustomerCreated customerCreated = new CustomerEvent.CustomerCreated("email", "name", new Address("street", "some city")); + ObjectMapper mapper = new ObjectMapper(); + String valueAsString = mapper.writeValueAsString(customerCreated); + System.out.println(valueAsString); + + CustomerEvent customerEvent = mapper.readValue(valueAsString, CustomerEvent.class); + + System.out.println(customerEvent); + } +} diff --git a/samples/spring-fibonacci-action/pom.xml b/samples/spring-fibonacci-action/pom.xml index 957390d26d..6c7a8484a5 100644 --- a/samples/spring-fibonacci-action/pom.xml +++ b/samples/spring-fibonacci-action/pom.xml @@ -16,7 +16,7 @@ yyyyMMddHHmmss com.example.Main - 11 + 17 UTF-8 1.0.8 @@ -123,7 +123,7 @@ ${dockerImage}:%l - docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${jdk.target}-alpine linux/amd64 diff --git a/samples/spring-fibonacci-action/src/it/java/com/example/fibonacci/FibonacciActionIntegrationTest.java b/samples/spring-fibonacci-action/src/it/java/com/example/fibonacci/FibonacciActionIntegrationTest.java index bc355dd83f..ccfd9fd24d 100644 --- a/samples/spring-fibonacci-action/src/it/java/com/example/fibonacci/FibonacciActionIntegrationTest.java +++ b/samples/spring-fibonacci-action/src/it/java/com/example/fibonacci/FibonacciActionIntegrationTest.java @@ -30,33 +30,33 @@ public class FibonacciActionIntegrationTest extends KalixIntegrationTestKitSuppo private WebClient webClient; @Test - public void calculateNextNumber() throws Exception { + public void calculateNextNumber() { Mono response = webClient.get() .uri("/fibonacci/5/next") .retrieve().bodyToMono(Number.class); - long next = response.block(Duration.of(5, SECONDS)).value; + long next = response.block(Duration.of(5, SECONDS)).value(); Assertions.assertEquals(8, next); } @Test - public void calculateNextNumberWithLimitedFibo() throws Exception { + public void calculateNextNumberWithLimitedFibo() { Mono response = webClient.get() .uri("/limitedfibonacci/5/next") .retrieve().bodyToMono(Number.class); - long next = response.block(Duration.of(5, SECONDS)).value; + long next = response.block(Duration.of(5, SECONDS)).value(); Assertions.assertEquals(8, next); } @Test - public void wrongNumberReturnsError() throws Exception { + public void wrongNumberReturnsError() { try { diff --git a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/FibonacciAction.java b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/FibonacciAction.java index 75ddb4f73f..3341826fe8 100644 --- a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/FibonacciAction.java +++ b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/FibonacciAction.java @@ -28,7 +28,7 @@ public Effect nextNumber(@PathVariable Long number) { @PostMapping("/next") public Effect nextNumber(@RequestBody Number number) { - long num = number.value; + long num = number.value(); if (isFibonacci(num)) { return effects().reply(new Number(nextFib(num))); } else { diff --git a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/LimitedFibonacciAction.java b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/LimitedFibonacciAction.java index d72448c557..d09c419200 100644 --- a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/LimitedFibonacciAction.java +++ b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/LimitedFibonacciAction.java @@ -37,10 +37,10 @@ public Effect nextNumber(@PathVariable Long number) { @PostMapping("/next") public Effect nextNumber(@RequestBody Number number) { - if (number.value < 0 || number.value > 10000) { + if (number.value() < 0 || number.value() > 10000) { return effects().error("Only numbers between 0 and 10k are allowed", Status.Code.INVALID_ARGUMENT); } else { - logger.info("Executing POST call to real /fibonacci = " + number.value); + logger.info("Executing POST call to real /fibonacci = " + number.value()); var serviceCall = kalixClient.post("/fibonacci/next", number, Number.class).execute(); return effects().asyncReply(serviceCall); diff --git a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/Number.java b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/Number.java index 7ff2db5e91..1a49904bb4 100644 --- a/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/Number.java +++ b/samples/spring-fibonacci-action/src/main/java/com/example/fibonacci/Number.java @@ -1,14 +1,4 @@ package com.example.fibonacci; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -public class Number { - - public final long value; - - @JsonCreator - public Number(@JsonProperty("value") long value) { - this.value = value; - } +public record Number(long value) { } diff --git a/samples/spring-fibonacci-action/src/test/java/com/example/fibonacci/FibonacciActionTest.java b/samples/spring-fibonacci-action/src/test/java/com/example/fibonacci/FibonacciActionTest.java index f262a7c4f0..b9f4e271fa 100644 --- a/samples/spring-fibonacci-action/src/test/java/com/example/fibonacci/FibonacciActionTest.java +++ b/samples/spring-fibonacci-action/src/test/java/com/example/fibonacci/FibonacciActionTest.java @@ -14,7 +14,7 @@ public void testNextFib() { ActionTestkit testkit = ActionTestkit.of(FibonacciAction::new); ActionResult result = testkit.call(a -> a.nextNumber(3L)); assertTrue(result.isReply()); - assertEquals(5L, result.getReply().value); + assertEquals(5L, result.getReply().value()); } @Test From 5578d1fdfdd50dab40745cbe9cbd11b1e9a817c9 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Thu, 6 Oct 2022 17:04:07 +0200 Subject: [PATCH 04/13] fix: java 17 for event sourced counter sample --- samples/spring-eventsourced-counter/README.md | 6 ++-- samples/spring-eventsourced-counter/pom.xml | 4 +-- .../src/main/java/com/example/Counter.java | 7 +++-- .../main/java/com/example/CounterEvent.java | 10 +++++++ .../main/java/com/example/ValueIncreased.java | 30 ------------------- .../java/com/example/ValueMultiplied.java | 29 ------------------ .../test/java/com/example/CounterTest.java | 3 +- samples/spring-fibonacci-action/pom.xml | 6 ++-- 8 files changed, 25 insertions(+), 70 deletions(-) create mode 100644 samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java delete mode 100644 samples/spring-eventsourced-counter/src/main/java/com/example/ValueIncreased.java delete mode 100644 samples/spring-eventsourced-counter/src/main/java/com/example/ValueMultiplied.java diff --git a/samples/spring-eventsourced-counter/README.md b/samples/spring-eventsourced-counter/README.md index f50749a93d..e031d7ccaa 100644 --- a/samples/spring-eventsourced-counter/README.md +++ b/samples/spring-eventsourced-counter/README.md @@ -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 diff --git a/samples/spring-eventsourced-counter/pom.xml b/samples/spring-eventsourced-counter/pom.xml index 1b2a97f9dd..fa5e65b0f5 100644 --- a/samples/spring-eventsourced-counter/pom.xml +++ b/samples/spring-eventsourced-counter/pom.xml @@ -16,7 +16,7 @@ yyyyMMddHHmmss com.example.Main - 11 + 17 UTF-8 1.0.8 @@ -91,7 +91,7 @@ ${dockerImage}:%l - docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${jdk.target}-alpine linux/amd64 diff --git a/samples/spring-eventsourced-counter/src/main/java/com/example/Counter.java b/samples/spring-eventsourced-counter/src/main/java/com/example/Counter.java index 7187844a40..ce3b5d2b6c 100644 --- a/samples/spring-eventsourced-counter/src/main/java/com/example/Counter.java +++ b/samples/spring-eventsourced-counter/src/main/java/com/example/Counter.java @@ -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 { @@ -58,12 +61,12 @@ public Effect 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(); } } diff --git a/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java b/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java new file mode 100644 index 0000000000..2a851425dd --- /dev/null +++ b/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java @@ -0,0 +1,10 @@ +package com.example; + +public sealed interface CounterEvent { + + record ValueIncreased(int value) implements CounterEvent { + } + + record ValueMultiplied(int value) implements CounterEvent { + } +} diff --git a/samples/spring-eventsourced-counter/src/main/java/com/example/ValueIncreased.java b/samples/spring-eventsourced-counter/src/main/java/com/example/ValueIncreased.java deleted file mode 100644 index abac9507ae..0000000000 --- a/samples/spring-eventsourced-counter/src/main/java/com/example/ValueIncreased.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2021 Lightbend Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ValueIncreased { - - public final int value; - - @JsonCreator - public ValueIncreased(@JsonProperty int value) { - this.value = value; - } -} diff --git a/samples/spring-eventsourced-counter/src/main/java/com/example/ValueMultiplied.java b/samples/spring-eventsourced-counter/src/main/java/com/example/ValueMultiplied.java deleted file mode 100644 index d464626764..0000000000 --- a/samples/spring-eventsourced-counter/src/main/java/com/example/ValueMultiplied.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 Lightbend Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ValueMultiplied { - public final int value; - - @JsonCreator - public ValueMultiplied(@JsonProperty Integer value) { - this.value = value; - } -} diff --git a/samples/spring-eventsourced-counter/src/test/java/com/example/CounterTest.java b/samples/spring-eventsourced-counter/src/test/java/com/example/CounterTest.java index d6ac5bd0df..0714c64583 100644 --- a/samples/spring-eventsourced-counter/src/test/java/com/example/CounterTest.java +++ b/samples/spring-eventsourced-counter/src/test/java/com/example/CounterTest.java @@ -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; diff --git a/samples/spring-fibonacci-action/pom.xml b/samples/spring-fibonacci-action/pom.xml index 6c7a8484a5..d42fda1658 100644 --- a/samples/spring-fibonacci-action/pom.xml +++ b/samples/spring-fibonacci-action/pom.xml @@ -11,7 +11,7 @@ - my-docker-repo/${project.artifactId} + aludwiko/${project.artifactId} ${project.version}-${build.timestamp} yyyyMMddHHmmss com.example.Main @@ -307,12 +307,12 @@ io.kalix kalix-spring-sdk - ${kalix-sdk.version} + 1.0.8-14-fedc8579-dev-SNAPSHOT io.kalix kalix-spring-sdk-testkit - ${kalix-sdk.version} + 1.0.8-14-fedc8579-dev-SNAPSHOT test From 3d25f4067c9bf2080468852f5f1649ddd814e120 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 09:16:56 +0200 Subject: [PATCH 05/13] fix: java 17 for views sample --- .../pom.xml | 4 +-- .../customer/api/CustomerIntegrationTest.java | 10 +++---- .../src/main/java/customer/api/Address.java | 13 +-------- .../src/main/java/customer/api/Customer.java | 28 ++++--------------- .../java/customer/api/CustomerEntity.java | 10 +++---- .../java/customer/api/CustomerEntityTest.java | 6 ++-- 6 files changed, 21 insertions(+), 50 deletions(-) diff --git a/samples/spring-customer-registry-views-quickstart/pom.xml b/samples/spring-customer-registry-views-quickstart/pom.xml index fd94004a5b..5c2264ec82 100644 --- a/samples/spring-customer-registry-views-quickstart/pom.xml +++ b/samples/spring-customer-registry-views-quickstart/pom.xml @@ -16,7 +16,7 @@ yyyyMMddHHmmss customer.Main - 11 + 17 UTF-8 1.0.8 @@ -123,7 +123,7 @@ ${dockerImage}:%l - docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot + docker.io/library/eclipse-temurin:${jdk.target}-alpine linux/amd64 diff --git a/samples/spring-customer-registry-views-quickstart/src/it/java/customer/api/CustomerIntegrationTest.java b/samples/spring-customer-registry-views-quickstart/src/it/java/customer/api/CustomerIntegrationTest.java index 703aa2d8bb..0e0e65a8ad 100644 --- a/samples/spring-customer-registry-views-quickstart/src/it/java/customer/api/CustomerIntegrationTest.java +++ b/samples/spring-customer-registry-views-quickstart/src/it/java/customer/api/CustomerIntegrationTest.java @@ -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 @@ -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 @@ -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()); } @@ -131,7 +131,7 @@ public void findByName() throws Exception { .retrieve() .bodyToMono(Customer.class) .block(timeout) - .name, + .name(), new IsEqual("Foo") ); } @@ -160,7 +160,7 @@ public void findByEmail() throws Exception { .retrieve() .bodyToMono(Customer.class) .block(timeout) - .name, + .name(), new IsEqual("Bar") ); } diff --git a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Address.java b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Address.java index 2edb2e73d9..7a828e9a6f 100644 --- a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Address.java +++ b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Address.java @@ -3,16 +3,5 @@ * Copyright (C) 2009-2022 Lightbend Inc. */ -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) { } diff --git a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Customer.java b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Customer.java index 15142a10e2..ab9480f735 100644 --- a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Customer.java +++ b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/Customer.java @@ -3,29 +3,13 @@ * Copyright (C) 2009-2022 Lightbend Inc. */ -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); + } } diff --git a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/CustomerEntity.java b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/CustomerEntity.java index f8232190f8..9cf5305c6b 100644 --- a/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/CustomerEntity.java +++ b/samples/spring-customer-registry-views-quickstart/src/main/java/customer/api/CustomerEntity.java @@ -36,16 +36,14 @@ public ValueEntity.Effect getCustomer() { @PostMapping("/changeName/{newName}") public Effect 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 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"); } } diff --git a/samples/spring-customer-registry-views-quickstart/src/test/java/customer/api/CustomerEntityTest.java b/samples/spring-customer-registry-views-quickstart/src/test/java/customer/api/CustomerEntityTest.java index 163fde6ad9..efc941da97 100644 --- a/samples/spring-customer-registry-views-quickstart/src/test/java/customer/api/CustomerEntityTest.java +++ b/samples/spring-customer-registry-views-quickstart/src/test/java/customer/api/CustomerEntityTest.java @@ -25,7 +25,7 @@ public void testCustomerNameChange() { { ValueEntityResult result = testKit.call(e -> e.changeName("FooBar")); assertEquals("OK", result.getReply()); - assertEquals("FooBar", testKit.getState().name); + assertEquals("FooBar", testKit.getState().name()); } } @@ -43,8 +43,8 @@ public void testCustomerAddressChange() { Address newAddress = new Address("Sesame Street", "Sesame City"); ValueEntityResult 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()); } } From 41bde256e99a11243e055cd804225b3256fa9ad2 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 10:57:53 +0200 Subject: [PATCH 06/13] Update samples/spring-eventsourced-customer-registry/pom.xml Co-authored-by: Renato Cavalcanti --- samples/spring-eventsourced-customer-registry/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/spring-eventsourced-customer-registry/pom.xml b/samples/spring-eventsourced-customer-registry/pom.xml index 8e8a007104..d6c7e0e4ac 100644 --- a/samples/spring-eventsourced-customer-registry/pom.xml +++ b/samples/spring-eventsourced-customer-registry/pom.xml @@ -12,7 +12,7 @@ - aludwiko/${project.artifactId} + my-docker-repo/${project.artifactId} ${project.version}-${build.timestamp} yyyyMMddHHmmss customer.Main From c0884fb91d0440b330862231e70bb6745bfb4564 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 11:02:02 +0200 Subject: [PATCH 07/13] fixing maven poms --- samples/spring-eventsourced-customer-registry/pom.xml | 4 ++-- samples/spring-fibonacci-action/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/spring-eventsourced-customer-registry/pom.xml b/samples/spring-eventsourced-customer-registry/pom.xml index d6c7e0e4ac..fae1b3cec3 100644 --- a/samples/spring-eventsourced-customer-registry/pom.xml +++ b/samples/spring-eventsourced-customer-registry/pom.xml @@ -308,12 +308,12 @@ io.kalix kalix-spring-sdk - 1.0.8-14-fedc8579-dev-SNAPSHOT + ${kalix-sdk.version} io.kalix kalix-spring-sdk-testkit - 1.0.8-14-fedc8579-dev-SNAPSHOT + ${kalix-sdk.version} test diff --git a/samples/spring-fibonacci-action/pom.xml b/samples/spring-fibonacci-action/pom.xml index d42fda1658..8883a8a30a 100644 --- a/samples/spring-fibonacci-action/pom.xml +++ b/samples/spring-fibonacci-action/pom.xml @@ -307,12 +307,12 @@ io.kalix kalix-spring-sdk - 1.0.8-14-fedc8579-dev-SNAPSHOT + ${kalix-sdk.version} io.kalix kalix-spring-sdk-testkit - 1.0.8-14-fedc8579-dev-SNAPSHOT + ${kalix-sdk.version} test From 007a70fa3a5297817a84bcdc52a3beec2b8eb46d Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 11:04:17 +0200 Subject: [PATCH 08/13] fixing maven poms --- samples/spring-fibonacci-action/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/spring-fibonacci-action/pom.xml b/samples/spring-fibonacci-action/pom.xml index 8883a8a30a..6c7a8484a5 100644 --- a/samples/spring-fibonacci-action/pom.xml +++ b/samples/spring-fibonacci-action/pom.xml @@ -11,7 +11,7 @@ - aludwiko/${project.artifactId} + my-docker-repo/${project.artifactId} ${project.version}-${build.timestamp} yyyyMMddHHmmss com.example.Main From 6a67695123e9b34931d0f899a24c9d6b921bd763 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 11:06:32 +0200 Subject: [PATCH 09/13] reverting changes --- .../src/main/java/customer/api/CustomerEvent.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java index 7c75860fe4..aa8eacad23 100644 --- a/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java +++ b/samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java @@ -8,23 +8,20 @@ import static customer.api.CustomerEvent.*; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -//@JsonSubTypes( -// { -// @JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"), -// @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"), -// @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed") -// }) +@JsonSubTypes( + { + @JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"), + @JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"), + @JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed") + }) public sealed interface CustomerEvent { - @JsonTypeName("customer-created") record CustomerCreated(String email, String name, Address address) implements CustomerEvent { } - @JsonTypeName("name-changed") record NameChanged(String newName) implements CustomerEvent { } - @JsonTypeName("address-changed") record AddressChanged(Address address) implements CustomerEvent { } } From 5f1fe7b0e739f9dad4706ee45effa4fee9bedf46 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 11:16:29 +0200 Subject: [PATCH 10/13] cleanups and renames --- .../pom.xml | 2 +- .../pom.xml | 2 +- .../test/java/customer/api/JacksonTest.java | 20 ------------------- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java diff --git a/samples/spring-customer-registry-views-quickstart/pom.xml b/samples/spring-customer-registry-views-quickstart/pom.xml index 5c2264ec82..090eaf4596 100644 --- a/samples/spring-customer-registry-views-quickstart/pom.xml +++ b/samples/spring-customer-registry-views-quickstart/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.example - spring-customer-registry + spring-customer-registry-views 1.0-SNAPSHOT jar diff --git a/samples/spring-eventsourced-customer-registry/pom.xml b/samples/spring-eventsourced-customer-registry/pom.xml index fae1b3cec3..603bd6359d 100644 --- a/samples/spring-eventsourced-customer-registry/pom.xml +++ b/samples/spring-eventsourced-customer-registry/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.example - spring-customer-registry + spring-eventsourced-customer-registry 1.0-SNAPSHOT jar diff --git a/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java b/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java deleted file mode 100644 index 241fa3c3c2..0000000000 --- a/samples/spring-eventsourced-customer-registry/src/test/java/customer/api/JacksonTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package customer.api; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; - -public class JacksonTest { - - @Test - public void testCustomerAddressChange() throws JsonProcessingException { - CustomerEvent.CustomerCreated customerCreated = new CustomerEvent.CustomerCreated("email", "name", new Address("street", "some city")); - ObjectMapper mapper = new ObjectMapper(); - String valueAsString = mapper.writeValueAsString(customerCreated); - System.out.println(valueAsString); - - CustomerEvent customerEvent = mapper.readValue(valueAsString, CustomerEvent.class); - - System.out.println(customerEvent); - } -} From 6811401dcab8c99f941587a294a07aef9d75f039 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 14:26:50 +0200 Subject: [PATCH 11/13] testing build with java 17 --- .circleci/config.yml | 14 +++++++------- build.sbt | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 45ccc25179..9a5e62c2e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,19 +17,19 @@ commands: parent: main install-java-11: - description: install openjdk-11 + description: install openjdk-17 steps: - run: - name: Install java 11 + name: Install java 17 command: | - wget https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.8%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.8_10.tar.gz -O /tmp/openjdk-11.tar.gz + wget https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.4.1%2B1/OpenJDK17U-jdk_x64_linux_hotspot_17.0.4.1_1.tar.gz -O /tmp/openjdk-17.tar.gz sudo mkdir -p /usr/lib/jvm - sudo tar xfvz /tmp/openjdk-11.tar.gz --directory /usr/lib/jvm - rm -f /tmp/openjdk-11.tar.gz + sudo tar xfvz /tmp/openjdk-17.tar.gz --directory /usr/lib/jvm + rm -f /tmp/openjdk-17.tar.gz - sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.8+10/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done' - sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.8+10/bin/*; do update-alternatives --set $(basename $bin) $bin; done' + sudo sh -c 'for bin in /usr/lib/jvm/jdk-17.0.4.1+1/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done' + sudo sh -c 'for bin in /usr/lib/jvm/jdk-17.0.4.1+1/bin/*; do update-alternatives --set $(basename $bin) $bin; done' setup_sbt: description: "Set up sbt" diff --git a/build.sbt b/build.sbt index d2c5032ba2..925b602aa0 100644 --- a/build.sbt +++ b/build.sbt @@ -65,7 +65,6 @@ lazy val sdkJava = project "-Xdoclint:none", "-overview", ((Compile / javaSource).value / "overview.html").getAbsolutePath, - "--no-module-directories", "-notimestamp", "-doctitle", "Kalix Java SDK", From adb55ca1672667a8b40a663a789ef603f5366587 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 15:26:02 +0200 Subject: [PATCH 12/13] reverting java 17 from grpc archetypes --- .../src/main/resources/archetype-resources/pom.xml | 4 ++-- .../src/main/resources/archetype-resources/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml b/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml index 6218a056b8..b7ff0f9255 100644 --- a/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml +++ b/maven-java/kalix-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/pom.xml @@ -17,7 +17,7 @@ yyyyMMddHHmmss ${package}.Main - 17 + 11 UTF-8 @project.version@ @@ -122,7 +122,7 @@ ${D}{dockerImage}:%l - docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine + docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot linux/amd64 diff --git a/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml b/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml index 6218a056b8..b7ff0f9255 100644 --- a/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml +++ b/maven-java/kalix-maven-archetype-value-entity/src/main/resources/archetype-resources/pom.xml @@ -17,7 +17,7 @@ yyyyMMddHHmmss ${package}.Main - 17 + 11 UTF-8 @project.version@ @@ -122,7 +122,7 @@ ${D}{dockerImage}:%l - docker.io/library/eclipse-temurin:${D}{jdk.target}-alpine + docker.io/library/adoptopenjdk:${D}{jdk.target}-jre-hotspot linux/amd64 From 25a9bb4c92250e59c4c0f276165b04f170986e4c Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 7 Oct 2022 15:50:14 +0200 Subject: [PATCH 13/13] missing jackson annotations --- .../src/main/java/com/example/CounterEvent.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java b/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java index 2a851425dd..0b53318247 100644 --- a/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java +++ b/samples/spring-eventsourced-counter/src/main/java/com/example/CounterEvent.java @@ -1,5 +1,16 @@ package com.example; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import static com.example.CounterEvent.*; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonSubTypes( + { + @JsonSubTypes.Type(value = ValueIncreased.class, name = "value-increased"), + @JsonSubTypes.Type(value = ValueMultiplied.class, name = "value-multiplied"), + }) public sealed interface CounterEvent { record ValueIncreased(int value) implements CounterEvent {