Forum: Building VoltDB Clients

Post: How to unit test java clients using VoltTableRow?

How to unit test java clients using VoltTableRow?
aweisberg
Feb 5, 2010
Hi Petter,
When we test with VoltTable we usually assemble a VoltTable with the data we want. You can construct VoltTables with your own schema in Java and then call addRow.
We are open to make those methods non-final, or making VoltTable and VoltTableRow interfaces. I am leaning towards making them interfaces.
I am interested in knowing which would work better for you.
Ariel
How to unit test java clients using VoltTableRow?
pmahlen
Nov 16, 2011
Hi,
I'm having some problems with figuring out how to unit test things with VoltTableRow, since that class has some final methods that are hard to mock. The code I wanted to write is something like this:
VoltTableRow row = Mockito.mock(VoltTableRow.class);

when(row.getLong(0)).thenReturn(1L);
when(row.getString(1)).thenReturn("the atom");

assertThat(mapper.mapToEntity(row), equalTo(new Atom(new Id<Atom>(1), "the atom", ImmutableList.<Attribute>of(attribute1, attribute2))));
That is, I have a class that takes a VoltTableRow and maps that to some entity, and I want to make sure that I can pass in a VoltTableRow that will give some well-defined values. Now, this code in particular doesn't work as Mockito doesn't like to override final methods. I also can't subclass VoltTableRow and override the getLong/getString methods as they are final.
Has anybody else run into this problem, and/or is there a standard approach to solve it?
Thanks,
Petter
Interfaces sounds like the
pmahlen
Nov 18, 2011
Hi,
I'm having some problems with figuring out how to unit test things with VoltTableRow, since that class has some final methods that are hard to mock. The code I wanted to write is something like this:
VoltTableRow row = Mockito.mock(VoltTableRow.class);

when(row.getLong(0)).thenReturn(1L);
when(row.getString(1)).thenReturn("the atom");

assertThat(mapper.mapToEntity(row), equalTo(new Atom(new Id<Atom>(1), "the atom", ImmutableList.<Attribute>of(attribute1, attribute2))));
That is, I have a class that takes a VoltTableRow and maps that to some entity, and I want to make sure that I can pass in a VoltTableRow that will give some well-defined values. Now, this code in particular doesn't work as Mockito doesn't like to override final methods. I also can't subclass VoltTableRow and override the getLong/getString methods as they are final.
Has anybody else run into this problem, and/or is there a standard approach to solve it?
Thanks,
Petter


Interfaces sounds like the best approach to me, too. That would give great de-coupling of client code from VoltDB internals.
Thanks,
Petter