walmartlabs/mupd8 — pull request #20 by zheguang (2013-04-28 04:24:37+00:00)
Title: SourceReader: add unit tests and re-org the code to meet new requirements

This patch introduces the set of requirements to JOSNSourceReader and general source reader:

- hasNext() should return true when there's next item in the source
- hasNext() should not consume items from the source
- hasNext() should return false when there's no item in the source
- hasNext() should not block forever (???)
- getNextDataPair() should return the next item in the source
- getNextDataPair() should throw NoSuchElementException if no next item

The new unit test coverage is added to set the bar. The interface (i.e. Mupd8Source) as well as implementation (i.e. JSONSource) are modified to meet the new requirements.

Note that the previous JSONSource didn't implement the canonical hasNext() and getNext() as listed above. This is fixed in this patch.

I've also refactored the JSONSource to favor Scala Idioms and slightly increase branch efficiency. Now it should be more readable.

However, the JSONSource seems to very tightly coupled with the actual source objects, such as TCP sockets, local files, etc. More work on the decoupling design is going to be next step.