Forum: Building VoltDB Applications

Post: Testing Custom Stored Procedures

Testing Custom Stored Procedures
gideon caller
Nov 19, 2015

I just wrote a somewhat complicated stored procedure and I want to test it.
What I did is extend the stored procedure and override the methods from the VoltProcedure class (specifically voltExecuteSQL and voltQueueSQL), however i'm having some issues mocking VoltTables in the code
I've got 2 questions basically:
1. Is there anyway to mock a VoltTable - it's final so mockito is not an option
2. I was wondering if there's any VoltDB way to create tests for complicated stored procedures

Nov 23, 2015
1. Mocking a VoltTable is something people have asked for and it's something we're looking at how to solve.

2. It is possible to run VoltDB and a VoltDB client in a single process, using the ServerThread class, or even the LocalCluster class.

An example I wrote a while back is here:

Note that ServerThread still assumes there is a catalog jar that contains your VoltDB application, like in pre-5.0 versions of VoltDB.

Updating this code and publishing docs on how to use is on our radar.
gideon caller
Nov 26, 2015
As always thanks for the huge help jhugg :)
I will look at the code and also update if it works for me or if I found another way to do it
gideon caller
Dec 1, 2015
Ok so I got some unit tests working with VoltDB and I figured I should share what I did:

* I extended my custom stored procedure with a class that I have control over and overrided the methods that my stored procedure under test uses (like getTransactionTime, voltQueueSQL, voltExecuteSQL etc). In each of these I return variables that I created. The tough part was to return a VoltTable from my code (since I didn't know how to create it).
* It's possible to create a mock VoltTable. I found a way to do it in the Building a Table Dynamically.
So now basically you have control on what is returned from the mock DB and also of the results that are returned (including a VoltTable)

It can probably also be done with some mocking framework (like Mockito but you still need to create a VoltTable yourself) but it just felt easier doing it on my own
Also, I think it's worth the effort to unittest stored procedures that are more than 2 or 3 lines since I found some bugs that would be really hard to trace otherwise. I'll share more ideas if I discover anything interesting

Mar 6, 2017
Hi @jhugg - with the move away from catalogue jar's, is this still the recommended approach for VDB6.x and VDB7.x? Also, are the docs you mention available?
Mar 7, 2017
There's some example code in this repo here:

You can use

To run VoltDB in a unit test. There are some examples in the repo. Ben Ballard might have a better write up. I will ping him tomorrow.
Mar 7, 2017
We have a wiki article on Using Eclipse to Develop, Unit Test, and Debug VoltDB Stored Procedures and Client Applications here:,-Unit-Test,-and-Debug-VoltDB-Stored-Procedures-and-Client-Applications
Mar 8, 2017
Thanks John, Ben. Do the instructions on the github wiki work on a Windows machine or is it Linux/Mac only?
Mar 8, 2017
The short answer is no; VoltDB doesn't run on Windows.

I will note VoltDB seems to run fine on recent insider builds of the Windows Subsystem for Linux. I would imagine it will work on the next major non-insider release, the "Creator's Update", which is rumored to be released in April. That said, I'm not sure how easy it will be to run the Eclipse debugger in that environment, but unit tests should work well.