I created my own solution to solve a similar problem. Not only for testing, but also for applying the scripts in the order that changes occur with the circuit over time. He will work under Jenkins or anywhere. There is a class for scrolling through the list of scripts in order, opening each as an input stream. This class then calls the execute () method in this class:
package org.makeyourcase.persistence; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.List; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; import com.datastax.driver.core.exceptions.SyntaxError; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class CqlFileRunner { private static final Logger LOG = Logger.getLogger(CqlFileRunner.class); @Value("${cassandra.node}") private String node; @Value("${cassandra.keyspace}") private String keyspace; @Autowired private CassandraClusterBuilderMaker cassandraClusterBuilderMaker; public void execute(InputStream commandStream) throws IOException { byte[] commandBuffer = new byte[commandStream.available()]; IOUtils.readFully(commandStream, commandBuffer); Cluster cluster = cassandraClusterBuilderMaker.create().addContactPoint(node).build(); Session session = cluster.connect(keyspace); List<String> commands = Arrays.asList(new String(commandBuffer, "UTF-8").split(";")); for(String command : commands){ if(!command.trim().isEmpty()){ command = command.trim() + ";"; LOG.info("Execute:\n" + command); try { session.execute(command); } catch (SyntaxError e) { LOG.error("Command failed with " + e.getMessage()); throw e; } } } } }
Given this, you can run cql scripts to create tables and load data. This is good for little things, but probably too slow for something big. A script might look like this:
CREATE TABLE access_tiers ( level bigint PRIMARY KEY, role text ); ALTER TABLE access_tiers WITH caching = 'all' AND compression = {'sstable_compression' : ''}; INSERT INTO access_tiers (level, role) VALUES (200, 'user_tier2'); INSERT INTO access_tiers (level, role) VALUES (1000, 'user_tier3'); INSERT INTO access_tiers (level, role) VALUES (5000, 'user_tier4'); INSERT INTO access_tiers (level, role) VALUES (10000, 'user_tier5'); INSERT INTO access_tiers (level, role) VALUES (20000, 'user_tier6'); INSERT INTO access_tiers (level, role) VALUES (50000, 'moderator');
Edit:
Starting from this original post, I have extracted the Java component that I use for my project. I also created a small sample project that shows how to integrate it. These are bare bones. There are various approaches to this problem, so I chose the one that was easy to build and does what I need. Here are two github projects:
https://github.com/DonBranson/cql_schema_versioning
https://github.com/DonBranson/cql_schema_versioning_example