org.cassandraunit.dataset.cql.ClassPathCQLDataSet Java Examples

The following examples show how to use org.cassandraunit.dataset.cql.ClassPathCQLDataSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedCassandraStoreFactory.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private Session createEmbeddedCassandra() {
    // Disable fsync for a massive speedup on old platters. This improves boot time by a few seconds.
    System.setProperty("cassandra.unsafesystem", "true");

    try {
        File cassandraTmpDir = Files.createTempDir();
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG, cassandraTmpDir.getAbsolutePath(), STARTUP_TIMEOUT);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot initialize the embedded Cassandra", e);
    }

    Session session = EmbeddedCassandraServerHelper.getSession();
    session.execute("CREATE KEYSPACE " + CASSANDRA_KEYSPACE + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }");
    session.execute("USE " + CASSANDRA_KEYSPACE);

    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataLoader.load(new ClassPathCQLDataSet(CASSANDRA_SCHEMA, "Titus"));

    return session;
}
 
Example #2
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavingAndLoadingDecisionTree() {
    final CQLDataLoader dataLoader = new CQLDataLoader(this.session);
    dataLoader.load(new ClassPathCQLDataSet(CQL_RESOURCE, "loadSavedecisiontree"));

    this.cassandraLoader = CassandraLoader.instanceOf(this.cluster, "loadSavedecisiontree", RULE_SET_NAME);
    final DecisionTreeRuleSet commissions = CommisionRuleSetSupplier.getCommisionRuleSet().build();
    assertNotNull(commissions);

    this.cassandraLoader.put(commissions);
    final Result<DecisionTreeRuleSet> decisionTreeRuleSetResult = this.cassandraLoader.get();
    assertTrue(decisionTreeRuleSetResult.isSuccess());
    final DecisionTreeRuleSet decisionTreeRuleSet = decisionTreeRuleSetResult.getData();
    assertNotNull(decisionTreeRuleSet);
    assertNotNull(decisionTreeRuleSet.getRules());
    assertThat(decisionTreeRuleSet, DecisionTreeRuleSetMatcher.isSame(commissions));
}
 
Example #3
Source File: AbstractCassandraTest.java    From gpmr with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException  {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9142).build();
    Session session = cluster.connect();
    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataLoader.load(new ClassPathCQLDataSet("config/cql/create-tables.cql", true, CASSANDRA_UNIT_KEYSPACE));
    applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
}
 
Example #4
Source File: CassandraInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void setUp() throws IOException, InterruptedException {
  System.setProperty("cassandra.skip_wait_for_gossip_to_settle", "0");
  System.setProperty("cassandra.load_ring_state", "false");
  System.setProperty("cassandra.initial_token", "0");
  System.setProperty("cassandra.num_tokens", "nil");
  System.setProperty("cassandra.allocate_tokens_for_local_replication_factor", "nil");
  EmbeddedCassandraServerHelper.startEmbeddedCassandra();
  CqlSession session = EmbeddedCassandraServerHelper.getSession();
  new CQLDataLoader(session).load(new ClassPathCQLDataSet("prepare_all.cql", "zeppelin"));

  Properties properties = new Properties();
  properties.setProperty(CASSANDRA_CLUSTER_NAME, EmbeddedCassandraServerHelper.getClusterName());
  properties.setProperty(CASSANDRA_COMPRESSION_PROTOCOL, "NONE");
  properties.setProperty(CASSANDRA_CREDENTIALS_USERNAME, "none");
  properties.setProperty(CASSANDRA_CREDENTIALS_PASSWORD, "none");

  properties.setProperty(CASSANDRA_LOAD_BALANCING_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_RETRY_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_RECONNECTION_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_SPECULATIVE_EXECUTION_POLICY, "DEFAULT");

  properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_LOCAL, "2");
  properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_REMOTE, "1");
  properties.setProperty(CASSANDRA_POOLING_MAX_REQUESTS_PER_CONNECTION, "1024");

  properties.setProperty(CASSANDRA_POOLING_POOL_TIMEOUT_MILLIS, "5000");
  properties.setProperty(CASSANDRA_POOLING_HEARTBEAT_INTERVAL_SECONDS, "30");

  properties.setProperty(CASSANDRA_QUERY_DEFAULT_CONSISTENCY, "ONE");
  properties.setProperty(CASSANDRA_QUERY_DEFAULT_SERIAL_CONSISTENCY, "SERIAL");
  properties.setProperty(CASSANDRA_QUERY_DEFAULT_FETCH_SIZE, "5000");

  properties.setProperty(CASSANDRA_SOCKET_CONNECTION_TIMEOUT_MILLIS, "5000");
  properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000");
  properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true");

  properties.setProperty(CASSANDRA_HOSTS, EmbeddedCassandraServerHelper.getHost());
  properties.setProperty(CASSANDRA_PORT,
          Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort()));
  properties.setProperty("datastax-java-driver.advanced.connection.pool.local.size", "1");
  interpreter = new CassandraInterpreter(properties);
  interpreter.open();
}
 
