Java Code Examples for org.cassandraunit.CQLDataLoader#load()
The following examples show how to use
org.cassandraunit.CQLDataLoader#load() .
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 |
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 |
@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: CassandraLoaderStandaloneTest.java From swblocks-decisiontree with Apache License 2.0 | 5 votes |
@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 4
Source File: CassandraLoaderStandaloneTest.java From swblocks-decisiontree with Apache License 2.0 | 5 votes |
@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 5
Source File: _AbstractCassandraTest.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@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 6
Source File: AbstractCassandraTest.java From gpmr with Apache License 2.0 | 5 votes |
@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 7
Source File: AbstractCassandraTest.java From gpmr with Apache License 2.0 | 5 votes |
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 8
Source File: TitusCassandraResource.java From titus-control-plane with Apache License 2.0 | 4 votes |
private void loadSchema() { CQLDataLoader dataLoader = new CQLDataLoader(EmbeddedCassandraServerHelper.getSession()); dataLoader.load(new ClassPathCQLDataSet(CASSANDRA_SCHEMA, "Titus")); }
Example 9
Source File: CassandraLoaderStandaloneTest.java From swblocks-decisiontree with Apache License 2.0 | 4 votes |
@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 10
Source File: CassandraLoaderStandaloneTest.java From swblocks-decisiontree with Apache License 2.0 | 4 votes |
@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: CassandraJUnitRule.java From cassandra-migration with MIT License | 4 votes |
private void load() { Session session = cluster.connect(); CQLDataLoader dataLoader = new CQLDataLoader(session); dataLoader.load(dataSet); session.close(); }
Example 12
Source File: CassandraMigrationAutoConfigurationTest.java From cassandra-migration with MIT License | 4 votes |
private void loadTestData() { Session session = cluster.connect(); CQLDataLoader dataLoader = new CQLDataLoader(session); dataLoader.load(dataSet); session.close(); }