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
Clone this repo to your local machine:
https://github.com/martin-scheelke/collatz.git
- Install the gradle wrapper:
gradle wrapper --gradle-version 6.3
- Edit the properties file at ./collatz/src/main/resources/.properties:
- Specify the DAO class: Set collatz.data.CollatzDAOImpl
gradlew clean test --info
- 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
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
For CI/CT integration with CircleCi - build and test in a docker image - see: https://app.circleci.com/pipelines/github/martin-scheelke/collatz
- The Java code style conforms to http://google.github.io/styleguide/