Skip to content

Commit

Permalink
Fix all the package names to use the new release artifacts
Browse files Browse the repository at this point in the history
Update READMEs
Add tests
  • Loading branch information
slinkydeveloper committed Nov 24, 2023
1 parent 28db66a commit 2e7aa90
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 125 deletions.
22 changes: 17 additions & 5 deletions jvm/java-blocking-http/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Blocking HTTP example

Example with Java blocking interface and HTTP server.
Sample project configuration of a Restate service using the Java blocking interface and HTTP server. It contains:

## Setup credentials

Because the SDK is not public yet, you need to set up the PAT credentials, see https://github.com/restatedev/e2e#setup-local-env
* [`build.gradle.kts`](build.gradle.kts)
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
* [Service class implementation `Greeter`](src/main/java/dev/restate/sdk/examples/Greeter.java)
* [Test `GreeterTest`](src/test/java/dev/restate/sdk/examples/GreeterTest.java)
* [Logging configuration](src/main/resources/log4j2.properties)

## Running the example

Expand All @@ -14,4 +16,14 @@ You can run the Java greeter service via:
./gradlew run
```

Or from the Intellij IDEA UI.
Or from the IDE UI.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from the IDE UI.
44 changes: 23 additions & 21 deletions jvm/java-blocking-http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ plugins {
id("com.google.protobuf") version "0.9.1"
}

dependencies {
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/restatedev/sdk-java")
credentials {
username = System.getenv("GH_PACKAGE_READ_ACCESS_USER")
password = System.getenv("GH_PACKAGE_READ_ACCESS_TOKEN")
}
}
}
repositories {
mavenCentral()
// OSSRH Snapshots repo
// TODO remove it once we have the proper release
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") }
}

val restateVersion = "0.0.1-SNAPSHOT"

dependencies {
// Restate SDK
implementation("dev.restate.sdk:sdk-java-blocking:1.0-SNAPSHOT")
implementation("dev.restate.sdk:sdk-http-vertx:1.0-SNAPSHOT")
implementation("dev.restate:sdk-java-blocking:$restateVersion")
implementation("dev.restate:sdk-http-vertx:$restateVersion")
// To use Jackson to read/write state entries (optional)
implementation("dev.restate.sdk:sdk-serde-jackson:1.0-SNAPSHOT")
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Protobuf and grpc dependencies
implementation("com.google.protobuf:protobuf-java:3.24.3")
Expand All @@ -35,6 +33,10 @@ dependencies {

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")

// Testing (optional)
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("dev.restate:sdk-test:$restateVersion")
}

// Configure protoc plugin
Expand All @@ -44,7 +46,7 @@ protobuf {
// We need both grpc and restate codegen(s) because the restate codegen depends on the grpc one
plugins {
id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:1.58.0" }
id("restate") { artifact = "dev.restate.sdk:protoc-gen-restate-java-blocking:1.0-SNAPSHOT:all@jar" }
id("restate") { artifact = "dev.restate:protoc-gen-restate-java-blocking:$restateVersion:all@jar" }
}

generateProtoTasks {
Expand All @@ -57,12 +59,12 @@ protobuf {
}
}

application {
mainClass.set("dev.restate.sdk.examples.Greeter")
// Configure test platform
tasks.withType<Test> {
useJUnitPlatform()
}

// Temporary solution for disabling caching of Java SDK until we release it
configurations.all {
// This disables caching for -SNAPSHOT dependencies
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
// Set main class
application {
mainClass.set("dev.restate.sdk.examples.Greeter")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.restate.sdk.examples;

import dev.restate.sdk.examples.generated.GreeterGrpc;
import dev.restate.sdk.examples.generated.GreeterGrpc.GreeterBlockingStub;
import dev.restate.sdk.examples.generated.GreeterProto.GreetRequest;
import dev.restate.sdk.examples.generated.GreeterProto.GreetResponse;
import dev.restate.sdk.testing.RestateGrpcChannel;
import dev.restate.sdk.testing.RestateRunner;
import dev.restate.sdk.testing.RestateRunnerBuilder;
import io.grpc.ManagedChannel;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

class GreeterTest {

// Runner runs Restate using testcontainers and registers services
@RegisterExtension
private static final RestateRunner restateRunner = RestateRunnerBuilder.create()
// Service to test
.withService(new Greeter())
.buildRunner();

@Test
void testGreet(
// Channel to send requests to Restate services
@RestateGrpcChannel ManagedChannel channel) {
GreeterBlockingStub client = GreeterGrpc.newBlockingStub(channel);
GreetResponse response = client.greet(GreetRequest.newBuilder().setName("Francesco").build());

assertEquals("Hello Francesco for the 1 time!", response.getMessage());
}
}
25 changes: 19 additions & 6 deletions jvm/java-blocking-lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Blocking HTTP example
# Blocking Lambda example

Example with Java blocking interface and Lambda.
Sample project configuration of a Restate service using the Java blocking interface and AWS Lambda. It contains:

## Setup credentials

Because the SDK is not public yet, you need to set up the PAT credentials, see https://github.com/restatedev/e2e#setup-local-env
* [`build.gradle.kts`](build.gradle.kts)
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
* [Service class implementation `Greeter`](src/main/java/dev/restate/sdk/examples/Greeter.java)
* [Lambda handler `LambdaHandler`](src/main/java/dev/restate/sdk/examples/LambdaHandler.java)
* [Test `GreeterTest`](src/test/java/dev/restate/sdk/examples/GreeterTest.java)
* [Logging configuration](src/main/resources/log4j2.properties)

## Package

Expand All @@ -16,4 +19,14 @@ Run:

You'll find the shadowed jar in the `build` directory.

The class to configure in Lambda is `dev.restate.sdk.lambda.LambdaHandler`.
The class to configure in Lambda is `dev.restate.sdk.examples.LambdaHandler`.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from the IDE UI.
39 changes: 20 additions & 19 deletions jvm/java-blocking-lambda/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
}

dependencies {
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/restatedev/sdk-java")
credentials {
username = System.getenv("GH_PACKAGE_READ_ACCESS_USER")
password = System.getenv("GH_PACKAGE_READ_ACCESS_TOKEN")
}
}
}
repositories {
mavenCentral()
// OSSRH Snapshots repo
// TODO remove it once we have the proper release
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") }
}

val restateVersion = "0.0.1-SNAPSHOT"

dependencies {
// Restate SDK
implementation("dev.restate.sdk:sdk-java-blocking:1.0-SNAPSHOT")
implementation("dev.restate.sdk:sdk-lambda:1.0-SNAPSHOT")
implementation("dev.restate:sdk-java-blocking:$restateVersion")
implementation("dev.restate:sdk-lambda:$restateVersion")
// To use Jackson to read/write state entries (optional)
implementation("dev.restate.sdk:sdk-serde-jackson:1.0-SNAPSHOT")
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Protobuf and grpc dependencies
implementation("com.google.protobuf:protobuf-java:3.24.3")
Expand All @@ -37,6 +35,10 @@ dependencies {

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")

// Testing (optional)
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("dev.restate:sdk-test:$restateVersion")
}

// Configure protoc plugin
Expand All @@ -46,7 +48,7 @@ protobuf {
// We need both grpc and restate codegen(s) because the restate codegen depends on the grpc one
plugins {
id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:1.58.0" }
id("restate") { artifact = "dev.restate.sdk:protoc-gen-restate-java-blocking:1.0-SNAPSHOT:all@jar" }
id("restate") { artifact = "dev.restate:protoc-gen-restate-java-blocking:$restateVersion:all@jar" }
}

generateProtoTasks {
Expand All @@ -59,8 +61,7 @@ protobuf {
}
}

// Temporary solution for disabling caching of Java SDK until we release it
configurations.all {
// This disables caching for -SNAPSHOT dependencies
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
// Configure test platform
tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.restate.sdk.core.CoreSerdes;
import dev.restate.sdk.core.StateKey;
import dev.restate.sdk.examples.generated.*;
import dev.restate.sdk.http.vertx.RestateHttpEndpointBuilder;

import static dev.restate.sdk.examples.generated.GreeterProto.*;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.restate.sdk.examples;

import dev.restate.sdk.lambda.BaseRestateLambdaHandler;
import dev.restate.sdk.lambda.RestateLambdaEndpointBuilder;

public class LambdaHandler extends BaseRestateLambdaHandler {
@Override
public void register(RestateLambdaEndpointBuilder builder) {
builder.withService(new Greeter());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.restate.sdk.examples;

import dev.restate.sdk.examples.generated.GreeterGrpc;
import dev.restate.sdk.examples.generated.GreeterGrpc.GreeterBlockingStub;
import dev.restate.sdk.examples.generated.GreeterProto.GreetRequest;
import dev.restate.sdk.examples.generated.GreeterProto.GreetResponse;
import dev.restate.sdk.testing.RestateGrpcChannel;
import dev.restate.sdk.testing.RestateRunner;
import dev.restate.sdk.testing.RestateRunnerBuilder;
import io.grpc.ManagedChannel;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

class GreeterTest {

// Runner runs Restate using testcontainers and registers services
@RegisterExtension
private static final RestateRunner restateRunner = RestateRunnerBuilder.create()
// Service to test
.withService(new Greeter())
.buildRunner();

@Test
void testGreet(
// Channel to send requests to Restate services
@RestateGrpcChannel ManagedChannel channel) {
GreeterBlockingStub client = GreeterGrpc.newBlockingStub(channel);
GreetResponse response = client.greet(GreetRequest.newBuilder().setName("Francesco").build());

assertEquals("Hello Francesco for the 1 time!", response.getMessage());
}
}
22 changes: 17 additions & 5 deletions jvm/kotlin-http/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Kotlin HTTP example

Example with Kotlin coroutines interface and HTTP server.
Sample project configuration of a Restate service using the Kotlin coroutines interface and HTTP server. It contains:

## Setup credentials

Because the SDK is not public yet, you need to set up the PAT credentials, see https://github.com/restatedev/e2e#setup-local-env
* [`build.gradle.kts`](build.gradle.kts)
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
* [Service class implementation `Greeter`](src/main/kotlin/dev/restate/sdk/examples/Greeter.kt)
* [Test `GreeterTest`](src/test/kotlin/dev/restate/sdk/examples/GreeterTest.kt)
* [Logging configuration](src/main/resources/log4j2.properties)

## Running the example

Expand All @@ -14,4 +16,14 @@ You can run the Kotlin greeter service via:
./gradlew run
```

Or from the Intellij IDEA UI.
Or from the IDE UI.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from the IDE UI.
Loading

0 comments on commit 2e7aa90

Please sign in to comment.