[erlang-questions] Mock Functions

Jay Nelson jay@REDACTED
Wed Sep 6 09:04:40 CEST 2006


Arnaud Bailly wrote:

 > I am implementing a small web application to handle billing of 
customers account.

See my paper from ICFP 2004 at http://www.duomark.com/erlang/ entitled 
"Structured Programming Using Processes 
<http://www.duomark.com/erlang/publications/acm2004.pdf>".

I describe implementing a Quicken-like application.  Processes are used 
in ways that make the code more structured and easier to do things like 
swap out the backend storage or frontend presentations.  The use of 
processes is counter to the typical advice of "one process per real 
world activity", but I give historical background on how one decides to 
subdivide a system and then argue why processes afford a new approach to 
architecting systems.

For the past couple years I've been pondering the currently accepted 
state-of-the-art in data structures and code organization.  The premise 
is, "Given processes are as cheap as structures or objects, would you 
design things differently?".  This year I will present an alternative 
approach for implementing traditional data caches.

It seems that a lot of CS decisions were made in the 60s, like 
databases, structured programming, code sharing, concurrency, etc.  The 
world has changed to where memory is cheap and storage is very fast and 
potentially endless for most problems.  I believe alternate approaches 
are effective now to fundamental tradeoffs made when the costs were very 
different.  The 2004 paper was my first attempt at articulating that 
message.

I am working on a library that would clean up parts of the code from the 
2004 paper dramatically.  With luck it will be available in a couple months.


 > How do I mock out something?

It is not even necessary for you to use processes.  Put your swappable 
functions in a module.  Write a replacement module with all the same 
signatures.  Pass the module name to an initialization function that 
launches a process containing the modules you want to assemble for your 
system test or deployment.

Think of mocked API as the "-behaviour" as you would specify in a 
gen_server implementation module.

Mocking is still useful when you want to simulate time delays (e.g., to 
query a terabyte document index) and other external things that affect 
the code performance or to model an environment that you cannot 
reproduce on your test machines.

jay




More information about the erlang-questions mailing list