Skip to content

Commit

Permalink
Upgrade junit lib to 5; Update tests; Reactoring heritage.
Browse files Browse the repository at this point in the history
  • Loading branch information
h3nrique committed Jul 30, 2024
1 parent d4b0d8f commit cdf3407
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 47 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<caffeine.version>3.1.8</caffeine.version>
<junit.version>4.13.2</junit.version>
<junit.version>5.10.3</junit.version>
<mysql-connector.version>8.4.0</mysql-connector.version>
<okhttp.version>4.12.0</okhttp.version>
<protobuf.version>4.27.2</protobuf.version>
Expand Down Expand Up @@ -65,8 +65,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -165,6 +165,7 @@
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/protobuf</source>
<source>${project.build.directory}/generated-test-sources/protobuf</source>
</sources>
</configuration>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/eigr/spawn/api/actors/StatefulActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import java.lang.reflect.ParameterizedType;

public interface StatefulActor<S> extends BaseActor {
default Class<S> getStateType() {
return (Class<S>) ((ParameterizedType)
getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
default Class<S> getStateType(Class<S> entityClass) {
return entityClass;
}
@Override
default Boolean isStateful() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/eigr/spawn/internal/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static Entity fromStatefulActorToEntity(BehaviorCtx ctx, Class<?> actor)
try {
Constructor<?> constructor = actor.getConstructor();
StatefulActor stActor = (StatefulActor) constructor.newInstance();
Class<?> stateType = stActor.getStateType();
Class<?> stateType = stActor.getStateType(stActor.getClass().getGenericSuperclass().getClass());
ActorBehavior behavior = stActor.configure(ctx);

if (behavior.getClass().isAssignableFrom(NamedActorBehavior.class)) {
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/io/eigr/spawn/AbstractContainerBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import io.eigr.spawn.test.actors.JoeActor;
import io.eigr.spawn.test.actors.StatelessNamedActor;
import io.eigr.spawn.test.actors.UnNamedActor;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.Testcontainers;
Expand All @@ -20,14 +25,15 @@
abstract class AbstractContainerBaseTest {

private static final Logger log = LoggerFactory.getLogger(AbstractContainerBaseTest.class);
private static final GenericContainer<?> SPAWN_CONTAINER;
private static GenericContainer<?> SPAWN_CONTAINER;
private static final String spawnProxyImage = "eigr/spawn-proxy:1.4.1-rc.1";
private static final String userFunctionPort = "8091";
private static final String spawnProxyPort = "9004";
protected static final Spawn spawnSystem;
protected static Spawn spawnSystem;
protected static final String spawnSystemName = "spawn-system-test";

static {
@BeforeAll
public static void setup() {
Testcontainers.exposeHostPorts(8091);

SPAWN_CONTAINER = new GenericContainer<>(DockerImageName.parse(spawnProxyImage))
Expand Down Expand Up @@ -73,5 +79,11 @@ abstract class AbstractContainerBaseTest {
throw new RuntimeException(e);
}
}

@AfterAll
public static void teardown() {
SPAWN_CONTAINER.stop();

}
}

35 changes: 18 additions & 17 deletions src/test/java/io/eigr/spawn/SpawnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
import io.eigr.spawn.test.actors.JoeActor;
import io.eigr.spawn.test.actors.StatelessNamedActor;
import io.eigr.spawn.test.actors.UnNamedActor;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class SpawnTest extends AbstractContainerBaseTest {
class SpawnTest extends AbstractContainerBaseTest {

@Test
public void testNamedInvocation() throws ActorCreationException, ActorInvocationException {
void testNamedInvocation() throws ActorCreationException, ActorInvocationException {
ActorRef joeActor = spawnSystem.createActorRef(
ActorIdentity.of(spawnSystemName, "JoeActor"));

Class type = joeActor.getType();

assertEquals(type, JoeActor.class);
assertNotNull(joeActor);
Assertions.assertEquals(type, JoeActor.class);
Assertions.assertNotNull(joeActor);

Actor.Request msg = Actor.Request.newBuilder()
.setLanguage("Erlang")
Expand All @@ -36,20 +37,20 @@ public void testNamedInvocation() throws ActorCreationException, ActorInvocation

if (maybeReply.isPresent()) {
Actor.Reply reply = maybeReply.get();
assertNotNull(reply);
assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
Assertions.assertNotNull(reply);
Assertions.assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
}
}

@Test
public void testUnNamedInvocation() throws ActorCreationException, ActorInvocationException {
void testUnNamedInvocation() throws ActorCreationException, ActorInvocationException {
ActorRef unNamedJoeActor = spawnSystem.createActorRef(
ActorIdentity.of(spawnSystemName, "UnNamedJoeActor", "UnNamedActor"));

Class type = unNamedJoeActor.getType();

assertEquals(type, UnNamedActor.class);
assertNotNull(unNamedJoeActor);
Assertions.assertEquals(type, UnNamedActor.class);
Assertions.assertNotNull(unNamedJoeActor);

Actor.Request msg = Actor.Request.newBuilder()
.setLanguage("Erlang")
Expand All @@ -60,20 +61,20 @@ public void testUnNamedInvocation() throws ActorCreationException, ActorInvocati

if (maybeReply.isPresent()) {
Actor.Reply reply = maybeReply.get();
assertNotNull(reply);
assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
Assertions.assertNotNull(reply);
Assertions.assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
}
}

@Test
public void testStatelessInvocation() throws ActorCreationException, ActorInvocationException {
void testStatelessInvocation() throws ActorCreationException, ActorInvocationException {
ActorRef statelessNamedActor = spawnSystem.createActorRef(
ActorIdentity.of(spawnSystemName, "StatelessNamedActor"));

Class type = statelessNamedActor.getType();

assertEquals(type, StatelessNamedActor.class);
assertNotNull(statelessNamedActor);
Assertions.assertEquals(type, StatelessNamedActor.class);
Assertions.assertNotNull(statelessNamedActor);

Actor.Request msg = Actor.Request.newBuilder()
.setLanguage("Elixir")
Expand All @@ -84,8 +85,8 @@ public void testStatelessInvocation() throws ActorCreationException, ActorInvoca

if (maybeReply.isPresent()) {
Actor.Reply reply = maybeReply.get();
assertNotNull(reply);
assertEquals("Hi Elixir. Hello From Java", reply.getResponse());
Assertions.assertNotNull(reply);
Assertions.assertEquals("Hi Elixir. Hello From Java", reply.getResponse());
}
}
}
37 changes: 18 additions & 19 deletions src/test/java/io/eigr/spawn/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,51 @@
import io.eigr.spawn.api.actors.workflows.SideEffect;
import io.eigr.spawn.api.exceptions.SpawnException;
import io.eigr.spawn.java.test.domain.Actor;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;

public class WorkflowTest extends AbstractContainerBaseTest {
class WorkflowTest extends AbstractContainerBaseTest {

private ActorRef joeActorRef;

@Before
@BeforeEach
public void before() throws SpawnException {
joeActorRef = spawnSystem.createActorRef(
ActorIdentity.of(spawnSystemName, "JoeActor"));
}

@Test
public void testBroadcastBuilder() {
void testBroadcastBuilder() {
Broadcast broadcast = Broadcast.to("test.channel", "hi", Actor.Request.getDefaultInstance());
final Protocol.Broadcast protocolBroadcast = broadcast.build();
assertEquals("test.channel", protocolBroadcast.getChannelGroup());
assertNotNull(protocolBroadcast.getValue());
Assertions.assertEquals("test.channel", protocolBroadcast.getChannelGroup());
Assertions.assertNotNull(protocolBroadcast.getValue());
}

@Test
public void testForwardBuilder() throws Exception {
void testForwardBuilder() throws Exception {
Forward forward = Forward.to(joeActorRef, "hi");
final Protocol.Forward protocolForward = forward.build();
assertEquals("hi", protocolForward.getActionName());
assertEquals("JoeActor", protocolForward.getActor());
Assertions.assertEquals("hi", protocolForward.getActionName());
Assertions.assertEquals("JoeActor", protocolForward.getActor());
}

@Test
public void testPipeBuilder() throws Exception {
void testPipeBuilder() throws Exception {
Pipe pipe = Pipe.to(joeActorRef, "hi");
final Protocol.Pipe protocolPipe = pipe.build();
assertEquals("hi", protocolPipe.getActionName());
assertEquals("JoeActor", protocolPipe.getActor());
Assertions.assertEquals("hi", protocolPipe.getActionName());
Assertions.assertEquals("JoeActor", protocolPipe.getActor());
}

@Test
public void testSideEffectBuilder() throws Exception {
void testSideEffectBuilder() throws Exception {
SideEffect effect = SideEffect.to(joeActorRef, "hi", Actor.Request.getDefaultInstance());
final Protocol.SideEffect protocolSideEffect = effect.build();
Protocol.InvocationRequest request = protocolSideEffect.getRequest();
assertNotNull(request);
assertEquals("hi", request.getActionName());
assertEquals("JoeActor", request.getActor().getId().getName());
Assertions.assertNotNull(request);
Assertions.assertEquals("hi", request.getActionName());
Assertions.assertEquals("JoeActor", request.getActor().getId().getName());
}
}

0 comments on commit cdf3407

Please sign in to comment.