com.strapdata.elassandraunit:elassandra-unit-shaded

Shaded version of cassandra-unit

License

License

Categories

Categories

Data
GroupId

GroupId

com.strapdata.elassandraunit
ArtifactId

ArtifactId

elassandra-unit-shaded
Last Version

Last Version

3.7.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

Shaded version of cassandra-unit

Download elassandra-unit-shaded

How to add to project

<!-- https://jarcasting.com/artifacts/com.strapdata.elassandraunit/elassandra-unit-shaded/ -->
<dependency>
    <groupId>com.strapdata.elassandraunit</groupId>
    <artifactId>elassandra-unit-shaded</artifactId>
    <version>3.7.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.strapdata.elassandraunit/elassandra-unit-shaded/
implementation 'com.strapdata.elassandraunit:elassandra-unit-shaded:3.7.1.4'
// https://jarcasting.com/artifacts/com.strapdata.elassandraunit/elassandra-unit-shaded/
implementation ("com.strapdata.elassandraunit:elassandra-unit-shaded:3.7.1.4")
'com.strapdata.elassandraunit:elassandra-unit-shaded:jar:3.7.1.4'
<dependency org="com.strapdata.elassandraunit" name="elassandra-unit-shaded" rev="3.7.1.4">
  <artifact name="elassandra-unit-shaded" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.strapdata.elassandraunit', module='elassandra-unit-shaded', version='3.7.1.4')
)
libraryDependencies += "com.strapdata.elassandraunit" % "elassandra-unit-shaded" % "3.7.1.4"
[com.strapdata.elassandraunit/elassandra-unit-shaded "3.7.1.4"]

Dependencies

compile (79)

