Slide 1

Slide 1 text

Oleg Nenashev, @oleg_nenashev CNCF Ambassador

Slide 2

Slide 2 text

> whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Community builder Developer Tools Hacker #RussiansAgainstPutin #StandWithUkraine

Slide 3

Slide 3 text

Async Q&A: Testcontainers Slack speakerdeck.com/onenashev

Slide 4

Slide 4 text

5 Staging & QA Tests Build Integration tests Build Tests Gaining confidence in you software “Shift Left” with modern tools

Slide 5

Slide 5 text

“Shift Left”, they said? YAML, they gave? 6

Slide 6

Slide 6 text

7 Java All the Way Down Up Application Unit Tests Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way

Slide 7

Slide 7 text

Today 8 1. Containerizing Spring App Development 2. Integration testing with Testcontainers and LocalStack 3. Mocking APIs with WireMock 4. Infrastructure as Code (IaC) with Pulumi 5. Testing IaC locally 6. Advanced Troubleshooting Localstack

Slide 8

Slide 8 text

Our Repository github.com/oleg-nenashev/mocks-as-code-demo git clone it

Slide 9

Slide 9 text

Workshop Prerequisites ● Internet :( ● Java 17 & your favorite IDE ● Testcontainers-compatible Docker environment ○ Tested on: Docker Desktop ○ You can use: Podman, Colima, Rancher Desktop (list) ○ OR: Testcontainers Cloud ● Pulumi CLI + registration ○ Guide: www.pulumi.com/docs/install/ 10

Slide 10

Slide 10 text

Our Application 11

Slide 11

Slide 11 text

12 AWS S3 SQS External API Our Application

Slide 12

Slide 12 text

Credits 13 ● Siva Prasad Reddy and Oleg Shelajev, Docker ● The demos are based on: ○ github.com/testcontainers/tc-guide-testing-aws-service-integrations-using-loca lstack ○ github.com/testcontainers-community/testcontainers-wiremock-demo

Slide 13

Slide 13 text

Integration Testing? 14 github.com/oleg-nenashev/mocks-as-code-demo/ tree/main/2_api_mocking

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Ways to do API integration testing 1. Testing against Production/Staging servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides

Slide 18

Slide 18 text

19 https://martinfowler.com/articles/ mocksArentStubs.html

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

21 SDKs testcontainers.org … and

Slide 21

Slide 21 text

22 github.com/testcontainers/ testcontainers-go

Slide 22

Slide 22 text

Example - Java 23

Slide 23

Slide 23 text

24 LOCAL STACK LocalStack Module K3s Module

Slide 24

Slide 24 text

25 Localstack www.localstack.cloud

Slide 25

Slide 25 text

LocalStack ● Local AWS Services emulation OR mocking ● “awslocal” CLI utility ● SDKs for languages and test frameworks 26 docs.localstack.cloud/

Slide 26

Slide 26 text

27 x.com/dastbe/status/1303858170155081728

Slide 27

Slide 27 text

Some of Them 28 ● Emulated: S3, SQS, … ● Mocked: EC2 (in the FOSS lib) ● Thoughts & Prayers: AWS GreenShift ;) ● …

Slide 28

Slide 28 text

Demo Time 29 github.com/oleg-nenashev/mocks-as-code-demo/ tree/main/1_application

Slide 29

Slide 29 text

No Implementation? 30 Fake it until you “$ make it”

Slide 30

Slide 30 text

Ways to do API integration testing 1. Testing against Production/Staging servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides

Slide 31

Slide 31 text

wiremock.org/docs/stubbing IF (request_url) THEN (response) * * it gets MUCH more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2 API Mocking 101

Slide 32

Slide 32 text

API Mocking Tools Main implementation in Java Native lib, Docker images and Testcontainers modules Support for GraalVM Rich Ecosystem Sandbox CNCF Project Golang / Microservice arch Docker image, Testcontainers module, All-in K8s Charts Less Rich Ecosystem

Slide 33

Slide 33 text

WireMock Ecosystem & Features wiremock.org/docs

Slide 34

Slide 34 text

WireMock Ecosystem wiremock.org/docs

Slide 35

Slide 35 text

WireMock in Java wiremock.org/docs/stubbing

Slide 36

Slide 36 text

WireMock Ecosystem / Java ● Java ● Kotlin ● Scala ● Groovy ● Clojure ● (?)Android 37 ● JUnit 4/5 ● Testcontainers ● Sprint Boot ● Spring Cloud Contract ● Quarkus ● Maven / Gradle Build Tool ● Spock ● Pact

Slide 37

Slide 37 text

Example - JUnit 5 38

Slide 38

Slide 38 text

39 WireMock has an official Testcontainers module! testcontainers.com/modules/wiremock

Slide 39

Slide 39 text

Demo Time 40 github.com/oleg-nenashev/mocks-as-code-demo

Slide 40

Slide 40 text

41 Infrastructure-as-Code, for real

Slide 41

Slide 41 text

42

Slide 42

Slide 42 text

43 And more constructive!

Slide 43

Slide 43 text

HOWTO: JavaDev-Ops 44

Slide 44

Slide 44 text

Enter -as-Code Tools! ● Infrastructure as Real Code ● SDKs for programming languages ● Standard IDEs ● Standard Developer Tools ● Extensibility via libraries 45

Slide 45

Slide 45 text

● Open-Ecosystem Tool for Infra-as-Code ● Open Source SDKs 46

Slide 46

Slide 46 text

● Multiple destinations 47 www.pulumi.com

Slide 47

Slide 47 text

● 120+ extensions: www.pulumi.com/registry/ 48 www.pulumi.com

Slide 48

Slide 48 text

Pulumi for Java 49 pulumi.com/docs/languages-sdks/java/

Slide 49

Slide 49 text

build.gradle 50

Slide 50

Slide 50 text

51 Java All the Way Down Up Application Unit Tests Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way

Slide 51

Slide 51 text

52 Localstack

Slide 52

Slide 52 text

Pulumi Local ● github.com/localstack/pulumi-local ● Setting the environment and the configuration right ● Just a script 53 Localstack

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Hacking Time! 56 github.com/oleg-nenashev/mocks-as-code-demo/ tree/main/3_deployment

Slide 56

Slide 56 text

When it Goes wrong 57

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Demo Time 61 github.com/oleg-nenashev/mocks-as-code-demo

Slide 61

Slide 61 text

Lessons Learned 62

Slide 62

Slide 62 text

Beware Pulumi for AWS Native ● AWS Native configuration is not applied for endpoints ● APIs are slightly different in the package 63

Slide 63

Slide 63 text

64

Slide 64

Slide 64 text

65

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

67

Slide 67

Slide 67 text

68 Java All the Way Down Up Application Unit Tests Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way

Slide 68

Slide 68 text

What I’m looking forward to? ● Feedback from Java developers ● Is Infra-as-Code with Java interesting to you? ● Do you want Pulumi-LocalStack for Java productization? ● Any other feedback on dev tools :)

Slide 69

Slide 69 text

References ● Main Demo: github.com/oleg-nenashev/mocks-as-code-demo ● This presentation: speakerdeck.com/onenashev/ workshop-mocks-as-code-in-cfg-mgmt

Slide 70

Slide 70 text

Keep Learning Tools 71 * AKA: Burning Out 101

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

It’s [always] a great time to contribute! testcontainers.org/contributing wiremock.org/participate 73

Slide 73

Slide 73 text

GitHub: oleg-nenashev Twitter: @oleg_nenashev Questions? 74