$30 off During Our Annual Pro Sale. View Details »

Microservices Testing Strategies

Microservices Testing Strategies

Building Cloud-Native App Series - Part 8 of 15
Microservices Architecture Series
Testing Platforms
- JUnit 5
- TestNG
- Spring Spock
Testing Strategies
- JUnit 5
- Cucumber BDD
- Selenium
- SpringBoot Test
- Mockito
- Wiremock
- Pact

Araf Karsh Hamid

June 01, 2022
Tweet

More Decks by Araf Karsh Hamid

Other Decks in Technology

Transcript

  1. @arafkarsh arafkarsh
    8 Years
    Network &
    Security
    6+ Years
    Microservices
    Blockchain
    8 Years
    Cloud
    Computing
    8 Years
    Distributed
    Computing
    Architecting
    & Building Apps
    a tech presentorial
    Combination of
    presentation & tutorial
    ARAF KARSH HAMID
    Co-Founder / CTO
    MetaMagic Global Inc., NJ, USA
    @arafkarsh
    arafkarsh
    1
    Microservices
    Architecture Series
    Building Cloud Native Apps
    Testing Strategies
    Behavior Driven Design
    JUnit 5, TestNG, Spring Spock
    Cucumber, Selenium, Mockito,
    WireMock, Pact
    Part 8 of 15

    View Slide

  2. @arafkarsh arafkarsh 2
    Slides are color coded based on the topic colors.
    Microservices
    Testing Strategies
    1
    Unit Testing
    JUnit 5
    2
    Behavior Driven
    Development
    Cucumber, Selenium
    Mockito
    3
    Integration /
    Contract Testing
    WireMock, Pact
    4

    View Slide

  3. @arafkarsh arafkarsh
    Agile
    Scrum (4-6 Weeks)
    Developer Journey
    Monolithic
    Domain Driven Design
    Event Sourcing and CQRS
    Waterfall
    Optional
    Design
    Patterns
    Continuous Integration (CI)
    6/12 Months
    Enterprise Service Bus
    Relational Database [SQL] / NoSQL
    Development QA / QC Ops
    3
    Microservices
    Domain Driven Design
    Event Sourcing and CQRS
    Scrum / Kanban (1-5 Days)
    Mandatory
    Design
    Patterns
    Infrastructure Design Patterns
    CI
    DevOps
    Event Streaming / Replicated Logs
    SQL NoSQL
    CD
    Container Orchestrator Service Mesh

    View Slide

  4. @arafkarsh arafkarsh
    Microservices Testing Strategies
    • Unit testing
    • Component testing
    • Integration Contract testing
    • Integration testing
    4
    1

    View Slide

  5. @arafkarsh arafkarsh
    Microservices Testing Strategies
    5
    E2E
    Testing
    Integration
    Testing
    Contract Testing
    Component Testing
    Unit Testing
    Number of Tests
    Speed
    Cost
    Time
    Mike Cohen’s Testing Pyramid
    Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html
    70%
    20%
    10%
    Ubiquitous
    Language
    Domain
    Expert
    Analyst Developers
    QA
    Design
    Docs
    Test Cases
    Code
    Architect

    View Slide

  6. @arafkarsh arafkarsh
    Other Testing Strategies or Anti Patterns
    6
    End 2 End
    Testing
    Integration
    Testing
    Unit
    Testing
    Inverted Pyramid /
    Ice Cream Cone Strategy
    Unit Testing
    Integration Testing
    End 2 End
    Testing
    Hour Glass Strategy
    70%
    20%
    10%
    45%
    45%
    10%

    View Slide

  7. @arafkarsh arafkarsh
    Microservices Testing Strategy
    7
    Unit Testing
    A unit test exercises the
    smallest piece of testable
    software in the application
    to determine whether it
    behaves as expected.
    Source: https://martinfowler.com/articles/microservice-testing/#agenda
    Component Testing
    A component test limits the
    scope of the exercised
    software to a portion of the
    system under test,
    manipulating the system
    through internal code
    interfaces and using test
    doubles to isolate the code
    under test from other
    components.
    Integration Testing
    An integration test verifies
    the communication paths
    and interactions between
    components to detect
    interface defects
    Integration Contract Testing
    An Integration Contract test is a
    test at the boundary of an
    external service verifying that it
    meets the contract expected by a
    consuming service.
    End 2 End Testing
    An end-to-end test verifies that a
    system meets external
    requirements and achieves its
    goals, testing the entire system,
    from end to end
    Say NO to End 2 End Tests - Mike
    Walker April 22, 2015. Google Test Blog

    View Slide

  8. @arafkarsh arafkarsh
    Microservices Testing Scenarios / Tools
    8
    Testing Tools
    Contract Testing Scope
    Integration Testing
    Verifies the communication
    paths and interactions between
    components to detect interface
    defects
    Contract Testing
    It is a test at the boundary of an
    external service verifying that it
    meets the contract expected by a
    consuming service.
    Payment Mock
    Integration Contract Testing Scope
    Test Double
    Montebank
    Cart
    Component Testing
    Unit
    Testing
    Integration Testing Scope
    Order
    REST / HTTP or
    Events / Kafka
    Item ID,
    Quantity,
    Address..
    Mock Order
    Component Testing
    A component test limits the
    scope of the exercised
    software to a portion of the
    system under test.
    Order
    Payment
    Unit
    Testing
    Firewall
    Integration Testing Scope
    REST / HTTP
    Payment
    Sandbox
    Component
    Testing
    U

    View Slide

  9. @arafkarsh arafkarsh
    Junit 5
    5.7.2
    Cucumber
    6.10.4
    Mockito
    3.11.2
    Selenium
    4.0.0
    WireMock
    2.29.1
    Pact
    4.0.10
    9
    Source: https://github.com/MetaArivu/ms-order-service

    View Slide

  10. @arafkarsh arafkarsh
    Package Structure
    10
    1. Order Service
    2. Payment Service
    3. Packing Service
    4. Shipping Service
    5. Warehouse Service
    6. Delivery City Service
    Services
    1. Order Controller
    Controllers
    Source: https://github.com/MetaArivu/ms-order-service

    View Slide

  11. @arafkarsh arafkarsh
    Order Service API Calls
    11
    http://localhost:90880/swagger-ui.html
    Based on Open API v3

    View Slide

  12. @arafkarsh arafkarsh
    JUnit 5
    • JUnit 5 Testing
    • Annotations
    • Tags and Filtering
    • Meta Annotations
    • Basic Assertions in JUnit 5
    • Testing Categories
    12
    2

    View Slide

  13. @arafkarsh arafkarsh
    JUnit 5 – Unit Testing
    13
    Assert
    @BeforeAll
    @BeforeEach
    @Test
    @AfterEach
    @AfterAll
    System
    Under
    Test
    All the
    Test
    Cases
    Setup
    Check
    Verify
    Teardown
    Test Suites
    Teardown All
    Setup All

    View Slide

  14. @arafkarsh arafkarsh
    JUnit 5 – Test Annotations
    14
    @Test
    @RepeatedTest
    @ParametrizedTest
    @NestedTest
    @ValueSource
    @EnumSource
    @MethodSource
    @CsvSource
    @CsvFileSource
    @ArgumentSource
    @DisplayName
    Give meaningful name
    for your tests
    @Tag
    Categorize and Filter
    your tests.
    @Order
    Execute your tests in a
    specific order.
    @Disabled
    Disables your test

    View Slide

  15. @arafkarsh arafkarsh
    JUnit 5 – Tags and Filtering
    15
    Functional
    Non-Functional
    Performance
    Usability
    Security
    Accessibility
    Stress
    Load

    View Slide

  16. @arafkarsh arafkarsh
    JUnit 5 – Meta Annotations
    16
    Non-Functional
    Performance
    Load

    View Slide

  17. @arafkarsh arafkarsh
    Filtering in POM File using Sure Fire Plugin
    1. Using Tags, you can filter specific
    tests to get executed in your build
    process.
    2. For Ex. If you tags like All, Unit,
    Components, Contract, and
    Integration and you want to run
    only Component and Contract
    Testing and exclude Non-
    Functional Tests. Then

    Component, Contract


    Non-Functional

    View Slide

  18. @arafkarsh arafkarsh
    Basic Assertions in JUnit 5
    18
    Assertion Details
    fail Fails a test with a given message and or Exception
    assertTrue Validates that the supplied Condition is True
    assertFalse Validates that the supplied Condition is False
    assertNull Validates the the supplied Object is Null
    assertEquals Validates that 2 supplied Objects are equal
    assertArrayEquals Validates that 2 supplied Arrays are equals
    assertIterableEquals Validates that 2 supplied Iterable Objects are equal.
    assertLineMatch Validates that 2 lines of Strings are equal.
    assertNotEquals Validates that 2 supplied Objects are NOT Equal
    assertSame Validates that 2 Object are same – compared with ==
    assertNotSame Validates that 2 Objects are not same – compared with !=

    View Slide

  19. @arafkarsh arafkarsh
    Assertions in JUnit 5
    19
    Assertion Details
    assertAll Groups different Assertion at the same time
    assertThrows
    To verify that a given Exception is thrown from piece
    of code.
    assertTimeout Verifies the timeout of a given operation
    assertTimeoutPreemptively If the timeout exceeds then terminated.
    3rd Party Assertions
    assertThat
    An object is matched with a Matcher to see if it
    meets the expectation.

    View Slide

  20. @arafkarsh arafkarsh
    JUnit 4 >> JUnit 5
    20
    JUnit 4 JUnit 5
    @BeforeClass Executed Before All @Test in the Current Class @BeforeAll
    @Before Executed Before each @Test @BeforeEach
    @After Executed After Each @Test @AfterEach
    @AfterClass Executed After All @Test in the Current Class @AfterAll
    @Category To Group the test cases @Tag

    View Slide

  21. @arafkarsh arafkarsh
    Junit 5 – Parametrized Tests
    21
    Value Source
    Enum Source

    View Slide

  22. @arafkarsh arafkarsh
    JUnit 5 – Parametrized Tests
    22
    CSV Source
    CSV File Source

    View Slide

  23. @arafkarsh arafkarsh
    JUnit 5 – Parametrized Tests
    23
    Method Source

    View Slide

  24. @arafkarsh arafkarsh
    JUnit 5 – Parametrized Tests
    24
    Argument Source
    Argument Source Provider

    View Slide

  25. @arafkarsh arafkarsh
    JUnit 5 – Nested Tests
    25

    View Slide

  26. @arafkarsh arafkarsh
    JUnit 5 – Repeated Tests
    26

    View Slide

  27. @arafkarsh arafkarsh
    Cucumber
    Behavior Driven Development
    27
    3

    View Slide

  28. @arafkarsh arafkarsh
    Features of BDD
    28
    • Focus on Behavior of the System
    rather than tests.
    • Collaboration between Business
    Stake holders, Analysts,
    Developers, QA.
    • Ubiquitous Language
    • Driven By Business Value
    • Extends Test Driven Development
    https://cucumber.io/
    Free and Open-Source Framework for
    Java Stack.
    Free and Open Source BDD
    Framework for .Net Stack
    https://specflow.org/

    View Slide

  29. @arafkarsh arafkarsh
    Behavior Driven Development
    29
    Source: https://dannorth.net/introducing-bdd/
    As an insurance Broker
    I want to know who my Gold Customers are
    So that I sell more
    Given Customer John Doe exists
    When
    he buys insurance ABC for
    $1000 USD
    Then He becomes a Gold Customer
    BDD Construct
    Role-Feature-Reason Matrix
    As a Customer
    I want to withdraw Cash from ATM
    So that I don’t have to wait in line at the bank
    Given
    The account is in Credit
    AND the Card is Valid
    AND the dispenser contains Cash
    BDD Construct
    Role-Feature-Reason Matrix
    When The Customer requests Cash
    Then
    Ensure that the Account is debited
    AND Ensure cash is dispensed
    AND ensure that Card is returned.

    View Slide

  30. @arafkarsh arafkarsh
    Theme/Epic – Shopping Portal / Cart
    30
    As a Consumer
    I want to Add a Product to Cart
    So that I can buy the product
    Role-Feature-Reason Matrix
    User Story – 1 : Add to Cart
    BDD Acceptance Criteria – 1: Add to Cart
    Given The user logged into the portal and a Product is
    selected and Product details are available
    When The user then clicks Add to Cart Button
    Then The system will add the Item (Product) into the
    card and Updates Item counter in the Cart Icon
    AND Saves the Cart information in the DB
    AND if the save fails the system shows an Error
    “Unable to Add Product to the Cart”.
    BDD Acceptance Criteria – 2: Save Cart
    Given The Request is authenticated
    When The Input contains user login id, product
    id
    Then The system will add the Item (Product)
    into the Cart & Saves the Cart
    information in the DB
    AND if the save fails the system shows
    an Error “Unable to Add Product to the
    Cart”.

    View Slide

  31. @arafkarsh arafkarsh
    Theme/Epic – Shopping Portal / Customer
    31
    As a Consumer
    I want to Select Shipping Address
    So that I can ship the items to that Address
    Role-Feature-Reason Matrix
    User Story – 3 : Select Address BDD Acceptance Criteria – 1 : Show Address
    Given The user in the Shopping Cart Page
    When User Clicks Proceed to Buy Button
    Then The System shows the Available Address for
    Shipping
    BDD Acceptance Criteria – 2 : Select Address
    Given The user in the Shopping Cart Page with
    Available Shipping Address
    When User Selects Address and Clicks Proceed to
    Buy
    Then The System save the Temp Order details
    from Items from Shopping and Selected
    Shipping Address
    AND this details are valid only for the user
    session. If the order is not placed Temp
    Order items will be put back in Cart DB
    BDD Acceptance Criteria – 3 : Save Temp Order
    Given The Request is authenticated
    When Input contains user login id, items, shipping
    address
    Then The System save the Temp Order details
    from Items from Shopping and Selected
    Shipping Address
    AND this details are valid only for the user
    session. If the order is not placed Temp
    Order items will be put back in Cart DB

    View Slide

  32. @arafkarsh arafkarsh
    Theme/Epic – Shopping Portal / Order
    32
    As a Consumer
    I want to Process the Order
    So that I can buy products
    Role-Feature-Reason Matrix
    User Story – 1 : Process Order
    BDD Acceptance Criteria – 1 : Add Payment
    Given The user in the Order Cart Page with Items
    and selected Shipping Address
    When User Selects Payment Option As Credit Card
    AND Input the Credit Card Details in the
    following fields Card Name, Card No. Expiry
    Date, CVV Number
    Then The System Validates the Credit Card
    Number and the Expiry Date and Card Name
    & CVV Must NOT be Null
    IF Invalid Systems says invalid Payment
    details else
    Saves the info and proceed for payment.
    BDD Acceptance Criteria – 3 : Save Payment
    Given The Request is authenticated
    When Input contains user login id, order id,
    payment details (card number only last 4
    digits)
    Then The System Validates the Credit Card
    Number and the Expiry Date and Card Name
    and CVV Must NOT be Null
    IF Invalid Systems returns invalid Payment
    details
    ELSE
    Saves the following info Card Name, Card
    Number (only last 4 digits), Expiry Date
    BDD Acceptance Criteria – 3 : Payment Gateway
    Given The Request is authenticated
    When Input contains Valid payment details
    Then With the Valid Payment Details System calls
    External Payment Service for Payment
    Processing and Returns Result to Calling
    System

    View Slide

  33. @arafkarsh arafkarsh
    As a Patient
    I want to get diagnosed by a Doctor
    So that I can be healthy again
    Role-Feature-Reason Matrix
    User Story – 1 : Patient Diagnosis
    BDD Acceptance Criteria – 1 : Show Patient Info
    Given The Patient John Doe Exists and has an
    Appointment with the doctor
    When The Doctor selects the Patient Info
    Then The System shows the Patient Info with
    following details
    Patient Name, Age, Gender, Contact No. and
    the Health info contains the following
    Pulse, Blood Pressure, Height and Weight
    BDD Acceptance Criteria – 2 : Add Diagnosis
    Given Patient Details are Available
    When Doctor Selects Add Diagnosis
    Then The system shows a text area for adding the
    diagnosis and the doctor can add multiple
    diagnosis.
    BDD Acceptance Criteria – 4 : Save Diagnosis
    Given The Request is authenticated
    When Input contains Patient Diagnosis Details
    Then With the Valid Patient Diagnosis Details and
    the system will save the data send the
    response back to the user.
    BDD Acceptance Criteria – 3 : Add Prescription
    Given Patient Details & Diagnosis are Available
    When Doctor Selects Add Prescription
    Then The system shows a text area for adding the
    prescription, and the frequency of usage in a
    day and for how many days, and the doctor
    can add multiple prescription.
    Theme/Epic –
    Hospital / Diagnosis
    33

    View Slide

  34. @arafkarsh arafkarsh
    BDD Specs
    34
    BDD Style Specs for Searching for a
    Product in Amazon

    View Slide

  35. @arafkarsh arafkarsh
    Cucumber JUnit 4 Integration
    35
    Specs Definition
    Steps for Testing

    View Slide

  36. @arafkarsh arafkarsh
    Step Definitions
    36
    Dependency Injection

    View Slide

  37. @arafkarsh arafkarsh
    Specs for Payment Criteria
    37

    View Slide

  38. @arafkarsh arafkarsh
    Cucumber Junit 4 Integration
    38
    Specs Definition
    Steps for Testing

    View Slide

  39. @arafkarsh arafkarsh
    Mockito
    Component / Mock / Contract Testing
    39

    View Slide

  40. @arafkarsh arafkarsh
    Mock Testing Tools Trends for Last 5 Years
    40

    View Slide

  41. @arafkarsh arafkarsh
    Mockito Concepts
    41
    Verify
    3. Verify Expectations
    and Results Verify Result
    1. Set the expectations Expect When()
    Then Return()
    Use
    2. Use the object being
    tested
    Test your Component

    View Slide

  42. @arafkarsh arafkarsh
    Annotation – @Mock, @InjectMock
    42
    Create Mocks for
    1. Repository
    2. Payment Service
    Inject the Mocks into
    Order Service
    Scenario
    Create Mocks for the following
    1. Repository Service
    2. Payment Service
    Annotations
    • @Mock
    • @InjectMocks
    Test Cases
    1. Given a Valid Order
    2. Test for Payment Accepted
    3. Test for Payment Declined

    View Slide

  43. @arafkarsh arafkarsh
    Conditions – when().thenReturn()
    43
    Test Cases
    1. Given a Valid Order
    2. Test for Payment Accepted
    3. Test for Payment Declined

    View Slide

  44. @arafkarsh arafkarsh
    Annotation - @Spy
    44
    Spy works on the Actual
    Implementation
    Inject the Mocks
    into Order Service
    Scenario
    Create Mocks for the following
    1. Packaging Service
    2. Shipping Service
    Annotations
    • @Spy
    • @Mock
    • @InjectMocks
    Test Cases
    1. Given a Valid Paid Order
    2. Test for Packaging
    3. Test for Shipping

    View Slide

  45. @arafkarsh arafkarsh
    Annotation - @Spy
    45
    Scenario – 1
    Create Mocks for the following
    1. Packaging Service
    2. Shipping Service
    Annotations
    • @Spy
    • @Mock
    • @InjectMocks
    Test Cases
    1. Given a Valid Paid Order
    2. Test for Packaging
    3. Test for Shipping

    View Slide

  46. @arafkarsh arafkarsh
    Annotation – @Spy
    46
    Scenario – 2
    Create Mocks for the following
    1. Packaging Service
    2. Shipping Service
    Annotations
    • @Spy
    • @Mock
    • @InjectMocks
    Test Cases
    1. Given a Valid Paid Order
    2. Test for Packaging
    3. Test for Shipping

    View Slide

  47. @arafkarsh arafkarsh
    Annotation – @Spy
    47
    Scenario – 3
    Create Mocks for the following
    1. Packaging Service
    2. Shipping Service
    Annotations
    • @Spy
    • @Mock
    • @InjectMocks
    Test Cases
    1. Given a Valid Paid Order
    2. Test for Packaging
    3. Test for Shipping

    View Slide

  48. @arafkarsh arafkarsh
    Advanced Features
    48
    Scenario
    Shipping Service with Delivery City
    Details for the final Shipment
    Mockito Advanced Features
    1. Ordering the Input – InOrder
    2. Argument Matcher
    3. Counts
    4. Built In Answer
    5. Storing Arguments – Captor
    6. Throwing Exceptions

    View Slide

  49. @arafkarsh arafkarsh
    Advanced Features – InOrder
    49

    View Slide

  50. @arafkarsh arafkarsh
    Advanced Features – Argument Matcher
    50

    View Slide

  51. @arafkarsh arafkarsh
    Advanced Features – Count : External Calls
    51

    View Slide

  52. @arafkarsh arafkarsh
    Advanced Features – Built in Answers
    52

    View Slide

  53. @arafkarsh arafkarsh
    Advanced Features – Built in Answers
    53

    View Slide

  54. @arafkarsh arafkarsh
    Advanced Features – Captor : Argument Capture
    54

    View Slide

  55. @arafkarsh arafkarsh
    Advanced Features – Catching Exception
    55

    View Slide

  56. @arafkarsh arafkarsh
    SpringBootTest 2
    With JUnit 5
    56

    View Slide

  57. @arafkarsh arafkarsh
    Spring Boot Test
    57
    1. Getting Application
    Context
    2. Auto wiring the
    dependencies
    3. JUnit 5 Based
    Examples
    ü This is required for
    WireMock and Pact
    Actual Payment Service
    Implementation is loaded

    View Slide

  58. @arafkarsh arafkarsh
    SpringBootTest POM Config for JUnit 5
    58
    Exclude Default JUnit 4
    SBT v 2.5.3

    View Slide

  59. @arafkarsh arafkarsh
    WireMock, Pact
    Integration / Contract Testing
    59
    4

    View Slide

  60. @arafkarsh arafkarsh
    WireMock
    o Without SpringBootTest
    o With SpringBootTest
    60

    View Slide

  61. @arafkarsh arafkarsh
    WireMock Architecture
    61
    Service (Client) WireMock
    Request Mapping
    Response Data
    HTTP/S Calls

    View Slide

  62. @arafkarsh arafkarsh
    Use Case – Order and Payment Service
    62
    Worker
    Nodes
    Order Pod
    Order Pod
    Order Pod
    Order Service
    N4
    N3
    MySQL
    DB
    EndPoints
    N2
    Payment Pod
    Payment Pod
    Payment Pod
    Payment
    Service
    Service Call
    Kube DNS
    EndPoints
    1. Order and Payment Service
    are loosely coupled.
    2. Both need to be tested
    without any dependencies.
    3. Payment Service is an
    External Service, So a Mock
    Server is required to do the
    integration Testing.

    View Slide

  63. @arafkarsh arafkarsh
    WireMock – Setup
    63
    1. WireMock Mock
    Payment Server is setup.
    2. Payment Service is
    initialized with Payment
    Gateway (Pointing to
    Mock HTTP Server).
    3. Step 2 is required if
    SpringBootTest is Not
    used.

    View Slide

  64. @arafkarsh arafkarsh
    WireMock – Payment Accepted
    64

    View Slide

  65. @arafkarsh arafkarsh
    WireMock – Payment Declined
    65

    View Slide

  66. @arafkarsh arafkarsh
    WireMock with SpringBootTest
    66
    Actual Payment Service &
    Config Implementation is
    loaded

    View Slide

  67. @arafkarsh arafkarsh
    PACT
    o Consumer Driven Contracts
    o Provider Verification
    o Pact Broker
    o Comparison Mockito / WireMock / Pact
    67

    View Slide

  68. @arafkarsh arafkarsh
    Use Case – Product and Product Review Service
    68
    Worker
    Nodes
    Product Pod
    Product Pod
    Product Pod
    Product
    Service
    N4
    N3
    MySQL
    DB
    EndPoints
    N2
    Review Pod
    Review Pod
    Review Pod
    Review
    Service
    N4
    N3
    N1
    Service Call
    Kube DNS
    EndPoints
    Mongo
    DB
    1. Product and Product
    Reviews are two
    Microservices getting
    developed independently.
    2. Both need to be tested
    without any dependencies.
    3. Contract is driven by
    Product Service (Consumer
    of Product Review).

    View Slide

  69. @arafkarsh arafkarsh
    E2E Testing Vs. Integration Testing
    69
    Product
    Service
    Mock
    Provider
    Review
    Service
    Review
    Service
    Mock
    Consumer
    Product
    Service
    Break the Test into 2 independently testable units.
    Product
    Service
    Review
    Service
    End 2 End Testing
    is Time Consuming
    and Error Prone

    View Slide

  70. @arafkarsh arafkarsh
    PACT Architecture – Consumer Testing
    70
    Product
    Service
    Mock
    Provider
    Expected Request
    Minimal Response
    Interaction
    • Pact = A contract between
    Consumer and Provider
    • Each Pact is a collection of
    interactions
    Compare
    Reply
    Expected Request
    Minimal Response
    Interaction
    Provider State
    Pact – Contract between
    Consumer & Provider
    Once the Consumer Testing
    is done Pact file is generated
    by Pact Framework
    Pact Broker
    Publish Pacts to
    Pact Broker
    pact-broker publish --consumer-app-version 1.0.0 --broker-base-url https://broker.com
    --broker-token SomeToken /path/to/pacts/consumer-provider.json --tag master
    $>

    View Slide

  71. @arafkarsh arafkarsh
    PACT Architecture – Provider Testing
    71
    Review
    Service
    Mock
    Consumer
    Expected Request
    Minimal Response
    Interaction
    Provider State
    Compare
    Send
    Once the Consumer
    Testing is done Pact
    file is generated by
    Pact Framework
    Expected Request
    Minimal Response
    Interaction
    Provider State
    Pact – Contract between
    Consumer & Provider

    View Slide

  72. @arafkarsh arafkarsh
    Pact Definition
    72
    Provider Name
    Consumer Name
    Contract Definition
    • @PactTestFor : Provider
    • @Pact : Consumer
    • Building Request /
    Response Pact

    View Slide

  73. @arafkarsh arafkarsh
    Pact Definition
    73
    Consumer Name
    Contract Definition
    • @PactTestFor : Provider
    • @Pact : Consumer
    • Building Request /
    Response Pact
    • Running Consumer Pact
    Test

    View Slide

  74. @arafkarsh arafkarsh
    Pact Contract JSON
    74
    1. Contract Defines the
    Provider and Consumer
    2. N number of Interactions
    can be defined under a
    single Contract
    3. Interaction Defines
    Request, Response,
    Provider States, Rules etc.
    4. Pact Specs v3.0

    View Slide

  75. @arafkarsh arafkarsh
    Pact : When to use?
    75
    ü Development of Consumer / Provider is
    controlled by your team/department/org.
    ü No. of Consumers are small for a given
    Provider
    ü Consumer and Provider are under active
    development.
    ü Consumer Driven Contract – Provider
    features are driven by Consumer.
    ü Provider team can easily control the data
    in the response.
    Pact is Good for When
    Source: https://docs.pact.io/getting_started/what_is_pact_good_for
    ü Both teams (Consumer & Provider)
    don’t use Pact.
    ü When the Consumers can’t be
    identified (Public APIs)
    ü Functional / Behavior Testing of the
    Provider
    ü Functionality is Driven by the
    Provider.
    ü Performance and Load Testing
    ü You can’t control the Response Data.
    Pact is NOT Good When

    View Slide

  76. @arafkarsh arafkarsh
    Comparison – Mockito / Pact
    76
    # Feature Mockito WireMock Pact
    TEST SCOPE >>> API Wire Inter Service
    1 Contract Testing Yes Yes Yes
    2 Behavior / Functional Testing Yes
    3 Test Double (Mock Provider) Yes
    4
    Consumer / Provider Testing using Shared
    Contract
    Yes
    5 Mock System (For Consumer / Provider) Yes Yes
    6 Multi Protocol Support (HTTP, Messaging) HTTP Yes
    7 Centralized Contract Management Yes
    8 API Documentation and Version Management Yes
    9 Record and Playback Yes Yes
    10 Supports JSON/XML Yes Yes

    View Slide

  77. @arafkarsh arafkarsh
    Microservices Testing Scenarios / Tools
    77
    Testing Tools
    Contract Testing Scope
    Integration Testing
    Verifies the communication
    paths and interactions between
    components to detect interface
    defects
    Contract Testing
    It is a test at the boundary of an
    external service verifying that it
    meets the contract expected by a
    consuming service.
    Payment Mock
    Integration Contract Testing Scope
    Test Double
    Montebank
    Cart
    Component Testing
    Unit
    Testing
    Integration Testing Scope
    Order
    REST / HTTP or
    Events / Kafka
    Item ID,
    Quantity,
    Address..
    Mock Order
    Component Testing
    A component test limits the
    scope of the exercised
    software to a portion of the
    system under test.
    Order
    Payment
    Unit
    Testing
    Firewall
    Integration Testing Scope
    REST / HTTP
    Payment
    Sandbox
    Component
    Testing
    U

    View Slide

  78. @arafkarsh arafkarsh
    Microservices Testing Strategies
    78
    E2E
    Testing
    Integration
    Testing
    Contract Testing
    Component Testing
    Unit Testing
    Number of Tests
    Speed
    Cost
    Time
    Mike Cohen’s Testing Pyramid
    Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html
    75%
    25%
    0%
    Ubiquitous
    Language
    Domain
    Expert
    Analyst Developers
    QA
    Design
    Docs
    Test Cases
    Code
    Architect

    View Slide

  79. @arafkarsh arafkarsh
    Chaos Engineering – Load / Stress / Performance
    79
    Chaos Monkey Randomly disables production instances
    Chaos Kong
    Similar to Chaos Monkey, simulates an outage of an
    entire Amazon availability zone.
    Doctor Monkey
    Checks CPU load, Memory usage and removes it
    from network if the health is bad.
    Janitor Monkey Search for unused resources and disposes them.
    Compliance Monkey
    Finds instances that don’t adhere to best-practices
    and shuts them down.
    Latency Monkey Induces Artificial delays
    Security Monkey
    Is an extension of Compliance Monkey. Find security
    vulnerabilities and terminates offending instances.
    Source: https://github.com/Netflix/SimianArmy/wiki
    Source: http://principlesofchaos.org/

    View Slide

  80. @arafkarsh arafkarsh
    Testing Strategy Summary
    80
    1. Unit Testing
    A unit test exercises the smallest piece of testable software.
    2. Component Testing
    A component test limits the scope of the exercised software to a portion of the system
    under test.
    3. Contract Testing
    It is a test at the boundary of an external service verifying that it meets the contract
    expected by a consuming service
    4. Integration Testing
    It verifies the communication paths and interactions between components to detect
    interface defects.

    View Slide

  81. @arafkarsh arafkarsh 81
    100s Microservices
    1,000s Releases / Day
    10,000s Virtual Machines
    100K+ User actions / Second
    81 M Customers Globally
    1 B Time series Metrics
    10 B Hours of video streaming
    every quarter
    Source: NetFlix: : https://www.youtube.com/watch?v=UTKIT6STSVM
    10s OPs Engineers
    0 NOC
    0 Data Centers
    So what do NetFlix think about DevOps?
    No DevOps
    Don’t do lot of Process / Procedures
    Freedom for Developers & be Accountable
    Trust people you Hire
    No Controls / Silos / Walls / Fences
    Ownership – You Build it, You Run it.

    View Slide

  82. @arafkarsh arafkarsh 82
    Design Patterns are
    solutions to general
    problems that
    software developers
    faced during software
    development.
    Design Patterns

    View Slide

  83. @arafkarsh arafkarsh 83
    DREAM | AUTOMATE | EMPOWER
    Araf Karsh Hamid :
    India: +91.999.545.8627
    http://www.slideshare.net/arafkarsh
    https://www.linkedin.com/in/arafkarsh/
    https://www.youtube.com/user/arafkarsh/playlists
    http://www.arafkarsh.com/
    @arafkarsh
    arafkarsh

    View Slide

  84. @arafkarsh arafkarsh 84
    Source Code: https://github.com/MetaArivu Web Site: https://metarivu.com/ https://pyxida.cloud/

    View Slide

  85. @arafkarsh arafkarsh 85
    http://www.slideshare.net/arafkarsh

    View Slide

  86. @arafkarsh arafkarsh
    References
    86
    1. July 15, 2015 – Agile is Dead : GoTo 2015 By Dave Thomas
    2. Apr 7, 2016 - Agile Project Management with Kanban | Eric Brechner | Talks at Google
    3. Sep 27, 2017 - Scrum vs Kanban - Two Agile Teams Go Head-to-Head
    4. Feb 17, 2019 - Lean vs Agile vs Design Thinking
    5. Dec 17, 2020 - Scrum vs Kanban | Differences & Similarities Between Scrum & Kanban
    6. Feb 24, 2021 - Agile Methodology Tutorial for Beginners | Jira Tutorial | Agile Methodology Explained.
    Agile Methodologies

    View Slide

  87. @arafkarsh arafkarsh
    References
    87
    1. Vmware: What is Cloud Architecture?
    2. Redhat: What is Cloud Architecture?
    3. Cloud Computing Architecture
    4. Cloud Adoption Essentials:
    5. Google: Hybrid and Multi Cloud
    6. IBM: Hybrid Cloud Architecture Intro
    7. IBM: Hybrid Cloud Architecture: Part 1
    8. IBM: Hybrid Cloud Architecture: Part 2
    9. Cloud Computing Basics: IaaS, PaaS, SaaS
    1. IBM: IaaS Explained
    2. IBM: PaaS Explained
    3. IBM: SaaS Explained
    4. IBM: FaaS Explained
    5. IBM: What is Hypervisor?
    Cloud Architecture

    View Slide

  88. @arafkarsh arafkarsh
    References
    88
    Microservices
    1. Microservices Definition by Martin Fowler
    2. When to use Microservices By Martin Fowler
    3. GoTo: Sep 3, 2020: When to use Microservices By Martin Fowler
    4. GoTo: Feb 26, 2020: Monolith Decomposition Pattern
    5. Thought Works: Microservices in a Nutshell
    6. Microservices Prerequisites
    7. What do you mean by Event Driven?
    8. Understanding Event Driven Design Patterns for Microservices

    View Slide

  89. @arafkarsh arafkarsh
    References – Microservices – Videos
    89
    1. Martin Fowler – Micro Services : https://www.youtube.com/watch?v=2yko4TbC8cI&feature=youtu.be&t=15m53s
    2. GOTO 2016 – Microservices at NetFlix Scale: Principles, Tradeoffs & Lessons Learned. By R Meshenberg
    3. Mastering Chaos – A NetFlix Guide to Microservices. By Josh Evans
    4. GOTO 2015 – Challenges Implementing Micro Services By Fred George
    5. GOTO 2016 – From Monolith to Microservices at Zalando. By Rodrigue Scaefer
    6. GOTO 2015 – Microservices @ Spotify. By Kevin Goldsmith
    7. Modelling Microservices @ Spotify : https://www.youtube.com/watch?v=7XDA044tl8k
    8. GOTO 2015 – DDD & Microservices: At last, Some Boundaries By Eric Evans
    9. GOTO 2016 – What I wish I had known before Scaling Uber to 1000 Services. By Matt Ranney
    10. DDD Europe – Tackling Complexity in the Heart of Software By Eric Evans, April 11, 2016
    11. AWS re:Invent 2016 – From Monolithic to Microservices: Evolving Architecture Patterns. By Emerson L, Gilt D. Chiles
    12. AWS 2017 – An overview of designing Microservices based Applications on AWS. By Peter Dalbhanjan
    13. GOTO Jun, 2017 – Effective Microservices in a Data Centric World. By Randy Shoup.
    14. GOTO July, 2017 – The Seven (more) Deadly Sins of Microservices. By Daniel Bryant
    15. Sept, 2017 – Airbnb, From Monolith to Microservices: How to scale your Architecture. By Melanie Cubula
    16. GOTO Sept, 2017 – Rethinking Microservices with Stateful Streams. By Ben Stopford.
    17. GOTO 2017 – Microservices without Servers. By Glynn Bird.

    View Slide

  90. @arafkarsh arafkarsh
    References
    90
    Domain Driven Design
    1. Oct 27, 2012 What I have learned about DDD Since the book. By Eric Evans
    2. Mar 19, 2013 Domain Driven Design By Eric Evans
    3. Jun 02, 2015 Applied DDD in Java EE 7 and Open Source World
    4. Aug 23, 2016 Domain Driven Design the Good Parts By Jimmy Bogard
    5. Sep 22, 2016 GOTO 2015 – DDD & REST Domain Driven API’s for the Web. By Oliver Gierke
    6. Jan 24, 2017 Spring Developer – Developing Micro Services with Aggregates. By Chris Richardson
    7. May 17. 2017 DEVOXX – The Art of Discovering Bounded Contexts. By Nick Tune
    8. Dec 21, 2019 What is DDD - Eric Evans - DDD Europe 2019. By Eric Evans
    9. Oct 2, 2020 - Bounded Contexts - Eric Evans - DDD Europe 2020. By. Eric Evans
    10. Oct 2, 2020 - DDD By Example - Paul Rayner - DDD Europe 2020. By Paul Rayner

    View Slide

  91. @arafkarsh arafkarsh
    References
    91
    Event Sourcing and CQRS
    1. IBM: Event Driven Architecture – Mar 21, 2021
    2. Martin Fowler: Event Driven Architecture – GOTO 2017
    3. Greg Young: A Decade of DDD, Event Sourcing & CQRS – April 11, 2016
    4. Nov 13, 2014 GOTO 2014 – Event Sourcing. By Greg Young
    5. Mar 22, 2016 Building Micro Services with Event Sourcing and CQRS
    6. Apr 15, 2016 YOW! Nights – Event Sourcing. By Martin Fowler
    7. May 08, 2017 When Micro Services Meet Event Sourcing. By Vinicius Gomes

    View Slide

  92. @arafkarsh arafkarsh
    References
    92
    Kafka
    1. Understanding Kafka
    2. Understanding RabbitMQ
    3. IBM: Apache Kafka – Sept 18, 2020
    4. Confluent: Apache Kafka Fundamentals – April 25, 2020
    5. Confluent: How Kafka Works – Aug 25, 2020
    6. Confluent: How to integrate Kafka into your environment – Aug 25, 2020
    7. Kafka Streams – Sept 4, 2021
    8. Kafka: Processing Streaming Data with KSQL – Jul 16, 2018
    9. Kafka: Processing Streaming Data with KSQL – Nov 28, 2019

    View Slide

  93. @arafkarsh arafkarsh
    References
    93
    Databases: Big Data / Cloud Databases
    1. Google: How to Choose the right database?
    2. AWS: Choosing the right Database
    3. IBM: NoSQL Vs. SQL
    4. A Guide to NoSQL Databases
    5. How does NoSQL Databases Work?
    6. What is Better? SQL or NoSQL?
    7. What is DBaaS?
    8. NoSQL Concepts
    9. Key Value Databases
    10. Document Databases
    11. Jun 29, 2012 – Google I/O 2012 - SQL vs NoSQL: Battle of the Backends
    12. Feb 19, 2013 - Introduction to NoSQL • Martin Fowler • GOTO 2012
    13. Jul 25, 2018 - SQL vs NoSQL or MySQL vs MongoDB
    14. Oct 30, 2020 - Column vs Row Oriented Databases Explained
    15. Dec 9, 2020 - How do NoSQL databases work? Simply Explained!
    1. Graph Databases
    2. Column Databases
    3. Row Vs. Column Oriented Databases
    4. Database Indexing Explained
    5. MongoDB Indexing
    6. AWS: DynamoDB Global Indexing
    7. AWS: DynamoDB Local Indexing
    8. Google Cloud Spanner
    9. AWS: DynamoDB Design Patterns
    10. Cloud Provider Database Comparisons
    11. CockroachDB: When to use a Cloud DB?

    View Slide

  94. @arafkarsh arafkarsh
    References
    94
    Docker / Kubernetes / Istio
    1. IBM: Virtual Machines and Containers
    2. IBM: What is a Hypervisor?
    3. IBM: Docker Vs. Kubernetes
    4. IBM: Containerization Explained
    5. IBM: Kubernetes Explained
    6. IBM: Kubernetes Ingress in 5 Minutes
    7. Microsoft: How Service Mesh works in Kubernetes
    8. IBM: Istio Service Mesh Explained
    9. IBM: Kubernetes and OpenShift
    10. IBM: Kubernetes Operators
    11. 10 Consideration for Kubernetes Deployments
    Istio – Metrics
    1. Istio – Metrics
    2. Monitoring Istio Mesh with Grafana
    3. Visualize your Istio Service Mesh
    4. Security and Monitoring with Istio
    5. Observing Services using Prometheus, Grafana, Kiali
    6. Istio Cookbook: Kiali Recipe
    7. Kubernetes: Open Telemetry
    8. Open Telemetry
    9. How Prometheus works
    10. IBM: Observability vs. Monitoring

    View Slide

  95. @arafkarsh arafkarsh
    References
    95
    1. Feb 6, 2020 – An introduction to TDD
    2. Aug 14, 2019 – Component Software Testing
    3. May 30, 2020 – What is Component Testing?
    4. Apr 23, 2013 – Component Test By Martin Fowler
    5. Jan 12, 2011 – Contract Testing By Martin Fowler
    6. Jan 16, 2018 – Integration Testing By Martin Fowler
    7. Testing Strategies in Microservices Architecture
    8. Practical Test Pyramid By Ham Vocke
    Testing – TDD / BDD

    View Slide

  96. @arafkarsh arafkarsh 96
    1. Simoorg : LinkedIn’s own failure inducer framework. It was designed to be easy to extend and
    most of the important components are plug- gable.
    2. Pumba : A chaos testing and network emulation tool for Docker.
    3. Chaos Lemur : Self-hostable application to randomly destroy virtual machines in a BOSH-
    managed environment, as an aid to resilience testing of high-availability systems.
    4. Chaos Lambda : Randomly terminate AWS ASG instances during business hours.
    5. Blockade : Docker-based utility for testing network failures and partitions in distributed
    applications.
    6. Chaos-http-proxy : Introduces failures into HTTP requests via a proxy server.
    7. Monkey-ops : Monkey-Ops is a simple service implemented in Go, which is deployed into an
    OpenShift V3.X and generates some chaos within it. Monkey-Ops seeks some OpenShift
    components like Pods or Deployment Configs and randomly terminates them.
    8. Chaos Dingo : Chaos Dingo currently supports performing operations on Azure VMs and VMSS
    deployed to an Azure Resource Manager-based resource group.
    9. Tugbot : Testing in Production (TiP) framework for Docker.
    Testing tools

    View Slide

  97. @arafkarsh arafkarsh
    References
    97
    CI / CD
    1. What is Continuous Integration?
    2. What is Continuous Delivery?
    3. CI / CD Pipeline
    4. What is CI / CD Pipeline?
    5. CI / CD Explained
    6. CI / CD Pipeline using Java Example Part 1
    7. CI / CD Pipeline using Ansible Part 2
    8. Declarative Pipeline vs Scripted Pipeline
    9. Complete Jenkins Pipeline Tutorial
    10. Common Pipeline Mistakes
    11. CI / CD for a Docker Application

    View Slide

  98. @arafkarsh arafkarsh
    References
    98
    DevOps
    1. IBM: What is DevOps?
    2. IBM: Cloud Native DevOps Explained
    3. IBM: Application Transformation
    4. IBM: Virtualization Explained
    5. What is DevOps? Easy Way
    6. DevOps?! How to become a DevOps Engineer???
    7. Amazon: https://www.youtube.com/watch?v=mBU3AJ3j1rg
    8. NetFlix: https://www.youtube.com/watch?v=UTKIT6STSVM
    9. DevOps and SRE: https://www.youtube.com/watch?v=uTEL8Ff1Zvk
    10. SLI, SLO, SLA : https://www.youtube.com/watch?v=tEylFyxbDLE
    11. DevOps and SRE : Risks and Budgets : https://www.youtube.com/watch?v=y2ILKr8kCJU
    12. SRE @ Google: https://www.youtube.com/watch?v=d2wn_E1jxn4

    View Slide

  99. @arafkarsh arafkarsh
    References
    99
    1. Lewis, James, and Martin Fowler. “Microservices: A Definition of This New Architectural Term”, March 25, 2014.
    2. Miller, Matt. “Innovate or Die: The Rise of Microservices”. e Wall Street Journal, October 5, 2015.
    3. Newman, Sam. Building Microservices. O’Reilly Media, 2015.
    4. Alagarasan, Vijay. “Seven Microservices Anti-patterns”, August 24, 2015.
    5. Cockcroft, Adrian. “State of the Art in Microservices”, December 4, 2014.
    6. Fowler, Martin. “Microservice Prerequisites”, August 28, 2014.
    7. Fowler, Martin. “Microservice Tradeoffs”, July 1, 2015.
    8. Humble, Jez. “Four Principles of Low-Risk Software Release”, February 16, 2012.
    9. Zuul Edge Server, Ketan Gote, May 22, 2017
    10. Ribbon, Hysterix using Spring Feign, Ketan Gote, May 22, 2017
    11. Eureka Server with Spring Cloud, Ketan Gote, May 22, 2017
    12. Apache Kafka, A Distributed Streaming Platform, Ketan Gote, May 20, 2017
    13. Functional Reactive Programming, Araf Karsh Hamid, August 7, 2016
    14. Enterprise Software Architectures, Araf Karsh Hamid, July 30, 2016
    15. Docker and Linux Containers, Araf Karsh Hamid, April 28, 2015

    View Slide

  100. @arafkarsh arafkarsh
    References
    100
    16. MSDN – Microsoft https://msdn.microsoft.com/en-us/library/dn568103.aspx
    17. Martin Fowler : CQRS – http://martinfowler.com/bliki/CQRS.html
    18. Udi Dahan : CQRS – http://www.udidahan.com/2009/12/09/clarified-cqrs/
    19. Greg Young : CQRS - https://www.youtube.com/watch?v=JHGkaShoyNs
    20. Bertrand Meyer – CQS - http://en.wikipedia.org/wiki/Bertrand_Meyer
    21. CQS : http://en.wikipedia.org/wiki/Command–query_separation
    22. CAP Theorem : http://en.wikipedia.org/wiki/CAP_theorem
    23. CAP Theorem : http://www.julianbrowne.com/article/viewer/brewers-cap-theorem
    24. CAP 12 years how the rules have changed
    25. EBay Scalability Best Practices : http://www.infoq.com/articles/ebay-scalability-best-practices
    26. Pat Helland (Amazon) : Life beyond distributed transactions
    27. Stanford University: Rx https://www.youtube.com/watch?v=y9xudo3C1Cw
    28. Princeton University: SAGAS (1987) Hector Garcia Molina / Kenneth Salem
    29. Rx Observable : https://dzone.com/articles/using-rx-java-observable

    View Slide