Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About us Olga Maciaszek-Sharma Software Engineer, Spring Cloud Team, Spring Project Twitter: @olga_maciaszek
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About us Eddú Meléndez Software Engineer and Open Source Contributor Twitter: @EdduMelendez
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Software Architecture Evolution
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Software Architecture Evolution - Monolith Browser Application Web Service
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Software Architecture Evolution - Microservices Consumer 1 API Gateway Service 2 Service 3 Service 1 Consumer 2
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ "Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations." — M. Conway
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What we need to solve before doing microservices? • Deployment • APIs • Contracts • Testing • Service Discovery • Health Checking • Configuration • Circuit Breaking • Tracing • Logging • Monitoring • ….
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What we need to solve before doing microservices? • Deployment • APIs • Contracts • Testing • Service Discovery • Health Checking • Configuration • Circuit Breaking • Tracing • Logging • Monitoring • ….
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Pain points during development • Unstable development environment ◦ Service not available • Downtime during deployments • Data is not available • Finding bugs during functional tests
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Test Pyramid 14 Source: https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1 5  Fully Deployed Test Environment Environment per Service One To Rule Them All
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1 7  Failsafe vs. Safe To Fail
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1 9  Stubbed Environments
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Invalid Stubs - Messaging 21 topic: foo class Product { int productId String productName } topic: bar class Product { int productId String productName } topic: foo class Product { int id String productName }
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Terminology • Producer • Consumer • Contract
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud Contract Benefits From Producer side: • Nice DSL to define contracts • Generate Stubs • Generate tests against defined contracts
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud Contract Benefits From Consumer side: • Validation against Contracts • Run stubs generated thanks to StubRunner
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Test using MockRestServiceServer 2 7 @RestClientTest public class MockServerTests { @Autowired private MockRestServiceServer server; @Test public void shouldReturnAllItems() { this.server.expect(requestTo(...uri...)) .andResponse(withSuccess(...body..., ...media type...)); } … }
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Test using WireMock 2 8 @AutoConfigureWireMock public class WireMockTests { @Test public void shouldReturnAllItems() { stub.get(urlEqualTo(...uri...)) .willReturn(aResponse() .withHeader(...key..., ...value...) .withBody(...body...))); } … }
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ATDD & Backwards Compatible APIs
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Backwards Compatibility Check 3 2
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Current Status - 2.0.1-RELEASE • Supports Messaging (Integration, Stream, RabbitMQ, Kafka) • Works with MockMvc • Works with RestDocs • Support for Maven and Gradle • Provides StubRunner • JUnit Rules • Pact Support
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is coming? - 2.1.0 • JUnit 5 extension for Spring Cloud Contract - Issue 691 • WebTestClient support (WebFlux support) - Issue 422 Link: https://bit.ly/2O0HSHc