jsevellec / cassandra-unit-examples Goto Github PK
View Code? Open in Web Editor NEWVarious examples of using cassandra-unit
Various examples of using cassandra-unit
This is just a really small issue - when using EmbeddedCassandraServerHelper#startEmbeddedCassandra(String, String)
to create embedded server instance, second parameter is ignored (tmpDir
).
Perhaps I'm mis-using cassandra-unit, but I'm trying to test MultigetSliceQueries using an example from Hector. Here's my test:
public class MultigetSliceRetrievalTest extends AbstractCassandraUnit4TestCase {
private static StringSerializer stringSerializer = StringSerializer.get();
@Test
public void testMutatorAndMultigetSliceQuery() throws Exception {
Keyspace keyspace = getKeyspace();
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
for (int i = 0; i < 20; i++) {
mutator.addInsertion("fake_key_" + i, keyspace.getKeyspaceName(), HFactory.createStringColumn("fake_column_0", "fake_value_0_" + i))
.addInsertion("fake_key_" + i, keyspace.getKeyspaceName(), HFactory.createStringColumn("fake_column_1", "fake_value_1_" + i))
.addInsertion("fake_key_" + i, keyspace.getKeyspaceName(), HFactory.createStringColumn("fake_column_2", "fake_value_2_" + i));
}
mutator.execute();
MultigetSliceQuery<String, String, String> multigetSliceQuery =
HFactory.createMultigetSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer);
multigetSliceQuery.setColumnFamily(keyspace.getKeyspaceName());
multigetSliceQuery.setKeys("fake_key_0", "fake_key_1","fake_key_2", "fake_key_3", "fake_key_4");
// set null range for empty byte[] on the underlying predicate
multigetSliceQuery.setRange(null, null, false, 3);
System.out.println(multigetSliceQuery);
QueryResult<Rows<String, String, String>> result = multigetSliceQuery.execute();
Rows<String, String, String> orderedRows = result.get();
System.out.println("Contents of rows: \n");
for (Row<String, String, String> r : orderedRows) {
System.out.println(" " + r);
}
System.out.println("Should have 5 rows: " + orderedRows.getCount());
}
@Override
public DataSet getDataSet() {
return new ClassPathYamlDataSet("extendedDataSet.yaml");
}
}
It fails on mutator.execute();
with:
me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:unconfigured columnfamily otherKeyspaceName)
Is this my fault?
Any clues would be greatly appreciated. =)
I cloned the latest version of the examples and running mvn test
throws up this error. I don't see any 1.1.1.2-SNAPSHOT in the sonatype snapshots repository, btw. 1.1.0.2 seems to work.
I am trying to run the following test:
@rule
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet("tcgadata.cql","tcgadata"));
@Test
public void should_have_started_and_execute_cql_script() throws Exception {
ResultSet result = cassandraCQLUnit.session.execute("select * from mytable WHERE id='myKey01'");
assertThat(result.iterator().next().getString("value"), is("myValue01"));
}
Using: cassandra-unit-spring 2.0.2.1-SNAPSHOT
And I get the following exception, looking at this yaml file, I do see the cas timeout setting.
09:55:16,556 INFO DatabaseDescriptor:132 - Loading settings from file: target/embeddedCassandra/cu-cassandra.yaml
09:55:16,956 ERROR DatabaseDescriptor:506 - Fatal configuration error error
Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot create property=cas_contention_timeout_in_ms for JavaBean=org.apache.cassandra.config.Config@76a9b9c; Unable to find property 'cas_contention_timeout_in_ms' on class: org.apache.cassandra.config.Config
in "", line 10, column 1:
cluster_name: 'Test Cluster'
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:372)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:177)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:136)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:122)
at org.yaml.snakeyaml.Loader.load(Loader.java:52)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:166)
at org.apache.cassandra.config.DatabaseDescriptor.loadYaml(DatabaseDescriptor.java:148)
at org.apache.cassandra.config.DatabaseDescriptor.<clinit>(DatabaseDescriptor.java:123)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.mkdirs(EmbeddedCassandraServerHelper.java:227)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.cleanupAndLeaveDirs(EmbeddedCassandraServerHelper.java:199)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:95)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:65)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:49)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:45)
at org.cassandraunit.BaseCassandraUnit.before(BaseCassandraUnit.java:18)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:41)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create property=cas_contention_timeout_in_ms for JavaBean=org.apache.cassandra.config.Config@76a9b9c; Unable to find property 'cas_contention_timeout_in_ms' on class: org.apache.cassandra.config.Config
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:305)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:184)
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:370)
... 30 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'cas_contention_timeout_in_ms' on class: org.apache.cassandra.config.Config
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:342)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:240)
... 32 more
null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot create property=cas_contention_timeout_in_ms for JavaBean=org.apache.cassandra.config.Config@76a9b9c; Unable to find property 'cas_contention_timeout_in_ms' on class: org.apache.cassandra.config.Config
Invalid yaml; unable to start server. See log for stacktrace.
After cloning cassandra-unit-examples (2 mins ago), and attempting to run mvn test, I get missing dependencies, so I look at the repos and find that the cassandra-unit SNAPSHOT dependency doesn't exit. So then I change it to one of the updated SNAPSHOT dependencies mentioned here [0], then I do mvn test and yes the dependency exists, but then tests fail with output like the following
{code}
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
ManuallyStartWithMyOwnCassandraYaml.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.hamcrest.Matchers.is;
ManuallyStartWithMyOwnCassandraYaml.java:[22,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@before
AutomaticallyStartAndLoadExtendedJsonDataSetTest.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.hamcrest.Matchers.is;
AutomaticallyStartAndLoadExtendedJsonDataSetTest.java:[32,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@OverRide
AutomaticallyStartAndLoadExtendedJsonDataSetTest.java:[43,12] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
SliceQuery<Composite, Composite, String> query = HFactory.createSliceQuery(getKeyspace(),
SecondaryIndexWithRuleTest.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.hamcrest.Matchers.is;
SecondaryIndexWithRuleTest.java:[27,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@rule
SecondaryIndexWithRuleTest.java:[33,20] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
IndexedSlicesQuery<String, String, ByteBuffer> query = HFactory.createIndexedSlicesQuery(
...
much much more
{code}
I will send a pull request if I get time to get to the bottom of this one.
[0] https://oss.sonatype.org/content/repositories/snapshots/org/cassandraunit/cassandra-unit/
The test always throws below error:
2015-07-22 18:58:35 DEBUG DatabaseDescriptor:322 - Syncing log with a period of 10000
2015-07-22 18:58:35 INFO DatabaseDescriptor:334 - Windows environment detected. DiskAccessMode set to standard, indexAccessMode standard
2015-07-22 18:58:35 ERROR DatabaseDescriptor:141 - Fatal configuration error
org.apache.cassandra.exceptions.ConfigurationException: Invalid partitioner class org.apache.cassandra.dht.Murmur3Partitioner
at org.apache.cassandra.config.DatabaseDescriptor.applyConfig(DatabaseDescriptor.java:388)
at org.apache.cassandra.config.DatabaseDescriptor.(DatabaseDescriptor.java:136)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.mkdirs(EmbeddedCassandraServerHelper.java:333)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.cleanupAndLeaveDirs(EmbeddedCassandraServerHelper.java:305)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:116)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:85)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64)
...........................
Invalid partitioner class org.apache.cassandra.dht.Murmur3Partitioner
Fatal configuration error; unable to start. See log for stacktrace.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- start here for emb server -->
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>2.1.3.2-SNAPSHOT</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-shaded</artifactId>
<version>2.1.3.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hectorclient</groupId>
<artifactId>hector-core</artifactId>
<version>2.0-0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
I know there was a fix that went in few days ago. Still the problem seems to show up. Thanks
EmbeddedCassandraServerHelper.startEmbeddedCassandra()
This line throws:
ERROR [DatabaseDescriptor] - Fatal configuration error
org.apache.cassandra.exceptions.ConfigurationException: Invalid yaml
Invalid yaml
at org.apache.cassandra.config.YamlConfigurationLoader.loadConfig(YamlConfigurationLoader.java:108)
at org.apache.cassandra.config.DatabaseDescriptor.loadConfig(DatabaseDescriptor.java:153)
at org.apache.cassandra.config.DatabaseDescriptor.<clinit>(DatabaseDescriptor.java:129)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.mkdirs(EmbeddedCassandraServerHelper.java:239)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.cleanupAndLeaveDirs(EmbeddedCassandraServerHelper.java:211)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:107)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:77)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:57)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:49)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:45)
at com.bluejeans.services.inval.mocks.MockCassandra.<init>(MockCassandra.java:15)
at com.bluejeans.services.inval.mocks.TestSeamStorageManager.setup(TestSeamStorageManager.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=java.lang.reflect.InvocationTargetException
in 'reader', line 10, column 1:
cluster_name: 'Test Cluster'
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:333)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481)
at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:475)
at org.apache.cassandra.config.YamlConfigurationLoader.loadConfig(YamlConfigurationLoader.java:101)
... 33 more
Caused by: org.yaml.snakeyaml.error.YAMLException: java.lang.reflect.InvocationTargetException
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:219)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189)
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:331)
... 39 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:217)
... 41 more
Caused by: java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;
at org.apache.cassandra.config.Config.<init>(Config.java:53)
... 46 more
NOTE: This is Cassandra 2.1.0
[ERROR] Failed to execute goal on project cassandra-unit-examples: Could not resolve dependencies for project org.cassandraunit:cassandra-unit-examples:jar:1.1.1.3-SNAPSHOT: Could not find artifact org.cassandraunit:cassandra-unit-spring:jar:2.0.2.1-SNAPSHOT in sonatype-oss-snapshot (https://oss.sonatype.org/content/repositories/snapshots/) -> [Help 1]
I downloaded the latest version of the examples.
In STS, there were some compile errors because of the pom.xml
I could use a preceding version 2013/06/21
Hi,
I have started using cassandra unit (v1.2.0.1) along with cassandra-unit-spring(v1.2.0.1)
I noticed that whenever my unit test case is set up with cassandra-unit like below it never picks up and loads the beans defined as part of the spring context xml available via "@ContextConfiguration".
When I comment out the CassandraUnit annotations I find that it loads my spring beans defined as part the classpath "cassandra-context.xml"
@TestExecutionListeners({ CassandraUnitTestExecutionListener.class })
@CassandraDataSet(value = { "simple.cql" })
@EmbeddedCassandra(clusterName = "Unit Test Cluster", host = "127.0.0.1", port = 9142)
@ContextConfiguration(locations = {
"classpath*:cassandra-context.xml"
})
Regards
Meena
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.