Skip to content

Commit

Permalink
Lesson 40
Browse files Browse the repository at this point in the history
  • Loading branch information
fmcarvalho committed Dec 13, 2024
1 parent 66e6485 commit b99b6fb
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lesson15-host/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ services:
ports:
- 5432:5432

db-tests:
container_name: db-tests
build:
context: ../lesson13-agendify-repository-jdbi
dockerfile: ../lesson13-agendify-repository-jdbi/tests/Dockerfile-db-test
environment:
- POSTGRES_USER=dbuser
- POSTGRES_PASSWORD=changeit
- POSTGRES_DB=db
ports:
- 5432:5432

# agendify-jvm-1 and agendify-jvm-2 are used to illustrate scenarios with a fixed number of servers
# with static and well know names.
agendify-jvm-1:
Expand All @@ -35,7 +23,7 @@ services:
image: agendify-jvm
environment:
PORT: 8081
DB_URL: "jdbc:postgresql://db-tests:5432/db?user=dbuser&password=changeit"
DB_URL: "jdbc:postgresql://agendify-postgres-test:5432/db?user=dbuser&password=changeit"
ports:
- 8081:8081
agendify-jvm-2:
Expand All @@ -44,7 +32,7 @@ services:
image: agendify-jvm
environment:
PORT: 8082
DB_URL: "jdbc:postgresql://db-tests:5432/db?user=dbuser&password=changeit"
DB_URL: "jdbc:postgresql://agendify-postgres-test:5432/db?user=dbuser&password=changeit"
ports:
- 8082:8082

Expand Down
12 changes: 12 additions & 0 deletions lesson15-host/test-infra/Dockerfile-postgres-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM postgres

USER postgres
WORKDIR /app

COPY src/sql/create-schema.sql /docker-entrypoint-initdb.d/1_create.sql
COPY src/sql/insert-test-data.sql /docker-entrypoint-initdb.d/2_insert-test-data.sql

COPY --chown=postgres:postgres ./tests/scripts/wait-for-postgres.sh ./bin/wait-for-postgres.sh
RUN chmod +x ./bin/wait-for-postgres.sh

EXPOSE 5432
28 changes: 28 additions & 0 deletions lesson40-demo-load-balancing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
kotlin("jvm") version "1.9.25"
}

group = "pt.isel"
version = "unspecified"

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework:spring-core:6.0.0")

// To use SLF4J
// For logging purposes
implementation("org.slf4j:slf4j-api:2.0.16")
runtimeOnly("org.slf4j:slf4j-simple:2.0.16")

testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
23 changes: 23 additions & 0 deletions lesson40-demo-load-balancing/src/main/kotlin/pt/isel/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pt.isel

import org.slf4j.LoggerFactory
import org.springframework.util.StopWatch
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse.BodyHandlers

private val logger = LoggerFactory.getLogger("main")

fun main() {
val httpClient = HttpClient.newHttpClient()
val request = HttpRequest.newBuilder(URI.create("http://localhost:8088/api/status/ip")).GET().build()
while (true) {
val sw = StopWatch().also { it.start() }
logger.info("Request sent...")
val response = httpClient.send(request, BodyHandlers.ofString())
sw.stop()
logger.info("...response received: {}, {}, {}", response.statusCode(), sw.totalTimeMillis, response.body())
Thread.sleep(2000)
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ include("lesson13-agendify-repository-jdbi")
include("lesson15-host")
include("lesson16-http-pipeline")
include("lesson18-agendify-SSE")
include("lesson40-demo-load-balancing")

0 comments on commit b99b6fb

Please sign in to comment.