Wipe Cassandra DB between tests (Rspec)

I am running rspec tests which include data in db Cassandra. What is the best practice here for cleaning / cleaning db between tests? For my mongo data, I am using DatabaseCleaner and looking for the equivalent of Cassandra. I am doing the following in my spec_helper.rb right now, but it is very slow, so I 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 
+4
source share
2 answers

An old question, but I found a useful meaning for it, maybe this will help someone else too (I use the 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 
+3
source

Try trimming, disabling autoSnapshot in cassandra.yaml and disabling durable_writes in your key space.

Truncation used to be quite slow, but this has been fixed since 1.1.1: https://issues.apache.org/jira/browse/CASSANDRA-4153

+1
source

Source: https://habr.com/ru/post/1437880/


All Articles