Skip to content

A REST based Spring free microservice for asynchronous calculation of Collatz series terms. Demonstrates dependency injection using the Java class loader and a mix of Java and Kotlin in a single Gradle build. Uses an ORM free and type safe database access with jOOQ. Postgres and flyway for DB version management

Notifications You must be signed in to change notification settings

martin-scheelke/collatz

Repository files navigation

Collatz REST API

by Martin Scheelke

   

A very simple REST API/microservice for asynchronous calculation of Collatz series terms - see Collatz Conjecture. The interface returns immediately when it receives an instruction to calculate a Collatz term. The result can then be retrieved by polling the interface.

This project demonstrates the following ideas:

  • Spark Java - a lightweight, drop-in HTTP server.
  • SOLID programming principles.
  • Dependency injection without using a framework such as Spring.
  • Kotlin's tail recursion optimisation - Java and Kotlin are combined in single Gradle project.
  • Simple CI/CD with Docker and CircleCI.
  • Gson for JSON handling.
  • Test Driven Development.
  • RESTAssured for declarative, JUnit driven REST interface tests.
  • Mocking with the Mockito framework

Install and Test Instructions

   

Clone

Clone this repo to your local machine:

https://github.com/martin-scheelke/collatz.git

 

Setup

  • Install the gradle wrapper:
gradle wrapper --gradle-version 6.3

 

Run unit and integration tests with non-thread-safe data store access:

 

  • Edit the properties file at ./collatz/src/main/resources/.properties:
  • Specify the DAO class: Set collatz.data.CollatzDAOImpl
 gradlew clean test --info

 

Run unit and integration tests with thread-safe data store:

 

  • Edit the properties file at ./collatz/src/main/resources/.properties
  • Specify the DAO class: Set collatz.data.ConcurrentCollatzDAOImpl
 gradlew clean test --info

 

Test outputs can be found at ../collatz/build/reports/tests/test/index.html

 

Manually test the REST API

Start the REST service:

gradlew runREST

Example tests with curl:

curl -X PUT http://localhost:4567/collatz/323
curl -X GET http://localhost:4567/collatz/323
curl -X GET http://localhost:4567/collatz
curl -X DELETE http://localhost:4567/collatz/323
curl -X DELETE http://localhost:4567/collatz

 

CircleCi integration

For CI/CT integration with CircleCi - build and test in a docker image - see:   https://app.circleci.com/pipelines/github/martin-scheelke/collatz

 

Code Style

About

A REST based Spring free microservice for asynchronous calculation of Collatz series terms. Demonstrates dependency injection using the Java class loader and a mix of Java and Kotlin in a single Gradle build. Uses an ORM free and type safe database access with jOOQ. Postgres and flyway for DB version management

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published