https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
p

Philipp Mayer

05/21/2023, 4:36 PM
Hi all, I’m currently working through exploring the testing hyperpyramid and do have a question:
ShopApi
(Github) gets passed in one
httpHandler
, which is being used (via
outgoingHttp
) for two different targets: The
Warehouse
and
SESNotifications
. In
LocalShopApiTests
(Github),
FakeWarehouse()
is being passed in, which then ends up also being used for
SESNotifications
. Shouldn’t there be two parameters, one that gets a
FakeWarehouse
and one that gets a
FakeSES
? Why is that/what am I missing here? 🙂 Thanks in advance!
s

s4nchez

05/21/2023, 5:32 PM
Yes, to keep adapters clearly separated I tend to recommend going with one handlers per dependency.
In that codebase it doesn’t make much difference because in the “end to end” tests we have an environment that can do the routing to the correct system.
Also, we didn’t want to complicate the example even further, but usually the “core” of the hexagon should ideally receive clients defined at domain level too, not http handlers directly.
d

dave

05/21/2023, 6:21 PM
Well spotted @Philipp Mayer! I think there is a bit of a confusion here. The Shop itself will definitely take a single dependency per port - so one for the Email client and one for the Warehouse client. However, I actually support using a single HTTP handler to the ShopAPI (which takes the HTTP "adapter")... and then use the reverse proxy pattern to split the traffic. This means that you only need one HTTP client (or you can also use a reverserproxy when injecting them to direct the traffic to a different HTTP client based on the URL.)
The reason that the FakeWarehouse is injected in is because there actually isn't a service level test that exercises the email client in that repo. We created the repo especially for the presentation, so it doesn't contain the amount of testing that we would generally put in covering all functionalities. We also wanted to keep the codes in the slides as simple as possible - they were complicated enough and the flow of the slides didn't really warrant putting in the FakeSES at that point in the deck! 🙂
p

Philipp Mayer

05/21/2023, 6:50 PM
Thanks for the in-depth explanation you two! I already thought that it's because of keeping things simple. I'm curious though: how do you do it at work? I'm building a real world example and I'm curious how my entry point into the module should look like. Let's say you have a service that calls two other services: do you take 2 URIs and 2 http handlers? Or do you have specific classes that are already wired that you pass in (hexagonal arch aside, I'm aware that this is abstracted away then :) )
I actually support using a single HTTP handler to the ShopAPI (which takes the HTTP "adapter")... and then use the reverse proxy pattern to split the traffic. This means that you only need one HTTP client (or you can also use a reverserproxy when injecting them to direct the traffic to a different HTTP client based on the URL.)
Interesting stuff! Is this a common pattern in your services? Passing in one http handler that's actually a reverse proxy which then translates two X services?
Sorry for all the questions, but I'm still wrapping my head around it as I didn't have the chance to work on a more complex project with http4k yet.
d

dave

05/21/2023, 7:11 PM
That's ok - questions are welcome! And the answer to your question is yes - you can use a reverseProxy() in client HTTP handlers to fan out from a single HTTP client, depending on the URL.
something like this shows it - it means you can use different retries, timeouts or even different client libraries for each.
val http = reverseProxy(
        WAREHOUSE_URL(ENV).authority to JavaHttpClient(),
        "ses" to JavaHttpClient()
    )
You can really go to town on this stuff - and actually hide is all behind a
ServiceDiscovery
interface - which is basically:
interface ServiceDiscovery = (AppName) -> HttpHandler
- we did have it in the example repo originally but it complicated the slides too much so we pared it back. But it does make the wiring stuff easier to manage TBH (what became the NetworkAccess in the repo)... especially for running different "universes" - such as an InMemoryUniverse and a StagingUniverse and a LocalServerUniverse....
As for the URLs, in our example the app always takes an Environment and passes individual URLs down to the individual clients to be used with a SetBaseHostFrom, but in the case of using a ServiceDiscovery, even that is all taken away and you end up just passing the client... so
HttpWarehouse(env[WAREHOUSE_URL], outgoingHttp)
... would become something like:
HttpWarehouse(serviceDiscovery(AppName.Warehouse)
(ie all of the envrironmental stuff is hidden from the main app construction logic)
The wider scope for all this is our intention of making application identities, profiles and their dependencies be explicitly codified - there are cool implications that doing this statically in code give you, like being able to make it impossible to create an HTTP client for another application which you have not explicitly declared a dependency on... or you can use the dependency matrix to be built into the tooling - to generate dashboards, or builds or anything else you can think of. But that's all somewhat a tad more than we had time for in 40 minutes plus questions... 😂
p

Philipp Mayer

05/21/2023, 7:40 PM
One last question: Most of this works by staying rather generic when declaring what dependency is needed (e.g.
HttpHandler
instead of
MyHttpBankClientClass
) - how do you assure that other teams/devs use it as intended? For example, you have
AppIncomingHttp
and
AppOutgoingHttp
which are both http handlers that could be mixed up. More of a design debate now, but I’m curious
d

dave

05/21/2023, 7:46 PM
Well the genericness comes into the main application - the hub itself is always typed to the specific Port interface. (Those last 2 we refer to as "Stacks" BTW because they are just a wrapper around a bunch of Filters). As for mixing them up, we try to build by convention and by leaning on common infrastructure and tests! So as well as a common set of infra building blocks, we have a common set of test cases (interfaces) which are applied to every service as a base-layer. These test cases will check for common things like
HasOpenApi
, or
EndpointsAreSecured
and they can all be mixed into the main test suite - all you need to do is to provide a base test class which supplies the HTTP handler application setup and implements all of the Test interfaces and you get them all for free 🙂
p

Philipp Mayer

05/21/2023, 7:49 PM
Awesome, that’s what I call great engineering culture. Thanks for the in-depth explanations!