With Ruby Client, How to Test for Server Availability or Clear All Data?

Keith Bennett keith.bennett at lmnsolutions.com
Fri Jul 1 09:34:06 EDT 2011

Awesome, Sean!  Thanks!!!

- Keith

On Fri, Jul 1, 2011 at 9:05 AM, Sean Cribbs <sean at basho.com> wrote:
> Keith,
> If this is just testing (e.g. Test::Unit or RSpec), I encourage you to use
> the Riak::TestServer instead (which you can also use from irb if you like).
> It will create a "phantom" node that uses the same code/runtime as your
> existing Riak installation, but exists completely separately and uses an
> in-memory backend so that it is trivial to wipe its data.  The docs for it
> are here (although they could use some
> improvement): http://seancribbs.github.com/ripple/Riak/TestServer.html
> In IRB I might do this to get it started:
> require 'riak/test_server'
> server = Riak::TestServer.new(:bin_dir => "/opt/local/riak/bin", :temp_dir
> => "~/riaktest")
> server.prepare!
> server.start
> Then when you want to wipe the data:
> server.recycle
> If you're using Ripple in a Rails 3 project, `rails generate ripple` will
> generate all of this for you and add it to your chosen testing framework.
> On Thu, Jun 30, 2011 at 6:43 PM, Keith Bennett
> <keith.bennett at lmnsolutions.com> wrote:
>> All -
>> I have some test procedures that require that I start with an empty data
>> store and end with the data exactly as it was before the test.
>> The brute force approach I'm taking now is to:
>> * shut down riak
>> * rename the data/bitcask directory
>> * start riak
>> * run my test and validate the results in riak
>> * shut down riak
>> * move the saved bitcask-xyz dir to bitcask again
>> * start riak
>> As you can see, I *really* want to start with no data, and end with no
>> changes to the existing data.  Of course, if other users were accessing
>> riak, this wouldn't work, but this is a test environment over which I have
>> control.
>> My problem is that it takes a little time after running riak start or stop
>> for the operation to complete, and so I have to insert a sleep afterwards so
>> that the next step in the code is not performed prematurely.  Is there a way
>> using the Ruby Riak client to know for sure whether or not riak is ready for
>> action? I could loop every fraction of a second, or, if there were a
>> blocking call, that would be even better.
>> That said, the shutting down and restarting is pretty drastic action.  Is
>> there a faster/easier/better way to accomplish what I want to do?
>> Thanks,
>> Keith
>> _______________________________________________
>> riak-users mailing list
>> riak-users at lists.basho.com
>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> --
> Sean Cribbs <sean at basho.com>
> Developer Advocate
> Basho Technologies, Inc.
> http://www.basho.com/

More information about the riak-users mailing list