-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christian Kaps <ck-github@mohiva.com>
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprActorsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.dapr.it.testcontainers; | ||
|
||
import io.dapr.actors.ActorId; | ||
import io.dapr.actors.client.ActorClient; | ||
import io.dapr.actors.client.ActorProxyBuilder; | ||
import io.dapr.testcontainers.Component; | ||
import io.dapr.testcontainers.DaprContainer; | ||
import io.dapr.testcontainers.DaprLogLevel; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest( | ||
webEnvironment = WebEnvironment.RANDOM_PORT, | ||
classes = { | ||
TestDaprActorsConfiguration.class, | ||
TestActorsApplication.class | ||
} | ||
) | ||
@Testcontainers | ||
@Tag("testcontainers") | ||
public class DaprActorsIT { | ||
private static final Network DAPR_NETWORK = Network.newNetwork(); | ||
|
||
@Container | ||
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2") | ||
.withAppName("actor-dapr-app") | ||
.withNetwork(DAPR_NETWORK) | ||
.withComponent(new Component("kvstore", "state.in-memory", "v1", | ||
Map.of("actorStateStore", "true"))) | ||
.withDaprLogLevel(DaprLogLevel.DEBUG) | ||
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String())) | ||
.withAppChannelAddress("host.testcontainers.internal"); | ||
|
||
/** | ||
* Expose the Dapr ports to the host. | ||
* | ||
* @param registry the dynamic property registry | ||
*/ | ||
@DynamicPropertySource | ||
static void daprProperties(DynamicPropertyRegistry registry) { | ||
registry.add("dapr.http.endpoint", DAPR_CONTAINER::getHttpEndpoint); | ||
registry.add("dapr.grpc.endpoint", DAPR_CONTAINER::getGrpcEndpoint); | ||
} | ||
|
||
@Autowired | ||
private ActorClient actorClient; | ||
|
||
@Test | ||
public void testWorkflows() throws Exception { | ||
ActorProxyBuilder<TestActor> builder = new ActorProxyBuilder(TestActor.class, actorClient); | ||
ActorId actorId = ActorId.createRandom(); | ||
TestActor actor = builder.build(actorId); | ||
|
||
String message = UUID.randomUUID().toString(); | ||
|
||
String echoedMessage = actor.echo(message); | ||
|
||
assertEquals(echoedMessage, message); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
sdk-tests/src/test/java/io/dapr/it/testcontainers/TestActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.dapr.it.testcontainers; | ||
import io.dapr.actors.ActorMethod; | ||
import io.dapr.actors.ActorType; | ||
|
||
@ActorType(name = "TestActor") | ||
public interface TestActor { | ||
@ActorMethod(name = "echo_message") | ||
String echo(String message); | ||
} |
16 changes: 16 additions & 0 deletions
16
sdk-tests/src/test/java/io/dapr/it/testcontainers/TestActorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.dapr.it.testcontainers; | ||
|
||
import io.dapr.actors.ActorId; | ||
import io.dapr.actors.runtime.AbstractActor; | ||
import io.dapr.actors.runtime.ActorRuntimeContext; | ||
|
||
public class TestActorImpl extends AbstractActor implements TestActor { | ||
public TestActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { | ||
super(runtimeContext, id); | ||
} | ||
|
||
@Override | ||
public String echo(String message) { | ||
return message; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
sdk-tests/src/test/java/io/dapr/it/testcontainers/TestActorsApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2024 The Dapr Authors | ||
* 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 io.dapr.it.testcontainers; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class TestActorsApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TestActorsApplication.class, args); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
sdk-tests/src/test/java/io/dapr/it/testcontainers/TestDaprActorsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.dapr.it.testcontainers; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import io.dapr.actors.client.ActorClient; | ||
import io.dapr.config.Properties; | ||
|
||
@Configuration | ||
public class TestDaprActorsConfiguration { | ||
@Bean | ||
public ActorClient daprActorClient( | ||
@Value("${dapr.http.endpoint}") String daprHttpEndpoint, | ||
@Value("${dapr.grpc.endpoint}") String daprGrpcEndpoint | ||
){ | ||
Map<String, String> overrides = Map.of( | ||
"dapr.http.endpoint", daprHttpEndpoint, | ||
"dapr.grpc.endpoint", daprGrpcEndpoint | ||
); | ||
|
||
return new ActorClient(new Properties(overrides)); | ||
} | ||
} |