Skip to content

Commit

Permalink
fix: java 17 for spring samples and maven archetypes (#1156)
Browse files Browse the repository at this point in the history
* fix: testing java 17 for samples

* fix: java 17 for maven archetypes

* fix: java 17 for kalix action example

* fix: java 17 for event sourced counter sample

* fix: java 17 for views sample

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

Co-authored-by: Renato Cavalcanti <[email protected]>

* fixing maven poms

* fixing maven poms

* reverting changes

* cleanups and renames

* testing build with java 17

* reverting java 17 from grpc archetypes

* missing jackson annotations

Co-authored-by: Renato Cavalcanti <[email protected]>
  • Loading branch information
aludwiko and octonato authored Oct 7, 2022
1 parent 78fded9 commit 0c5d561
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 284 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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-customer-registry-views-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>spring-customer-registry</artifactId>
<artifactId>spring-customer-registry-views</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

Expand All @@ -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,21 @@
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 {
}

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
Loading

0 comments on commit 0c5d561

Please sign in to comment.