[devnexus 2022] what’s new in spring 2022

Speaker: Spencer Gibb

Twitter: @spencerbgibb

Link to table of contents

———————

History

  • Spring 1 came out in 2004. Spring 5 came out in 2017 – included Java 8/11/17
  • Spring Boot 1 released 2014 with Java 6 baseline. Spring Boot 2 released 2018 with Java 8 (baseline)/11/17. Now has 6 month release cycle to match Java
  • Spring Cloud – launched 2015. last release in 2020. Started with wors *Angle, Brixton, etc). Switched to # release versions (2020)
  • Josh Long’s favorite place on the internet is prod. Secon favorite is start.spring.io.

Spring 6

  • corresponding libraries have version as well. e: Spring security, data
  • Spring Boot 3 and Spring Cloud 2022.0. go with Spring 6
  • Go to Spring Initializr (start.spring.io) if not sure what goes together

Java 17

  • Baseline Java 17. Must hava Java17+ to run
  • Will have compatability wihth Java 18, 19, etc

Jakarta EE 9

  • Package renaming (javax -> jakarta)
  • Tomcat 10/Jetty 11/Undertow 2.2
  • JPA3 3 (Hibernate 6)

Native

  • GraalVM compiles to native
  • Faster startup, less memory usage
  • Spring Native was an exeperimental project. AOT metadata processing moves to Spring Framework. Built time pugins move to Spring Boot. Type and resoures hints move to relevant projects
  • Native pros – serverless, cost via lower resource consumption, CLI
  • Native cons – less mature, no JIT

Observablity

  • Introuced with Sleuth. 2021.0 will be last Sleuth release
  • Now Micrometer tracing
  • new Observation API
  • Instrumentation moving to relevant projects
  • Micrometer staying as Java 8 baseline

Declarative Clients

  • Feign was part of spring-cloud-netflix and open sourced Now spring-cloud-openfeign
  • Declarative blocking web service client
  • Now in Spring framework
  • Will add for GraphQL and RSocket (reactive sockets)

General

  • API testing tool: https://httpie.io
  • thenounproject.com – good collection of free stock art
  • Logger creates a lazy version so doesn’t interpolate strings unless needed. Also, a supplier verson
  • AutoConfiguration annotation to replace Configuration annotation
  • Problem details – standard json format for error messages. Content type application/problem+json
  • Removing a bunch of stuff. One is Freemarker JSP whch I didn’t know existed
  • OSS Spring 5 supported until 2024

My take

Excellent outline making the content easy to remember. Which is good because there was a lot of infomration! The live coding was good for seeing the code based changes and also breaking up the information. I liked seing the ”upgrade” with the jakarta package names and the micrometer example

[devnexus 2022] batch processing in action

Speaker: Hillmer Chona & Rodrigo Graciano

Twitter @HillmerCh and @RodgrigoGraciano

Link to table of contents

———————

Anotations vs XML

  • @EnableBatchProcessing automatically provides beans for job repo, job launcher, etc
  • If use XML, need to create all beans yourself
  • Don’t mix and match XML vs annotations. Could wind up with two of a bean

Concepts

  • Steps – one reader/writer
  • Job repository – provided by framework
  • async doesnt block – JobLauncher vs AsyncJobLauncher
  • Can run at the comand line or in web container
  • Processors – transform, filter, validate
  • Chunk – collect data and sent data on when chunk complete
  • Many types of readers, and writers built in. Can also write own
  • Listeners run before/after job
  • Step listeners are more detailed
  • Fault tolerance – skip exceptions
  • Retries

Flows

  • Conditional – exit status, run different step on success/fail.
  • Decider – can have custom logic, not just exit status ex: day of week)
  • Split – run steps in paralelel

Live demo

  • Heavy use of chaining
  • Yay! Records
  • JobExecutionListener has two methdods beforeJob() and afterJob(). Alternatively, an put logic in parent job

My take

The keynote ran late and I didn’t make it in tie for the beginning. Luckily, I saw Rodrigo do a practice run so was able to jump in. Lots of information and presentation well designed for explaining concepts

automated testing for digital experiences using junit 5 – live blogging from spring days

Automated Testing for Digital Experiences Using JUnit 5
Speaker: Justin Baumgartner
See list of all blog posts from conference

General

  • Asked how many use JUnit 4. Almost everyone. [didn’t ask about TestNG, but did cite most used framework in general]
  • JUnit 4 is ten years old
  • “It’s all about the tests” – TDD/CI/CD – create. more importance on tests

Gaps in JUnit 4

  • Tight coupling between the APIs we use to write tests and the ones build tools use. Separating the jars lets progress at different speeds
  • Built on Java 5. Can’t use lambdas [aside from a tiny bit in assertj]
  • Runner restrictions – can only have one
  • Rules aren’t flexible enough

JUnit 5

  • Release in early fall
  • New architecture: JUnit platform (for build tools and IDEs to discover and execute tests), JUnit Jupiter (for writing tests), JUnit Vintage (to run legacy tests)
  • Potential for Cucumber or Spock runner so can run all tests in one place
  • Extension model: Can hook into life cycle callbacks. Used instead of runners/rules. An extension point is an interface. Example BeforeEachCallback. Need to be stateless; get TestExtensionContext as parameter. Can implement multiple callback if want called multiple times and store state in getStore(context).
  • Can pass parameters into test methods using @ExtendWith(xxx.class) so narrow scope. Implement ParameterResolver to create the object you want to mock.
  • Dynamic tests: create tests at runtime. Not expected to use often. @TestFactory and then create tests as lambdas. Each dynamicTest in list is an actual test (vs run in a loop
  • @ParmeterizedTest and @ValueSources – hard code parameters, read from file. [need to look at how to run “legacy” style parameterized test – answer – there’s. a @MethodSource where you can havve any logic]
  • RepeatedTest(x) – to run test a bunch of times
  • @Disabled – can disable class or test. Appear in report but not run. (unlike @Ignore where don’t appear in report at all)
  • @DisplayName so can print clearer name than test name
  • @Tag – replaces @Category – to grou/filter tests
  • assertAll() – new assertion – facilitates grouping of assertions

Said backward compatible. But not all runners/rules are in Jupiter. So would have to use Vintage test engine to use those or port. Jupiter has different packages for annotations/assertions so can mix within class. So if using Jupiter engine, still can use “old” asserts until change imports.

Nice ending presentation. I’m really excited about JUnit 5!