Group / Artifact Type Version
junit : junit jar 4.12
com.strapdata.elasticsearch : elasticsearch jar 6.8.4.4
com.strapdata.cassandra : cassandra-all jar 3.11.6.1
org.xerial.snappy : snappy-java jar 1.1.1.7
net.jpountz.lz4 : lz4 jar 1.3.0
com.ning : compress-lzf jar 0.8.4
commons-cli : commons-cli jar 1.3.1
org.apache.commons : commons-math3 jar 3.2
com.googlecode.concurrentlinkedhashmap : concurrentlinkedhashmap-lru jar 1.4
org.slf4j : jcl-over-slf4j jar 1.7.7
com.googlecode.json-simple : json-simple jar 1.1
org.mindrot : jbcrypt jar 0.3m
io.airlift : airline jar 0.6
javax.inject : javax.inject jar 1
io.dropwizard.metrics : metrics-core jar 3.1.5
io.dropwizard.metrics : metrics-jvm jar 3.1.5
com.thinkaurelius.thrift : thrift-server jar 0.3.7
com.lmax : disruptor jar 3.0.1
com.clearspring.analytics : stream jar 2.5.2
it.unimi.dsi : fastutil jar 6.5.7
com.strapdata.cassandra : cassandra-thrift jar 3.11.6.1
de.jflex : jflex jar 1.6.0
org.apache.ant : ant jar 1.7.0
org.apache.ant : ant-launcher jar 1.7.0
com.googlecode.concurrent-trees : concurrent-trees jar 2.4.0
org.fusesource : sigar jar 1.6.4
org.eclipse.jdt.core.compiler : ecj jar 4.4.2
org.caffinitas.ohc : ohc-core jar 0.4.4
org.caffinitas.ohc : ohc-core-j8 jar 0.4.4
com.github.ben-manes.caffeine : caffeine jar 2.2.6
org.jctools : jctools-core jar 1.2.1
org.ow2.asm : asm jar 5.0.4
org.glassfish.main.external : jmxremote_optional-repackaged jar 5.0
com.strapdata.elasticsearch : elasticsearch-core jar 6.8.4.4
com.strapdata.elasticsearch » elasticsearch-secure-sm jar 6.8.4.4
com.strapdata.elasticsearch » elasticsearch-x-content jar 6.8.4.4
org.apache.lucene : lucene-core jar 7.7.2
org.apache.lucene : lucene-analyzers-common jar 7.7.2
org.apache.lucene : lucene-backward-codecs jar 7.7.2
org.apache.lucene : lucene-grouping jar 7.7.2
org.apache.lucene : lucene-highlighter jar 7.7.2
org.apache.lucene : lucene-join jar 7.7.2
org.apache.lucene : lucene-memory jar 7.7.2
org.apache.lucene : lucene-misc jar 7.7.2
org.apache.lucene : lucene-queries jar 7.7.2
org.apache.lucene : lucene-queryparser jar 7.7.2
org.apache.lucene : lucene-sandbox jar 7.7.2
org.apache.lucene : lucene-spatial jar 7.7.2
org.apache.lucene : lucene-spatial-extras jar 7.7.2
org.apache.lucene : lucene-spatial3d jar 7.7.2
org.apache.lucene : lucene-suggest jar 7.7.2
com.strapdata.elasticsearch : elasticsearch-cli jar 6.8.4.4
com.carrotsearch : hppc jar 0.7.1
joda-time : joda-time jar 2.10.1
org.yaml : snakeyaml jar 1.17
com.fasterxml.jackson.core : jackson-core jar 2.8.11
com.fasterxml.jackson.dataformat : jackson-dataformat-smile jar 2.8.11
com.fasterxml.jackson.dataformat : jackson-dataformat-yaml jar 2.8.11
com.fasterxml.jackson.dataformat : jackson-dataformat-cbor jar 2.8.11
com.tdunning : t-digest jar 3.2
org.hdrhistogram : HdrHistogram jar 2.1.9
org.apache.logging.log4j : log4j-api jar 2.11.1
org.elasticsearch : jna jar 4.5.1
com.boundary : high-scale-lib jar 1.0.6
com.github.jbellis : jamm jar 0.3.0
commons-codec : commons-codec jar 1.10
commons-logging : commons-logging jar 1.1.3
org.apache.logging.log4j : log4j-to-slf4j jar 2.11.1
ch.qos.logback : logback-classic jar 1.1.8
ch.qos.logback : logback-core jar 1.1.8
org.javassist : javassist jar 3.20.0-GA
net.sf.jopt-simple : jopt-simple jar 5.0.2
com.strapdata.elasticsearch.plugin » transport-netty4-client jar 6.8.4.4
org.apache.commons : commons-lang3 jar 3.4
org.apache.thrift : libthrift jar 0.9.2
org.apache.httpcomponents : httpclient jar 4.2.5
org.apache.httpcomponents : httpcore jar 4.2.4
net.java.dev.jna : jna jar 4.1.0
org.slf4j : slf4j-api jar 1.7.12

Project Modules

There are no modules declared in this project.

git statu# ElassandraUnit

ElassandraUnit is a fork form CassandraUnit modified for Elassandra.

ElassandraUnit helps you writing isolated JUnit tests in a Test Driven Development style with an embedded Elassandra instance.

Elassandra Unit Figure

  • Start an embedded Elassandra (including both Cassandra and Elasticsearch).
  • Create structure (keyspace and Column Families) and load data from an XML, JSON or YAML DataSet.
  • Execute a CQL script.
  • Query Cassandra through the Cassandra driver
  • Query Elasticsearch through the Elasticsearch REST API.

Quick start

