Skip to content

Commit d82f495

Browse files
authored
Merge branch 'h3nrique:master' into master
2 parents 1b36a37 + 3ea128e commit d82f495

File tree

10 files changed

+44
-25
lines changed

10 files changed

+44
-25
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
Java demo project using [Spawn](https://github.com/eigr/spawn) to find postal codes at [ViaCEP](https://viacep.com.br).
44

5-
## Start environment
5+
## Test
6+
Before running the Maven command, ensure that a container environment (Docker/Podman) is running.
7+
8+
```bash
9+
mvn test
10+
```
11+
12+
## Start local environment
613

714
```bash
815
docker compose up
916
```
1017

11-
## Test
18+
## Test local environment
1219

1320
```bash
1421
# Request PostalCode
15-
curl -v -H 'Content-Type: application/json' -d '{ "postalCode": "03694090" }' 'http://localhost:8080/postalcode'
22+
curl -v -H 'Content-Type: application/json' -d '{ "postalCode": "03568000" }' 'http://localhost:8080/postalcode'
1623

1724
# Get PostalCode info
18-
curl -v 'http://localhost:8080/postalcode/03694090'
25+
curl -v 'http://localhost:8080/postalcode/03568000'
1926
```
2027

2128
## To deploy on Openshift with Openshift Pipeline (Tekton)

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
# context: https://github.com/eigr/spawn.git#main
2929
# dockerfile: ./Dockerfile-proxy
3030
# image: spawn/proxy:main-localbuild
31-
image: eigr/spawn-proxy:1.4.1-rc.1
31+
image: eigr/spawn-proxy:1.4.2-rc.2
3232
environment:
3333
SPAWN_USE_INTERNAL_NATS: "false"
3434
SPAWN_PUBSUB_ADAPTER: nats

pom.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
<groupId>com.github.h3nrique</groupId>
55
<artifactId>postalcode-spawn-demo</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>1.1-SNAPSHOT</version>
88
<name>postalcode-spawn-demo</name>
99

1010
<properties>
1111
<maven.compiler.source>17</maven.compiler.source>
1212
<maven.compiler.target>17</maven.compiler.target>
13+
<maven.compiler.release>17</maven.compiler.release>
1314
<project.encoding>UTF-8</project.encoding>
1415
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1516

1617
<!-- Lib versions -->
17-
<spawn.sdk.version>v1.3.1</spawn.sdk.version>
18+
<spawn.sdk.version>v1.4.2</spawn.sdk.version>
1819
<protobuf.version>4.27.2</protobuf.version>
1920
<testcontainers.version>1.20.1</testcontainers.version>
2021
<gson.version>2.11.0</gson.version>
@@ -64,20 +65,31 @@
6465
<dependency>
6566
<groupId>ch.qos.logback</groupId>
6667
<artifactId>logback-classic</artifactId>
67-
<version>1.4.14</version>
68+
<version>1.5.6</version>
6869
</dependency>
6970

7071
<!-- Tests -->
7172
<dependency>
7273
<groupId>org.junit.jupiter</groupId>
7374
<artifactId>junit-jupiter-api</artifactId>
74-
<version>5.10.2</version>
75+
<version>5.10.3</version>
7576
<scope>test</scope>
7677
</dependency>
7778
<dependency>
7879
<groupId>org.testcontainers</groupId>
7980
<artifactId>testcontainers</artifactId>
8081
<scope>test</scope>
82+
<exclusions>
83+
<exclusion> <!-- Remove when testcontainers update -->
84+
<groupId>org.apache.commons</groupId>
85+
<artifactId>commons-compress</artifactId>
86+
</exclusion>
87+
</exclusions>
88+
</dependency>
89+
<dependency> <!-- Remove when testcontainers update -->
90+
<groupId>org.apache.commons</groupId>
91+
<artifactId>commons-compress</artifactId>
92+
<version>1.27.1</version>
8193
</dependency>
8294
</dependencies>
8395

@@ -145,6 +157,7 @@
145157
<configuration>
146158
<source>${maven.compiler.source}</source>
147159
<target>${maven.compiler.target}</target>
160+
<release>${maven.compiler.release}</release>
148161
</configuration>
149162
</plugin>
150163
<plugin>
@@ -196,4 +209,4 @@
196209
</build>
197210
</profile>
198211
</profiles>
199-
</project>
212+
</project>

request.http

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GET http://localhost:8080/postalcode
55
POST http://localhost:8080/postalcode
66
Content-Type: application/json
77

8-
{ "postalCode": "03694090" }
8+
{ "postalCode": "03568000" }
99

1010
### get
11-
GET http://localhost:8080/postalcode/03694090
11+
GET http://localhost:8080/postalcode/03568000

src/main/java/com/github/h3nrique/postalcode/actors/PostalCode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import com.github.h3nrique.postalcode.proto.Common;
44
import com.github.h3nrique.postalcode.proto.Postalcode;
55
import com.github.h3nrique.postalcode.service.PostalCodeService;
6+
import io.eigr.spawn.api.actors.ActionBindings;
67
import io.eigr.spawn.api.actors.ActorContext;
78
import io.eigr.spawn.api.actors.StatefulActor;
89
import io.eigr.spawn.api.actors.Value;
910
import io.eigr.spawn.api.actors.behaviors.ActorBehavior;
1011
import io.eigr.spawn.api.actors.behaviors.BehaviorCtx;
1112
import io.eigr.spawn.api.actors.behaviors.NamedActorBehavior;
12-
import io.eigr.spawn.internal.ActionBindings;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

@@ -50,7 +50,7 @@ public Value onCreatePostalCode(ActorContext<Postalcode.PostalCodeState> context
5050
.setStatus(Common.PostalCodeStatus.FOUND)
5151
.build();
5252
return Value.at()
53-
.state(builder.build())
53+
.state(state)
5454
.noReply();
5555
}
5656
return Value.at()

src/main/java/com/github/h3nrique/postalcode/actors/PostalCodeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.h3nrique.postalcode.proto.Common;
44
import com.github.h3nrique.postalcode.proto.Postalcode;
55
import io.eigr.spawn.api.ActorIdentity;
6+
import io.eigr.spawn.api.actors.ActionBindings;
67
import io.eigr.spawn.api.actors.ActorContext;
78
import io.eigr.spawn.api.actors.StatelessActor;
89
import io.eigr.spawn.api.actors.Value;
@@ -11,7 +12,6 @@
1112
import io.eigr.spawn.api.actors.behaviors.NamedActorBehavior;
1213
import io.eigr.spawn.api.exceptions.ActorCreationException;
1314
import io.eigr.spawn.api.exceptions.ActorInvocationException;
14-
import io.eigr.spawn.internal.ActionBindings;
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
1717

src/main/java/com/github/h3nrique/postalcode/service/PostalCodeService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public Map<String, String> find(String postalCode) {
3737
.build();
3838
Call call = client.newCall(request);
3939
try (Response response = call.execute()) {
40-
assert response.body() != null;
40+
ResponseBody body = response.body();
41+
assert body != null;
4142
if(response.isSuccessful()) {
42-
String responseJson = response.body().string();
43+
String responseJson = body.string();
4344
Type type = new TypeToken<Map<String, String>>() { }.getType();
4445
Map<String, String> map = new Gson().fromJson(responseJson, type);
4546
log.debug("postalcode response '{}'.", map);

src/test/java/com/github/h3nrique/postalcode/actor/AbstractContainerBaseTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
1717
import org.testcontainers.utility.DockerImageName;
1818

19-
import java.util.concurrent.Executors;
20-
2119
abstract class AbstractContainerBaseTest {
2220

23-
private static final Logger log = LoggerFactory.getLogger(AbstractContainerBaseTest.class);
21+
private static final Logger LOG = LoggerFactory.getLogger(AbstractContainerBaseTest.class);
2422

25-
private static final String spawnProxyImageName = "eigr/spawn-proxy:1.4.1-rc.1";
23+
private static final String SPAWN_PROXY_IMAGE_NAME = "eigr/spawn-proxy:1.4.2-rc.2";
2624
static final GenericContainer<?> SPAWN_CONTAINER;
2725
static final Spawn spawnSystem;
2826
static final App.Config cfg;
2927

3028
static {
3129
Testcontainers.exposeHostPorts(8091);
3230

33-
SPAWN_CONTAINER = new GenericContainer<>(DockerImageName.parse(spawnProxyImageName))
31+
SPAWN_CONTAINER = new GenericContainer<>(DockerImageName.parse(SPAWN_PROXY_IMAGE_NAME))
3432
.waitingFor(new LogMessageWaitStrategy()
3533
.withRegEx(".*Proxy Application started successfully.*"))
3634
.withEnv("TZ", "America/Sao_Paulo")
@@ -72,6 +70,6 @@ abstract class AbstractContainerBaseTest {
7270
} catch (SpawnException e) {
7371
throw new RuntimeException(e);
7472
}
75-
log.info("Spawn system started");
73+
LOG.info("Spawn system started");
7674
}
7775
}

src/test/java/com/github/h3nrique/postalcode/actor/CepActorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CepActorTest extends AbstractContainerBaseTest {
1717

1818
@Test
1919
public void findCep() throws SpawnException {
20-
String cep = "03694090";
20+
String cep = "03568000";
2121
Postalcode.CreateRequest createRequest = Postalcode.CreateRequest.newBuilder()
2222
.setPostalCode(cep)
2323
.build();

src/test/java/com/github/h3nrique/postalcode/service/PostalCodeServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void setUp() {
2222

2323
@Test
2424
public void findCepOk() {
25-
Map<String, String> cepResult = postalCodeService.find("03694090");
25+
Map<String, String> cepResult = postalCodeService.find("03568000");
2626
assertFalse(cepResult.isEmpty());
2727
log.debug("cepResult :: [{}]", cepResult);
2828
}

0 commit comments

Comments
 (0)