This project is a submission for the Peloton quiz. It interfaces with the Peloton API to retrieve sequences of increasing integers from named streams. It provides an HTTP endpoint that, when given the name of two integer streams, will retrieve values from each and merge them together, maintaining increasing order.
The project is implemented using the new ASP.net 5 framework, which was put into release candidate at the Microsoft Build conference on April 29, 2015. This framework was selected so that the author could use this opportunity to experiment with the new technology. The code is organized into three projects.
The StreamMerge project is the ASP.net web application that hosts the HTTP endpoint. It has one controller, QuizController
, that handles incoming HTTP requests. The controller uses attribute based routing to map the path, /quiz/merge
, to the Merge
action on QuizController
. Its Startup
class is responsible for initializing the ASP.net MVC 6 framework and configuring dependency injection.
The StreamMerge.App project is a class library that contains the core implementation for issuing HTTP request to the target API and merging streams. It is separate from the web application project so that its logic could be distributed separately, such as in console apps, desktop apps, XBox apps... whatever. Most of its implementing types are internal
to the assembly, leaving only the business logic contract, IStreamRepository
, and its return objects as public
to consumers.
The StreamMerge.App.Tests project is responsible for unit testing components in StreamMerge.App. As a separate project, it is not deployed to the web server when StreamMerge is published. The project has one high-level smoke test: StreamRepositoryTests
. This test simply verifies that successive calls to StreamRepository
invokes the internal IStreamClient
and merges the results, returning them in increasing order. It has a fake implementation of IStreamClient
to avoid issuing real HTTP requests against the target API during the evaluation of the test.
The code is laid out using C# style and conventions. It uses C# features like async
/await
to issue non-blocking out-of-process I/O. Feel free to ask about any C# peculiar details.
ASP.net 5 can target the newly open sourced CoreCLR. CoreCLR is multi-platform, capable of running on Windows, OS X, or Linux.
The easier way to run this application is using the package hosted on GitHub:
- Install a .NET Execution Environment (DNX).
- Download the packaged application.
- Extract the zip archive.
- Start the application.
- Windows: run
web.cmd
. - Bash: run
web
.
- Windows: run
- Issue GET requests to http://localhost:5000/quiz/merge with the appropriate query string parameters.
To run the application from scratch, one must clone this repository and then setup DNX. Once DNX is installed (either on Windows, OS X, or Linux), one should go through the process of getting the required packages in position and starting the runtime.
- Install a .NET Execution Environment (DNX).
- Clone this repository.
- Change directories to the root of the cloned repository.
- Run
dnu restore
to restore the required packages. - Change directories to .\src\StreamMerge.
- Start the application with the command
dnx . web
on Windows ordnx . kestrel
on OS X/Linux. - Issue GET requests to http://localhost:5000/quiz/merge with the appropriate query string parameters.
Note, I haven't actually tried this on OS X and Linux; your mileage may vary.
Running the unit test project is described here.
No future work is actually planned for this project. However, if there were to be updates, these tasks would be valuable:
- Unit test coverage of corner cases - The test as written now is simply a quick check that streams are merged and state is preserved between invocations. Better test coverage should be added to cover corner cases. For example, what happens when the application is invoked with overlapping stream names? The quiz prompt was vague on this point, so the behavior right now is undefined.
- Configurable target API - The address of the Peloton API is presently hard coded into
StreamClient
. This should instead be driven by configuration files so that one can retarget the application to a different location like a sandbox API instance. This could be implemented using theIConfiguration
contract. - More expressive input contract - The quiz prompt only asked to merge two named streams. The
IStreamRepository
contract, though, is capable of merging any positive number of streams. Extending this capability to consumers of StreamMerge could be valuable.