File tree Expand file tree Collapse file tree 5 files changed +40
-8
lines changed
sdk-spring-boot-starter/src/test/java/dev/restate/sdk/springboot
main/java/dev/restate/sdk/testing
test/java/dev/restate/sdk/testing Expand file tree Collapse file tree 5 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 2020@ SpringBootTest (
2121 classes = Greeter .class ,
2222 properties = {"greetingPrefix=Something something " })
23- @ RestateTest (restateContainerImage = "ghcr.io/restatedev/restate:main" )
23+ @ RestateTest (containerImage = "ghcr.io/restatedev/restate:main" )
2424public class SdkTestingIntegrationTest {
2525
2626 @ Autowired @ BindService private Greeter greeter ;
Original file line number Diff line number Diff line change @@ -63,18 +63,29 @@ public class ManualRestateRunner
6363 this .runtimeContainer
6464 // We expose these ports only to enable port checks
6565 .withExposedPorts (RESTATE_INGRESS_ENDPOINT_PORT , RESTATE_ADMIN_ENDPOINT_PORT )
66+ // Let's have a high logging level by default to avoid spamming too much, it can be
67+ // overriden by the user
68+ .withEnv ("RUST_LOG" , "warn" )
6669 .withEnv (additionalEnv )
6770 // These envs should not be overriden by additionalEnv
6871 .withEnv ("RESTATE_META__REST_ADDRESS" , "0.0.0.0:" + RESTATE_ADMIN_ENDPOINT_PORT )
6972 .withEnv (
7073 "RESTATE_WORKER__INGRESS__BIND_ADDRESS" , "0.0.0.0:" + RESTATE_INGRESS_ENDPOINT_PORT )
7174 .withNetworkAliases (RESTATE_RUNTIME )
7275 // Configure wait strategy on health paths
73- .setWaitStrategy (
76+ .waitingFor (
7477 new WaitAllStrategy ()
7578 .withStrategy (Wait .forHttp ("/health" ).forPort (RESTATE_ADMIN_ENDPOINT_PORT ))
7679 .withStrategy (
77- Wait .forHttp ("/restate/health" ).forPort (RESTATE_INGRESS_ENDPOINT_PORT )));
80+ Wait .forHttp ("/restate/health" ).forPort (RESTATE_INGRESS_ENDPOINT_PORT )))
81+ .withLogConsumer (
82+ outputFrame -> {
83+ switch (outputFrame .getType ()) {
84+ case STDOUT , STDERR ->
85+ LOG .debug ("[restate] {}" , outputFrame .getUtf8StringWithoutLineEnding ());
86+ case END -> LOG .debug ("[restate] END" );
87+ }
88+ });
7889
7990 if (configFile != null ) {
8091 this .runtimeContainer .withCopyToContainer (Transferable .of (configFile ), "/config.yaml" );
Original file line number Diff line number Diff line change 99package dev .restate .sdk .testing ;
1010
1111import java .util .List ;
12+ import java .util .regex .Pattern ;
1213import org .junit .jupiter .api .extension .*;
1314import org .junit .platform .commons .support .AnnotationSupport ;
1415
@@ -74,7 +75,19 @@ private RestateRunner initializeRestateRunner(ExtensionContext extensionContext)
7475 // Build runner discovering services to bind
7576 var runnerBuilder = RestateRunnerBuilder .create ();
7677 servicesToBind .forEach (runnerBuilder ::bind );
77- runnerBuilder .withRestateContainerImage (testAnnotation .restateContainerImage ());
78+ runnerBuilder .withRestateContainerImage (testAnnotation .containerImage ());
79+ if (testAnnotation .environment () != null ) {
80+ for (String env : testAnnotation .environment ()) {
81+ String [] splitEnv = env .split (Pattern .quote ("=" ), 2 );
82+ if (splitEnv .length != 2 ) {
83+ throw new IllegalStateException (
84+ "Environment variables should be passed in the form of NAME=VALUE. Found an invalid env: '"
85+ + env
86+ + "'" );
87+ }
88+ runnerBuilder .withAdditionalEnv (splitEnv [0 ], splitEnv [1 ]);
89+ }
90+ }
7891 return runnerBuilder .buildRunner ();
7992 }
8093}
Original file line number Diff line number Diff line change 4242 * href="https://java.testcontainers.org/">Testcontainers</a>, and register the services.
4343 *
4444 * <p>This extension is scoped per test class, meaning that the restate runner will be shared among
45- * test methods. Because of the aforementioned issue , the extension sets the {@link TestInstance}
46- * {@link TestInstance.Lifecycle#PER_CLASS} automatically.
45+ * test methods. Because of this behaviour , the extension sets the {@link TestInstance} as {@link
46+ * TestInstance.Lifecycle#PER_CLASS} automatically.
4747 *
4848 * <p>Use the annotations {@link RestateClient}, {@link RestateURL} and {@link RestateAdminClient}
4949 * to interact with the deployed environment:
6666@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
6767public @interface RestateTest {
6868
69+ /**
70+ * Environment variables in form {@literal key=value} that should be added to the deployed Restate
71+ * container.
72+ *
73+ * @return the environment variables to add
74+ */
75+ String [] environment () default {};
76+
6977 /** Restate container image to use */
70- String restateContainerImage () default "docker.io/restatedev/restate:latest" ;
78+ String containerImage () default "docker.io/restatedev/restate:latest" ;
7179}
Original file line number Diff line number Diff line change 1414import org .junit .jupiter .api .Test ;
1515import org .junit .jupiter .api .Timeout ;
1616
17- @ RestateTest (restateContainerImage = "ghcr.io/restatedev/restate:main" )
17+ @ RestateTest (containerImage = "ghcr.io/restatedev/restate:main" )
1818class CounterTest {
1919
2020 @ BindService private final Counter counter = new Counter ();
You can’t perform that action at this time.
0 commit comments