1

I am interested in writing unit tests for my map reduce jobs that are intended to run with riak-kv. I am using native Erlang interface (& embedded riak-kv)

Basically I could of course start riak database for the test and put data into it, but that would take some significant amount of time (for unit test) and require some proper configuration of the database

I am interested in some quick mock-server, that could help me

  • Check my map reduce query
  • Check that my map and reduce are conforming
Lol4t0
  • 12,444
  • 4
  • 29
  • 65
  • The mock would need to be quite complex to handle the map-reduce query and how much confidence would you have in your code that it will run on real Riak correctly? I would probably look into ways of speeding up the test when it's using a real Riak database. For example, you could use a virtual machine running Riak with a snapshot taken when all has been set up. Then always restore the same snapshot when the test case starts. On the other hand that could be an overkill for a unit test. Maybe you can break down the test into more simple testable pieces suitable for unit tests? – Greg Mar 22 '16 at 10:21
  • @Amiramix, as I'm using `modfun`s to execute map & reduce steps, I should start database _in place_, remote riak instance would not work because it will lack of `map` & `reduce` implementations. Actually I don't need any storage or distributing features, but again, I want to check that my `query` is correct & my `map` & `reduce` work well with that query. I cannot imagine how I can check it without riak map reduce system itself. I sure can test `map` & `reduce` itself but my view of how that functions should work can differ with real riak - that is want I want to check – Lol4t0 Mar 22 '16 at 16:53
  • Well, couldn't you inject your code into a remote node? Erlang allows you to copy a binary representation of your loaded module to a remote node and load it there. For unit testing it would be probably better to have a simple mockup that doesn't actually run any map-reduce but for integration testing (with common test) I don't see any better option. – Greg Mar 22 '16 at 17:49
  • @Amiramix, well that is quite close to my current view, but I would like to focus on the _simple mockup_ now. I could write some myself, but using someone's else could be more reliable as it would introduce some _cross checking_ – Lol4t0 Mar 22 '16 at 18:31
  • Google found some non-Erlang mocks but I couldn't find any written in Erlang. Even those non-Erlang didn't support more complex functions than just save and get. I see only two options, one is to decompose the query (if possible) to more testable ones (see for example http://stackoverflow.com/questions/754527/best-way-to-test-sql-queries) and the other is to start a project to write such a mock. A real Risk node is the third already discussed option. Good luck :) – Greg Mar 22 '16 at 19:52

0 Answers0