Example #5
Source File: CassandraMigrationAutoConfigurationTest.java    From cassandra-migration with MIT License 5 votes vote down vote up
@Bean
public Cluster cluster() throws Exception {
    dataSet = new ClassPathCQLDataSet(CASSANDRA_INIT_SCRIPT, TEST_KEYSPACE);
    cluster = new Cluster.Builder().addContactPoints(LOCALHOST).withPort(9142).build();
    init();
    return cluster;
}
 
Example #6
Source File: AbstractCassandraTest.java    From gpmr with Apache License 2.0 5 votes vote down vote up
private static void applyScripts(CQLDataLoader dataLoader, String cqlDir, String pattern) throws IOException, URISyntaxException {
    URL dirUrl = ClassLoader.getSystemResource(cqlDir);
    if (dirUrl == null) { // protect for empty directory
        return;
    }

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(dirUrl.toURI()), pattern)) {
        for (Path entry : stream) {
            String fileName = entry.getFileName().toString();
            dataLoader.load(new ClassPathCQLDataSet(cqlDir + fileName, false, false, CASSANDRA_UNIT_KEYSPACE));
        }
    }
}
 
Example #7
Source File: _AbstractCassandraTest.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9142).build();
    Session session = cluster.connect();
    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataLoader.load(new ClassPathCQLDataSet("config/cql/create-tables.cql", true, "cassandra_unit_keyspace"));
}
 
Example #8
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
@Test
public void testPersistingChangeSets() {
    final CQLDataLoader dataLoader = new CQLDataLoader(this.session);
    dataLoader.load(new ClassPathCQLDataSet(CQL_RESOURCE, "decisiontreechange"));

    this.cassandraLoader = CassandraLoader.instanceOf(this.cluster, "decisiontreechange", RULE_SET_NAME);

    final DecisionTreeRuleSet commissions = CommisionRuleSetSupplier.getCommisionRuleSet().build();
    assertNotNull(commissions);

    // Find default UK rule, id 5 and increase output rate to 1.3
    final DecisionTreeRule ukRule = commissions.getRules().get(new UUID(0, 5));
    assertNotNull(ukRule);

    // change is created for the date range of the UK rule - this is the change period
    final Builder<ChangeBuilder, Change> builder = ChangeBuilder.creator(commissions);
    builder.with(ChangeBuilder::changeRange, new DateRange(ukRule.getStart(), ukRule.getEnd()));
    builder.with(ChangeBuilder::audit, new Audit("USER1", NOW, "USER2", NOW));
    builder.with(ChangeBuilder::activation, NOW);

    builder.with(ChangeBuilder::ruleChange, RuleChangeBuilder.creator(ukRule.getRuleCode())
            .with(RuleChangeBuilder::output, Collections.singletonList("Rate:1.3")));

    final ChangeSet change = new ChangeSet(UUID.randomUUID(), "updateUKRate",
            Collections.singleton(builder.build()));

    this.cassandraLoader.put(change);

    final Result<ChangeSet> loadedChange = this.cassandraLoader.getChange("updateUKRate");
    assertNotNull(loadedChange);
    if (!loadedChange.isSuccess()) {
        assertTrue(loadedChange.getException().getMessage(), loadedChange.isSuccess());
    }
}
 
