org.apache.cassandra.service.EmbeddedCassandraService Java Examples

The following examples show how to use org.apache.cassandra.service.EmbeddedCassandraService. 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: BatchTests.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@BeforeClass()
public static void setup() throws ConfigurationException, IOException
{
    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("drop keyspace if exists junit;");
    session.execute("create keyspace junit WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
    session.execute("CREATE TABLE junit.noncounter (\n" +
            "  id int PRIMARY KEY,\n" +
            "  val text\n" +
            ");");
    session.execute("CREATE TABLE junit.counter (\n" +
            "  id int PRIMARY KEY,\n" +
            "  val counter,\n" +
            ");");


    noncounter = session.prepare("insert into junit.noncounter(id, val)values(?,?)");
    counter = session.prepare("update junit.counter set val = val + ? where id = ?");
}
 
Example #2
Source File: PreparedStatementsTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception
{
    Schema.instance.clear();

    EmbeddedCassandraService cassandra = new EmbeddedCassandraService();
    cassandra.start();

    // Currently the native server start method return before the server is fully binded to the socket, so we need
    // to wait slightly before trying to connect to it. We should fix this but in the meantime using a sleep.
    Thread.sleep(500);

    cluster = Cluster.builder().addContactPoint("127.0.0.1")
                               .withPort(DatabaseDescriptor.getNativeTransportPort())
                               .build();
    session = cluster.connect();

    session.execute(dropKsStatement);
    session.execute(createKsStatement);
}
 
Example #3
Source File: NonNativeTimestampTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws Exception
{
    Schema.instance.clear();
    EmbeddedCassandraService cassandra = new EmbeddedCassandraService();
    cassandra.start();
}
 
Example #4
Source File: CQLMetricsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass()
public static void setup() throws ConfigurationException, IOException
{
    Schema.instance.clear();

    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("CREATE KEYSPACE IF NOT EXISTS junit WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
    session.execute("CREATE TABLE IF NOT EXISTS junit.metricstest (id int PRIMARY KEY, val text);");
}
 
Example #5
Source File: MultiSliceTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws IOException, TException 
{
    Schema.instance.clear(); // Schema are now written on disk and will be reloaded
    new EmbeddedCassandraService().start();
    ThriftSessionManager.instance.setCurrentSocket(new InetSocketAddress(9160));        
    server = new CassandraServer();
    server.set_keyspace("Keyspace1");
}
 
Example #6
Source File: CorruptionTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@BeforeClass()
public static void setup() throws ConfigurationException, IOException
{
    Schema.instance.clear();

    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1")
                     .withRetryPolicy(new LoggingRetryPolicy(Policies.defaultRetryPolicy()))
                     .withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE +" WITH replication " +
                    "= {'class':'SimpleStrategy', 'replication_factor':1};");
    session.execute("USE " + KEYSPACE);
    session.execute("CREATE TABLE IF NOT EXISTS " + TABLE + " (" +
                     "key blob," +
                     "value blob," +
                     "PRIMARY KEY (key));");


    // Prepared statements
    getStatement = session.prepare("SELECT value FROM " + TABLE + " WHERE key = ?;");
    getStatement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);

    putStatement = session.prepare("INSERT INTO " + TABLE + " (key, value) VALUES (?, ?);");
    putStatement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);



    StringBuilder s = new StringBuilder();
    char a='a';
    char z='z';
    for (int i = 0; i < 500*1024; i++)
    {
        char x = (char)((i%((z-a)+1))+a);
        if (x == 'a')
        {
            x = '\n';
        }
        s.append(x);
    }
    VALUE = s.toString();
}
 
Example #7
Source File: DeleteTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws Exception
{
    Schema.instance.clear();

    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("drop keyspace if exists junit;");
    session.execute("create keyspace junit WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };");
    session.execute("CREATE TABLE junit.tpc_base (\n" +
            "  id int ,\n" +
            "  cid int ,\n" +
            "  val text ,\n" +
            "  PRIMARY KEY ( ( id ), cid )\n" +
            ");");
    session.execute("CREATE TABLE junit.tpc_inherit_a (\n" +
            "  id int ,\n" +
            "  cid int ,\n" +
            "  inh_a text ,\n" +
            "  val text ,\n" +
            "  PRIMARY KEY ( ( id ), cid )\n" +
            ");");
    session.execute("CREATE TABLE junit.tpc_inherit_b (\n" +
            "  id int ,\n" +
            "  cid int ,\n" +
            "  inh_b text ,\n" +
            "  val text ,\n" +
            "  PRIMARY KEY ( ( id ), cid )\n" +
            ");");
    session.execute("CREATE TABLE junit.tpc_inherit_b2 (\n" +
            "  id int ,\n" +
            "  cid int ,\n" +
            "  inh_b text ,\n" +
            "  inh_b2 text ,\n" +
            "  val text ,\n" +
            "  PRIMARY KEY ( ( id ), cid )\n" +
            ");");
    session.execute("CREATE TABLE junit.tpc_inherit_c (\n" +
            "  id int ,\n" +
            "  cid int ,\n" +
            "  inh_c text ,\n" +
            "  val text ,\n" +
            "  PRIMARY KEY ( ( id ), cid )\n" +
            ");");

    pstmtI = session.prepare("insert into junit.tpc_inherit_b ( id, cid, inh_b, val) values (?, ?, ?, ?)");
    pstmtU = session.prepare("update junit.tpc_inherit_b set inh_b=?, val=? where id=? and cid=?");
    pstmtD = session.prepare("delete from junit.tpc_inherit_b where id=? and cid=?");
    pstmt1 = session.prepare("select id, cid, val from junit.tpc_base where id=? and cid=?");
    pstmt2 = session.prepare("select id, cid, inh_a, val from junit.tpc_inherit_a where id=? and cid=?");
    pstmt3 = session.prepare("select id, cid, inh_b, val from junit.tpc_inherit_b where id=? and cid=?");
    pstmt4 = session.prepare("select id, cid, inh_b, inh_b2, val from junit.tpc_inherit_b2 where id=? and cid=?");
    pstmt5 = session.prepare("select id, cid, inh_c, val from junit.tpc_inherit_c where id=? and cid=?");
}
 
Example #8
Source File: PigTestBase.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
protected static void startCassandra() throws IOException
{
    Schema.instance.clear(); // Schema are now written on disk and will be reloaded
    cassandra = new EmbeddedCassandraService();
    cassandra.start();
}