MockStoreClientFactory

22 views
Skip to first unread message

Jason Ko

unread,
Mar 25, 2011, 5:10:11 PM3/25/11
to project-voldemort
I was writing a test case using MockStoreClientFactory and I came
across a problem. It seems that if you have a MockStoreClientFactory,
requesting the same store twice gives you two different stores. I
would expect that calling getStoreClient() with the same name would
give you the same store, or at least the same behavior as the original
store. Is this on purpose?

The reason I ask is because I'm writing a unit test where I'd like to
inspect the behavior of a store, but I don't have access to that
store. I expected that I would be able to get access to the store by
calling getStoreClient() with the same name.

Would it make sense to enhance MockStoreClientFactory to keep a
reference to previously requested stores and return the same store if
the name is being asked again?

public void testTest() throws Exception
{
StoreClient<String, byte[]> s1 =
_updateClientFactory.getStoreClient("asdf");
StoreClient<String, byte[]> s2 =
_updateClientFactory.getStoreClient("asdf");

byte[] value = new byte[] { 1 };
s1.put("a1", value);
byte[] b = s2.getValue("a1"); // <-- returns null
assertTrue(Arrays.equals(value, b)); // <-- fails test case
}

Alex Feinberg

unread,
Mar 25, 2011, 10:17:17 PM3/25/11
to project-...@googlegroups.com
Hey Jason,

It is correctly, currently MockStoreClientFactory creates a new
instance of the in-memory storage engine on each request. The simplest
thing you could do now is to wrap the MockStoreClientFactory with a
CachingStoreClientFactory, which would mean the same store is
returned:

StoreClientFactory scf = new CachingStoreClientFactory(new
MockStoreClientFactory());
StoreClient<String, byte[]> s1 = scf.getStoreClient("asdf");


Thanks,
- Alex

> --
> You received this message because you are subscribed to the Google Groups "project-voldemort" group.
> To post to this group, send email to project-...@googlegroups.com.
> To unsubscribe from this group, send email to project-voldem...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/project-voldemort?hl=en.
>
>

Jason Ko

unread,
Mar 28, 2011, 12:06:57 PM3/28/11
to project-...@googlegroups.com
Thanks Alex, that works. I noticed CachingStoreClientFactory is not in the
javadoc on the voldemort website (
http://project-voldemort.com/javadoc/all/ ). Can it be updated? Thanks.

Jason

Mark Rambacher

unread,
Mar 28, 2011, 10:29:03 PM3/28/11
to project-voldemort
Out of curiosity, why do the StoreClientFactory objects *not* return a
cached StoreClient, rather than creating a new one every time? What
are the advantages to creating a new one every time?

Thanks,

Mark

On Mar 28, 12:06 pm, Jason Ko <j...@linkedin.com> wrote:
> Thanks Alex, that works. I noticed CachingStoreClientFactory is not in the
> javadoc on the voldemort website (http://project-voldemort.com/javadoc/all/). Can it be updated? Thanks.
>
> Jason
Reply all
Reply to author
Forward
0 new messages