Example #9
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoRuleSetInKeySpace() {
    // Try to load a missing ruleset and confirm it reports a failure.
    final CQLDataLoader dataLoader = new CQLDataLoader(this.session);
    dataLoader.load(new ClassPathCQLDataSet(CQL_RESOURCE, "not_a_ruleset"));
    this.cassandraLoader = CassandraLoader.instanceOf(this.cluster, "not_a_ruleset", "NOT_A_RULESET");

    final Result<DecisionTreeRuleSet> results = this.cassandraLoader.get();
    assertFalse(results.isSuccess());
    assertFalse(this.cassandraLoader.test(results));
}
 
Example #10
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 4 votes vote down vote up
@Test
    public void persistsChangeSetWithNewValueGroup() {
        final CQLDataLoader dataLoader = new CQLDataLoader(this.session);
        dataLoader.load(new ClassPathCQLDataSet(CQL_RESOURCE, "decisiontreechangegroupnew"));

        this.cassandraLoader = CassandraLoader.instanceOf(this.cluster, "decisiontreechangegroupnew",
                "commissions_no_groups");
        final DecisionTreeRuleSet commissions = CommisionRuleSetSupplier.getCommisionRuleSet().build();
        this.cassandraLoader.put(commissions);

        final Set<ValueGroup> current = commissions.getValueGroups();
//        assertTrue(current.isEmpty());

        // Change the value groups
        final Builder<ValueGroupChangeBuilder, List<ValueGroupChange>> valueGroupChangeBuilder =
                ValueGroupChangeBuilder.creator("CMEGroup");
        valueGroupChangeBuilder.with(ValueGroupChangeBuilder::ruleSet, commissions);
        valueGroupChangeBuilder.with(ValueGroupChangeBuilder::drivers, Arrays.asList("CME", "CBOT"));
        valueGroupChangeBuilder.with(ValueGroupChangeBuilder::changeRange,
                new DateRange(DecisionTreeRule.EPOCH, DecisionTreeRule.MAX));
        valueGroupChangeBuilder.with(ValueGroupChangeBuilder::driver, "EXCHANGE");
        valueGroupChangeBuilder.with(ValueGroupChangeBuilder::ruleCodes, Collections.singletonList(new UUID(0, 1)));

        // persist change
        final Builder<ChangeBuilder, Change> changeBuilder = ChangeBuilder.creator(commissions);
        changeBuilder.with(ChangeBuilder::changeRange, new DateRange(DecisionTreeRule.EPOCH, DecisionTreeRule.MAX));
        changeBuilder.with(ChangeBuilder::audit, new Audit("USER1", NOW, "USER2", NOW));
        changeBuilder.with(ChangeBuilder::activation, NOW);
        changeBuilder.with(ChangeBuilder::valueGroupChange, valueGroupChangeBuilder);

        final ChangeSet changeSet = new ChangeSet(UUID.randomUUID(), "updateValueGroups",
                Collections.singleton(changeBuilder.build()));
        this.cassandraLoader.put(changeSet);

        final Result<ChangeSet> loadedChange = this.cassandraLoader.getChange("updateValueGroups");
        assertNotNull(loadedChange);
        if (!loadedChange.isSuccess()) {
            assertTrue(loadedChange.getException().getMessage(), loadedChange.isSuccess());
        }

        final Set<Change> changes = loadedChange.getData().getChanges();
        assertThat(changes, hasSize(1));

        final Optional<Change> change = changes.stream().findFirst();
        assertTrue(change.isPresent());
        assertThat(change.get().getRuleChanges(), hasSize(2));

        final Set<ValueGroupChange> groupChanges = change.get().getValueGroupChanges();
        assertThat(groupChanges, hasSize(2));

        final Optional<ValueGroupChange> groupChange = groupChanges.stream()
                .filter(groupChangeFilter -> groupChangeFilter.getType().equals(Type.NEW)).findFirst();
        assertTrue(groupChange.isPresent());
        assertEquals("EXCHANGE", groupChange.get().getValueGroup().getDriverName());
        assertThat(groupChange.get().getValueGroup().getRuleCodes(), contains(new UUID(0, 1)));
    }
 
Example #11
Source File: TitusCassandraResource.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private void loadSchema() {
    CQLDataLoader dataLoader = new CQLDataLoader(EmbeddedCassandraServerHelper.getSession());
    dataLoader.load(new ClassPathCQLDataSet(CASSANDRA_SCHEMA, "Titus"));
}
 
