Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micronaut Test Resources

Micronaut Test Resources

Cédric Champeau

December 14, 2022
Tweet

More Decks by Cédric Champeau

Other Decks in Programming

Transcript

  1. Micronaut Test Resources
    Automatic test resources provisioning
    for your Micronaut applications
    Cédric Champeau
    Micronaut, Oracle Labs
    @[email protected]
    @CedricChampeau
    Copyright © 22-12-14, Oracle and/or its affiliates
    Micronaut® is a registered trademark of Object Computing, Inc. Use is for referential purposes and does not
    imply any endorsement or affiliation with any third-party product. Unauthorized use is strictly prohibited.

    View Slide

  2. - Working at Oracle Labs on Micronaut
    Main focus on build plugins and dev
    productivitity
    - Formerly working at Gradle Inc
    - Author of static compiler of Groovy
    - Amateur astronomer
    @[email protected]
    https://www.astrobin.com/users/melix/
    https://bit.ly/3eGD0GM (Youtube)
    About me
    Copyright © 2022, Oracle and/or its affiliates
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  3. Graal Cloud Native (GCN)
    Copyright © 2022, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted
    3
    Use Graal Cloud Native toolkit to leverage services like
    object-storage, monitoring, authentication, secret
    management, and deploy to popular cloud platforms.
    Graal Cloud Native lets you take full advantage of
    powerful cloud services without coupling to
    proprietary platform APIs and makes application
    portability possible.
    Graal Cloud Native supports Micronaut and Spring
    Boot Java Frameworks with Helidon support coming
    soon.

    View Slide

  4. Simplified service
    usage eliminates the
    need to learn
    proprietary platform
    APIs.
    Advanced compile-time
    validation to reduce
    dev/test/debug cycle.
    Inject cloud features
    right into an application
    exactly where they are
    needed.
    Major public cloud
    services supported out
    of the box.
    Compile Java
    applications with
    GraalVM Native to start
    lightening fast, operate
    at peak performance
    immediately, and require
    less memory and CPU.
    Package into lightweight
    container images for
    even faster deployment
    Deploy to different
    cloud providers with no
    code changes.
    Support for all the
    major cloud platforms.
    Graal Cloud Native
    Copyright © 2022, Oracle and/or its affiliates | Confidential: Internal
    4
    Easily Leverage
    Cloud Platform
    Services
    Multicloud by
    design
    Developer
    Productivity
    Write Microservices
    as Cloud-Native
    Applications
    Benefits

    View Slide

  5. - Micronaut is focused on modern architectures
    like Serverless and Microservices
    - Also a complete framework for any type of
    application
    - Lightweight, reactive (HTTP Client/Server
    based on Netty)
    - Annotation processor to compute framework
    infrastructure at compile time
    Micronaut
    Copyright © 2022, Oracle and/or its affiliates
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  6. Micronaut computes:
    - All dependency & configuration injection
    - Annotation metadata, meta-annotations
    - AOP proxies
    - Bean introspections
    - And all other framework infrastructure
    - Reflection, runtime proxy, and dynamic
    classloader free
    Micronaut = Build Time Framework Infrastructure
    Copyright © 2022, Oracle and/or its affiliates
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  7. High-performance JDK distribution
    Increases application throughput, reduces
    latency, reduces memory use
    Graal just-in-time (JIT) compiler that runs on top
    of HotSpot, written in Java
    native-image ahead-of-time (AoT) compiler
    compiles Java applications into small self-
    contained native binaries
    Micronaut = Build Time Framework Infrastructure
    Copyright © 2022, Oracle and/or its affiliates
    graalvm.org github.com/graalvm/graalvm-demos
    oracle.com/graalvm

    View Slide

  8. Micronaut + GraalVM Native Image are a match
    made in heaven
    Less work to configure Native Image because
    Micronaut eliminates reflection, runtime
    proxies, bytecode generation and dynamic
    classloading
    Startup time 20ms and Memory Consumption
    18MB!
    Micronaut GraalVM
    ♥️
    Copyright © 2022, Oracle and/or its affiliates
    graalvm.org github.com/graalvm/graalvm-demos
    oracle.com/graalvm
    ♥️

    View Slide

  9. - New in Micronaut 3.6
    - Simplifies setup of tests
    - eg. spawn a database container, a Kafka
    server, …
    - Compatible with native executables
    - Extensible
    Micronaut Test Resources
    Copyright © 2022, Oracle and/or its affiliates
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  10. Copyright © 2022, Oracle and/or its affiliates | Confidential: Internal/Restricted/Highly Restricted
    10

    View Slide

  11. Micronaut Test Resources
    Copyright © 2022, Oracle and/or its affiliates
    Demo 1 : Micronaut Data JDBC + Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide


  12. ./gradlew test → spawns test resources

    ./gradlew run → also spawns test resources

    ./gradlew -t test (or run) → keeps tests resources alive

    ./gradlew startTestResourcesService → test resources outlive the build

    ./gradlew nativeTest
    • Builds a native image which can connect to test resources service
    • Runs tests against the test resources
    Micronaut Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  13. Micronaut Test Resources
    Copyright © 2022, Oracle and/or its affiliates
    Demo 2 : Micronaut MQTT + Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide


  14. Supports test resources service cross-project
    • Two independent “Git” repositories can share resources
    • Or in simpler use cases, different modules of same repository

    Supports test resources service cross-build tools!
    • e.g, producer built with Maven and consumer built with Gradle
    Micronaut Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide

  15. Micronaut Test Resources
    Copyright © 2022, Oracle and/or its affiliates
    Demo 3 : Micronaut Email + Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide


  16. Supports conventional way to declare new resources
    Micronaut Test Resources
    test-resources:
    containers:
    fakesmtp:
    image-name: ghusta/fakesmtp
    hostnames:
    - smtp.host
    exposed-ports:
    - smtp.port: 25

    View Slide

  17. Micronaut Test Resources
    Copyright © 2022, Oracle and/or its affiliates
    Demo 4 : Custom Test Resources
    micronaut.io github.com/micronaut-projects/micronaut-core

    View Slide


  18. Supports completely adhoc test resources
    Micronaut Test Resources
    public class MyTestResource implements TestResourcesResolver {
    public static final String MY_TEST_PROPERTY = "my.user.name";
    @Override
    public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) {
    return Collections.singletonList(MY_TEST_PROPERTY);
    }
    @Override
    public Optional resolve(String propertyName, Map properties, Map testResourcesConfiguration) {
    if (MY_TEST_PROPERTY.equals(propertyName)) {
    return Optional.of("world");
    }
    return Optional.empty();
    }
    }

    View Slide

  19. View Slide


  20. Supports both JDBC and R2DBC
    • PostgreSQL
    • MySQL/MariaDB
    • Oracle XE
    • Microsoft SQL Server

    Container based resources
    • Elasticsearch
    • Kafka
    • MongoDB
    • MQTT (HiveMQ, RabbitMQ)
    • Neo4J
    • Redis
    • Hashicorp Vault
    Micronaut Test Resources : conclusion

    View Slide


  21. Generic Testcontainers support
    • Expose your own container via conventional properties
    • Allows mounting local files, etc.

    Generic test resources support
    • Implement your own!

    Compatible with native images
    • Isolates your application code from test resources
    • Native binary connects to remote service
    Micronaut Test Resources : conclusion

    View Slide


  22. Micronaut Launch : https://micronaut.io/launch

    Micronaut Project: https://micronaut.io/

    Micronaut Test Resources: https://github.com/micronaut-projects/micronaut-test-resources
    Slides coming @[email protected]
    Micronaut Test Resources : resources

    View Slide

  23. View Slide