Slide 1

Slide 1 text

Oleg Nenashev, @oleg_nenashev CNCF Ambassador / Gradle Inc.

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: Gradle Community Slack, Testcontainers Slack speakerdeck.com/onenashev

Slide 4

Slide 4 text

4 Developer Productivity Engineering (DPE)

Slide 5

Slide 5 text

DPE is Like SRE, but for Developer Productivity 5

Slide 6

Slide 6 text

6 gradle.com/ developer-productivity-engineering

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

8 Localstack

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

10 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 11

Slide 11 text

Today 11 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 12

Slide 12 text

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

Slide 13

Slide 13 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/ ● Nice2Have: Gradle Build Scan account ○ scans.gradle.com/ 13

Slide 14

Slide 14 text

Our Application 14

Slide 15

Slide 15 text

15 AWS S3 SQS External API Our Application

Slide 16

Slide 16 text

Credits 16 ● 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 17

Slide 17 text

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

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 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 22

Slide 22 text

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

Slide 23

Slide 23 text

23 SDKs testcontainers.org … and

Slide 24

Slide 24 text

24 github.com/testcontainers/ testcontainers-go

Slide 25

Slide 25 text

Example - Java 25

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

27 LOCAL STACK LocalStack Module K3s Module

Slide 28

Slide 28 text

28 Localstack www.localstack.cloud

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

30 x.com/dastbe/status/1303858170155081728

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 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 35

Slide 35 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 36

Slide 36 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 37

Slide 37 text

WireMock Ecosystem & Features wiremock.org/docs

Slide 38

Slide 38 text

WireMock Ecosystem wiremock.org/docs

Slide 39

Slide 39 text

WireMock in Java wiremock.org/docs/stubbing

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

Example - JUnit 5 41

Slide 42

Slide 42 text

WireMock Plugin for Gradle 42 William-Hill-Online/wiremock-gradle-plugin

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

45 Infrastructure-as-Code, for real

Slide 46

Slide 46 text

46

Slide 47

Slide 47 text

47 And more constructive!

Slide 48

Slide 48 text

HOWTO: JavaDev-Ops 48

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

● Multiple destinations 51 www.pulumi.com

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

build.gradle 54

Slide 55

Slide 55 text

55 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 56

Slide 56 text

56 Localstack

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

When it Goes wrong 61

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

66 gradle --scan Gradle Profiler Java Tools and IDEs Gradle Observability

Slide 67

Slide 67 text

67 OpenTelemetry plugin for Gradle ● Injecting traces and spans to the Gradle execution ● Helps to find the slowest parts of your build with the Gradle OpenTelemetry build plugin. ● Created by Craig Atkinson ● craigatk/opentelemetry-gradle-plugin

Slide 68

Slide 68 text

68 Gradle tasks tracing github.com/craigatk/ opentelemetry-gradle-plugin

Slide 69

Slide 69 text

Tests traces too! github.com/craigatk/opentelemetry-gradle-plugin

Slide 70

Slide 70 text

70

Slide 71

Slide 71 text

But Not Insights? 71

Slide 72

Slide 72 text

Based On True Events 72

Slide 73

Slide 73 text

Gradle Build Scan & Develocity

Slide 74

Slide 74 text

● For many open source projects: Gradle sponsors Develocity licenses/hosting, helps with build optimization and developer productivity ● Maven, Bazel and sbt projects welcome gradle/develocity-oss-projects

Slide 75

Slide 75 text

works for Pulumi and Integration Tests Tool! 75

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

Lessons Learned 77

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

79

Slide 80

Slide 80 text

80

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

82

Slide 83

Slide 83 text

83 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 84

Slide 84 text

Move to Kotlin? blog.gradle.org/kotlin-dsl-is-now-the-default -for-new-gradle-builds ● 2023 - Kotlin is a default for Gradle build authoring ● Scripts, Plugins

Slide 85

Slide 85 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 Gradle :)

Slide 86

Slide 86 text

References ● Main Demo: github.com/oleg-nenashev/mocks-as-code-demo ● Gradle Build Scan: scans.gradle.com ● Credits: github.com/testcontainers/tc-guide-testing-rest-api-integrations-u sing-wiremock

Slide 87

Slide 87 text

Keep Learning Tools 87 * AKA: Burning Out 101

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

It’s [always] a great time to contribute! gradle.github.io/community/contributing testcontainers.org/contributing wiremock.org/participate 89

Slide 90

Slide 90 text

GitHub: oleg-nenashev Twitter: @oleg_nenashev Gradle Community Slack, #developer-productivity-engineering Questions? Testcontainers Slack 90