I'm running rspec tests that involve data in a Cassandra db. What is the best practice here for wiping/cleaning the db between tests? For my mongo data, I'm using DatabaseCleaner, and am looking for a Cassandra equivalent. I'm currently doing the following in my spec_helper.rb but it's very slow, so am looking for a better solution. Thanks!
config.before :each do
    ['column1', 'column2'].each do |name|
      begin
        $cassandra.drop_column_family(name)
      rescue
        next
      ensure
        cf = Cassandra::ColumnFamily.new(keyspace: 'db_name', name: name, comparator_type: 'TimeUUIDType')
        $cassandra.add_column_family(cf)
      end
    end
                Old question, but I've found useful gist for it, maybe it will help someone else too (I'm using cequel gem to access Cassandra):
https://gist.github.com/elado/c95a4ffa952809865ee8
# in spec_helper.rb
RSpec.configure do |config|
  records = []
  config.before :suite do
    Cequel::Record.descendants.each do |klass|
      klass.after_create {|r| records << r }
    end
  end
  config.after :each do
    records.each(&:destroy)
    records.clear
  end
  def clean_cequel!
    Cequel::Record.descendants.each { |klass| Cequel::Record.connection.schema.truncate_table(klass.table_name) }
  end
  config.before :suite do
    clean_cequel!
  end
  config.after :suite do
    clean_cequel!
  end
end
                        Try to truncate, disable autoSnapshot in your cassandra.yaml and disable durable_writes on your keyspace.
Truncate used to be quite slow, but this is fixed since 1.1.1: https://issues.apache.org/jira/browse/CASSANDRA-4153
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With