Skip to content

Commit

Permalink
Improve testing tools Javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Nov 6, 2024
1 parent 5880f27 commit 820d821
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
uses: gradle/actions/wrapper-validation@v3

- name: Build with Gradle
run: ./gradlew build
# Javadoc 11 won't work with our Javadocs, they need 21
run: ./gradlew build -x javadoc

- name: Upload test results
if: always()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.DockerImageName;

/** Manual runner for Restate. We recommend using {@link RestateRunner} with JUnit 5. */
/**
* Manual runner for the Restate test infra, starting the Restate server container together with the
* provided services and automatically registering them. To start the infra use {@link #run()} and
* to stop it use {@link #stop()}.
*
* <p>Use {@link RestateRunnerBuilder#buildManualRunner()} to build an instance of this class.
*
* <p>If you use JUnit 5, we suggest using {@link RestateRunner} instead.
*/
public class ManualRestateRunner
implements AutoCloseable, ExtensionContext.Store.CloseableResource {

Expand Down Expand Up @@ -75,6 +83,12 @@ public class ManualRestateRunner
}

/** Run restate, run the embedded service endpoint server, and register the services. */
public void start() {}

/**
* @deprecated Use {@link #start()} instead.
*/
@Deprecated(forRemoval = true)
public void run() {
// Start listening the local server
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@
* Restate runner for JUnit 5. Example:
*
* <pre>{@code
* {@literal @}RegisterExtension
* @RegisterExtension
* private final static RestateRunner restateRunner = RestateRunnerBuilder.create()
* .withService(new MyService())
* .buildRunner();
* }</pre>
*
* <p>The runner will deploy the services locally, execute Restate as container using
* testcontainers, and register the services.
* <p>The runner will deploy the services locally, execute Restate as container using <a
* href="https://java.testcontainers.org/">Testcontainers</a>, and register the services.
*
* <p>This extension is scoped per test class, meaning that the restate runner will be shared among
* test methods.
*
* <p>Use the annotations {@link RestateClient}, {@link RestateURL} and {@link RestateAdminClient}
* to interact with the deployed runtime:
* to interact with the deployed server:
*
* <pre>{@code
* {@literal @}Test
* void testGreet({@literal @}RestateGrpcChannel ManagedChannel channel) {
* CounterGrpc.CounterBlockingStub client = CounterGrpc.newBlockingStub(channel);
* // Use client
* @Test
* void initialCountIsZero(@RestateClient Client client) {
* var client = CounterClient.fromClient(ingressClient, "my-counter");
*
* // Use client as usual
* long response = client.get();
* assertThat(response).isEqualTo(0L);
* }
* }</pre>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import java.util.HashMap;
import java.util.Map;

/** Builder for {@link RestateRunner}. See {@link RestateRunner} for more details. */
/**
* Builder for {@link RestateRunner}.
*
* @see RestateRunner
*/
public class RestateRunnerBuilder {

private static final String DEFAULT_RESTATE_CONTAINER = "docker.io/restatedev/restate";
Expand Down Expand Up @@ -73,6 +77,9 @@ public <O> RestateRunnerBuilder bind(ServiceDefinition<O> serviceDefinition, O o
return this;
}

/**
* @return a {@link ManualRestateRunner} to start and stop the test infra manually.
*/
public ManualRestateRunner buildManualRunner() {
return new ManualRestateRunner(
this.endpointBuilder.build(),
Expand All @@ -81,6 +88,9 @@ public ManualRestateRunner buildManualRunner() {
this.configFile);
}

/**
* @return a {@link RestateRunner} to be used as JUnit 5 Extension.
*/
public RestateRunner buildRunner() {
return new RestateRunner(this.buildManualRunner());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import java.net.URL;

/**
* Inject Restate's URL (either {@link String} or {@link URL}) to interact with the deployed
* runtime.
* Inject Restate's URL (either {@link String} or {@link URL}) to interact with the deployed server.
*/
@Target(value = ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CounterTest {
@Timeout(value = 10)
void testGreet(@RestateClient Client ingressClient) {
var client = CounterClient.fromClient(ingressClient, "my-counter");
long response = client.get();

long response = client.get();
assertThat(response).isEqualTo(0L);
}
}

0 comments on commit 820d821

Please sign in to comment.