A study of Free monads and their applications in testing service orchestration, with a Star Trek theme.
sbt test in the root directory. Note that the test execution may be slow due to a problem with Java on macOS Sierra.
The motivation for this exercise is in two observations —
But, let's dive in to the scenario and see how this works in practise!
James T. Kirk has a problem. The USS Enterprise has recently been fitted with a new multitronic computer, and while her subsystems are tried and true, the Captain is concerned whether the new computer will correctly coordinate those systems.
After all, each expedition into space can feature a number of potentially dangerous encounters! Not only that, but the computer needs to keep track of the remaining dilithium and coordinate warp speed accordingly.
We have been given a spec of the Enterprise's systems by Montgomery Scott, found in the
trek-domain project. Now, we only need to write a highly testable system that will satisfy the intrepid Captain!
Since Functional Programming is clearly the way of the future, and we're already in the 24th century in Star Trek, we'll make use of Free monads. It must be a good choice, since it already sounds like something from the Star Trek universe!
We could use mocks and spies for the testing, but let's face it — the Captain doesn't like spies on his starship. Keeping mocks up-to-date is also tedious and error-prone.
Encoding the logic operations in Free reifies the logic as data. This data can then be conveniently tested against known fixtures.
There are two implementations:
trek-catsA Cats-based manual Free encoding layered under a monadic planning façade
trek-freesFreestyle based implementation with a
Let's take a look at the manual to see how the Enterprise's systems operate.
Note! Before attempting to operate your Constitution-class starship, you must first turn the crank shaft to start the ignition!
The heart of the ship, producing the energy for the other systems.
The warp-capable drives that propel the starship in the vast void of space.
Powerful directed-energy beam weapons that operate on various frequencies.
Highly polarized energetic distortion field emitters that protect the starship.