Example #12
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 4 votes vote down vote up
@Test
public void persistingChangeSetsWithValueGroups() {
    final CQLDataLoader dataLoader = new CQLDataLoader(this.session);
    dataLoader.load(new ClassPathCQLDataSet(CQL_RESOURCE, "decisiontreechangegroup"));

    this.cassandraLoader = CassandraLoader.instanceOf(this.cluster, "decisiontreechangegroup", RULE_SET_NAME);
    final DecisionTreeRuleSet commissions = CommisionRuleSetSupplier.getCommisionRuleSet().build();
    assertNotNull(commissions);
    final DecisionTreeRuleSet ruleSet = commissions;
    this.cassandraLoader.put(ruleSet);

    final Set<ValueGroup> current = ruleSet.getValueGroups();
    final Optional<ValueGroup> matching = current.stream().filter(valueGroup ->
            valueGroup.getId().equals(new UUID(0, 1))).findFirst();

    assertTrue(matching.isPresent());

    final ValueGroup group = matching.get();
    final Instant end = group.getRange().getFinish();
    final DateRange changeRange = new DateRange(NOW.minus(Period.ofWeeks(20)), NOW.plus(Period.ofWeeks(20)));
    final List<String> drivers = Arrays.asList("CME", "KCBOT");

    // Change the value groups
    final Builder<ValueGroupChangeBuilder, List<ValueGroupChange>> valueGroupChangeBuilder =
            ValueGroupChangeBuilder.creator(group.getName());
    valueGroupChangeBuilder.with(ValueGroupChangeBuilder::ruleSet, ruleSet);
    valueGroupChangeBuilder.with(ValueGroupChangeBuilder::drivers, drivers);
    valueGroupChangeBuilder.with(ValueGroupChangeBuilder::changeRange, changeRange);

    // persist the change...
    final Builder<ChangeBuilder, Change> changeBuilder = ChangeBuilder.creator(ruleSet);
    changeBuilder.with(ChangeBuilder::changeRange, changeRange);
    changeBuilder.with(ChangeBuilder::audit, new Audit("USER1", NOW, "USER2", NOW));
    changeBuilder.with(ChangeBuilder::activation, NOW);
    changeBuilder.with(ChangeBuilder::valueGroupChange, valueGroupChangeBuilder);

    final ChangeSet changeSet = new ChangeSet(UUID.randomUUID(), "updateValueGroups",
            Collections.singleton(changeBuilder.build()));
    this.cassandraLoader.put(changeSet);

    final Result<ChangeSet> loadedChange = this.cassandraLoader.getChange("updateValueGroups");
    assertNotNull(loadedChange);
    if (!loadedChange.isSuccess()) {
        assertTrue(loadedChange.getException().getMessage(), loadedChange.isSuccess());
    }
}
 
Example #13
Source File: CassandraJUnitRule.java    From cassandra-migration with MIT License 4 votes vote down vote up
public CassandraJUnitRule(String dataSetLocation, String ymlFileLocation) {
    dataSet = new ClassPathCQLDataSet(dataSetLocation, TEST_KEYSPACE);
    cluster = new Cluster.Builder().addContactPoints(LOCALHOST).withPort(9142).build();
    this.ymlFileLocation = ymlFileLocation;
}
 
Example #14
Source File: CassandraLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void startCassandra() throws IOException, InterruptedException {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    cqlSession = EmbeddedCassandraServerHelper.getSession();
    new CQLDataLoader(cqlSession).load(new ClassPathCQLDataSet("shedlock.cql", "shedlock"));
}
 
Example #15
Source File: CassandraAdapterDataTypesTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@BeforeAll
static void load(Session session) {
  new CQLDataLoader(session)
      .load(new ClassPathCQLDataSet("datatypes.cql"));
}
 
Example #16
Source File: CassandraAdapterTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@BeforeAll
static void load(Session session) {
  new CQLDataLoader(session)
      .load(new ClassPathCQLDataSet("twissandra.cql"));
}
 
Example #17
Source File: CassandraIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra("/camel-cassandra.yaml", "target/camel-cassandra", 30000);
    new LoadableCassandraCQLUnit(new ClassPathCQLDataSet("cassandra/BasicDataSet.cql", KEYSPACE), "/camel-cassandra.yaml").setup();
}