Add the following dependencies:

    <dependency>
        <groupId>com.strapdata.elassandraunit</groupId>
        <artifactId>elassandra-unit-spring</artifactId>
        <version>${elassandra-unit.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.strapdata.elassandraunit</groupId>
                <artifactId>elassandra-unit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.strapdata.elassandraunit</groupId>
        <artifactId>elassandra-unit</artifactId>
        <classifier>shaded</classifier>
        <exclusions>
            <exclusion>
                <artifactId>httpclient</artifactId>
                <groupId>org.apache.httpcomponents</groupId>
            </exclusion>
            <exclusion>
                <artifactId>httpcore</artifactId>
                <groupId>org.apache.httpcomponents</groupId>
            </exclusion>
        </exclusions>
        <version>${elassandra-unit.version}</version>
        <scope>test</scope>
    </dependency>

Add the Elasticsearch REST high level client with the same version as the one embedded in elassandra.

    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>6.2.3</version>
    </dependency>

To handle Elasticsearch search requests over CQL, set the system property cassandra.custom_query_handler_class to org.elassandra.index.ElasticQueryHandler:

    ...
    <build>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <configuration>
                <systemPropertyVariables>
                    <cassandra.custom_query_handler_class>org.elassandra.index.ElasticQueryHandler</cassandra.custom_query_handler_class>
                </systemPropertyVariables>
            </configuration>
            </plugin>
        </plugins>
    </build>

Create a JUnit test class :

public class SimpleTest {

    static final String KEYSPACE = "ks";

    @ClassRule
    public static CassandraCQLUnit cassandraCQLUnit =
        new CassandraCQLUnit(new SimpleCQLDataSet(
            "CREATE TABLE users (email text PRIMARY KEY, firstname text, lastname text, es_query text, es_options text);", KEYSPACE));

    private static Mapper<User> userMapper;
    private static RestHighLevelClient client;

    @Before
    public void setup() throws IOException {
        userMapper = new MappingManager(cassandraCQLUnit.session).mapper(User.class);
        client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));

        // create an elasticsearch index on table users
        CreateIndexRequest request = new CreateIndexRequest("users");
        request.mapping("users", XContentFactory.jsonBuilder()
            .startObject()
                .startObject("users")
                    .field("discover", ".*")
                .endObject()
            .endObject());
        request.settings(Settings.builder()
            .put("keyspace", KEYSPACE)                          // map index users to our keyspace.
            .put("index.synchronous_refresh",true)// synchronous elasticsearch refresh
            .build());
        CreateIndexResponse createIndexResponse = client.indices().create(request);
    }

    @Test
    public void testMapper() throws Exception {
        User user1 = new User().withEmail("[email protected]").withFirstname("Bob").withLastname("Smith");
        User user2 = new User().withEmail("[email protected]").withFirstname("Alice").withLastname("Smith");
        User user3 = new User().withEmail("[email protected]").withFirstname("Paul").withLastname("Dupont");
        userMapper.save(user1);
        userMapper.save(user2);
        userMapper.save(user3);

        User user = userMapper.get("[email protected]");
        assertThat(user, is(user1));

        // Elasticsearch search through the REST API
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(QueryBuilders.termQuery("lastname", "Smith"));
        SearchRequest searchRequest = new SearchRequest().indices("users").source(sourceBuilder);
        SearchResponse searchResponse = client.search(searchRequest);
        assertThat(searchResponse.getHits().totalHits, is(2L));

        // Elasticsearch search through CQL
        String esQuery = new SearchSourceBuilder().query(QueryBuilders.termQuery("lastname", "Smith")).toString(ToXContent.EMPTY_PARAMS);
        ResultSet results = cassandraCQLUnit.session.execute(
            "SELECT * FROM users WHERE es_options = ? AND es_query = ? ALLOW FILTERING", "indices=users", esQuery);
        Result<User> users = userMapper.map(results);
        assertThat(users.all().size(), is(2));
    }
}

Resources

Support

License

This project is licensed under LGPL V3.0

Acknowledgments

  • CassandraUnit is developped by Jérémy Sevellec
  • Elasticsearch and Kibana are trademarks of Elasticsearch BV, registered in the U.S. and in other countries.
  • Apache Cassandra, Apache Lucene, Apache, Lucene and Cassandra are trademarks of the Apache Software Foundation.
  • Elassandra is a trademark of Strapdata SAS, registered in the U.S. and in other countries.
com.strapdata.elassandraunit

Strapdata

Strapdata simplify your data stack with Elassandra = Elasticsearch + Cassandra

Versions

Version
3.7.1.4
3.7.1.3
3.7.1.2
3.7.1.1
3.7.1.0
3.5.0.5
3.5.0.4
3.5.0.3
3.5.0.2
3.5.0.1