Skip to content

virantha/platform_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

platform_test

Author: Virantha Ekanayake

Demo

Please use the following URL to access the REST endpoint for "sending" a message:

http://techvectors.com:8080/message/route

The endpoint satisfies a POST request with the specified schema. If the POST request is valid, it will return a JSON object ("Content-Type", "application/json") in the specified format. Otherwise, it will return a HTTP error code along with the error message.

Error-checking

The following conditions will trigger an error response:

  • JSON not matching schema
  • Blank message
  • Empty recipients list
  • Recipients list larger than 5000
  • Any recipient that is not 10 digits

Source

The source is written in Go:

Github

Go source files:

If you want to run the actual source, please clone the repository, install the Gorilla mux package, and run:

cd go/src/github.com/virantha
go run server.go errors.go

I used a Python test script (based on Py.test) for automating the testing of the REST API. I thought this would be easier to use for testing than curl scripts. If needed, I also added in a utility function that outputs the equivalent curl in curl.txt (available in the repository). This script tests to make sure proper errors are returned in case of malformed input, as well as ensuring that several test cases are properly processed. It uses the third-party Requests library.

Answers to questions

a. Complexity

Each request is processed in O(n) time where n is the number of recipients. If the category count (m) starts becoming large, then it will be O(nm)

The linear time comes from having to traverse through each recipient to validate a proper phone number. Plus, of course, there's the underlying JSON parsing and assembling of the routed JSON, that is also linear time.

The actually routing is pretty efficient, as it relies mainly on looping through the throughput categories.

Yes, it's possible to optimally solve this problem in polynomial time. With other throughput values, it may not be possible to find an optimal solution. For instance, if you did not have the single message relay, then you could not optimally route any message that was not a multiple of 5. In general, you would need your recipient count to be an integer multiple of at least one of the throughput values.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages