Skip to content

Commit

Permalink
Merge pull request #664 from hector-client/cassandra-2.0.1
Browse files Browse the repository at this point in the history
Cassandra 2.0.1
  • Loading branch information
zznate committed May 28, 2014
2 parents da4187c + f2fc542 commit 8742f88
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 328 deletions.
32 changes: 18 additions & 14 deletions core/src/test/java/me/prettyprint/cassandra/model/CqlQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import static me.prettyprint.hector.api.factory.HFactory.createKeyspace;
import static me.prettyprint.hector.api.factory.HFactory.createMutator;
import static me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
import me.prettyprint.hector.api.query.QueryResult;

import org.apache.cassandra.utils.ByteBufferUtil;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -22,6 +23,7 @@ public class CqlQueryTest extends BaseEmbededServerSetupTest {
private final static String KEYSPACE = "Keyspace1";
private static final StringSerializer se = new StringSerializer();
private static final LongSerializer le = new LongSerializer();
private static int customColumns = 0;
private Cluster cluster;
private Keyspace keyspace;
private String cf = "StandardLong1";
Expand All @@ -31,16 +33,16 @@ public void setupCase() {
cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170");
keyspace = createKeyspace(KEYSPACE, cluster);
createMutator(keyspace, se)
.addInsertion("cqlQueryTest_key1", cf, createColumn("birthyear", 1974L, se, le))
.addInsertion("cqlQueryTest_key1", cf, createColumn("birthmonth", 4L, se, le))
.addInsertion("cqlQueryTest_key2", cf, createColumn("birthyear", 1975L, se, le))
.addInsertion("cqlQueryTest_key2", cf, createColumn("birthmonth", 4L, se, le))
.addInsertion("cqlQueryTest_key3", cf, createColumn("birthyear", 1975L, se, le))
.addInsertion("cqlQueryTest_key3", cf, createColumn("birthmonth", 5L, se, le))
.addInsertion("cqlQueryTest_key4", cf, createColumn("birthyear", 1975L, se, le))
.addInsertion("cqlQueryTest_key4", cf, createColumn("birthmonth", 6L, se, le))
.addInsertion("cqlQueryTest_key1", cf, createColumn("birthyear", 1971L, se, le))
.addInsertion("cqlQueryTest_key1", cf, createColumn("birthmonth", 1L, se, le))
.addInsertion("cqlQueryTest_key2", cf, createColumn("birthyear", 1972L, se, le))
.addInsertion("cqlQueryTest_key2", cf, createColumn("birthmonth", 2L, se, le))
.addInsertion("cqlQueryTest_key3", cf, createColumn("birthyear", 1973L, se, le))
.addInsertion("cqlQueryTest_key3", cf, createColumn("birthmonth", 3L, se, le))
.addInsertion("cqlQueryTest_key4", cf, createColumn("birthyear", 1974L, se, le))
.addInsertion("cqlQueryTest_key4", cf, createColumn("birthmonth", 4L, se, le))
.addInsertion("cqlQueryTest_key5", cf, createColumn("birthyear", 1975L, se, le))
.addInsertion("cqlQueryTest_key5", cf, createColumn("birthmonth", 7L, se, le))
.addInsertion("cqlQueryTest_key5", cf, createColumn("birthmonth", 5L, se, le))
.addInsertion("cqlQueryTest_key6", cf, createColumn("birthyear", 1976L, se, le))
.addInsertion("cqlQueryTest_key6", cf, createColumn("birthmonth", 6L, se, le))
.execute();
Expand All @@ -52,9 +54,10 @@ public void testSimpleSelect() {
cqlQuery.setQuery("select * from StandardLong1");
QueryResult<CqlRows<String,String,Long>> result = cqlQuery.execute();
CqlRows<String, String, Long> rows = result.get();

// check that we contain a 'key' column
assertNotNull(rows.getList().get(0).getColumnSlice().getColumnByName("KEY"));
assertEquals(6,rows.getCount());
assertEquals(6 + customColumns,rows.getCount());
}

@Test
Expand All @@ -64,7 +67,7 @@ public void testSimpleSelect20() {
cqlQuery.setCqlVersion("2.0.0");
QueryResult<CqlRows<String,String,Long>> result = cqlQuery.execute();
CqlRows<String, String, Long> rows = result.get();
assertEquals(6,rows.getCount());
assertEquals(6 + customColumns,rows.getCount());
}

@Test
Expand Down Expand Up @@ -101,8 +104,9 @@ public void testSyntaxFailQuery() {
@Test
public void testInsertSyntax() {
CqlQuery<String,String,Long> cqlQuery = new CqlQuery<String,String,Long>(keyspace, se, se, le);
cqlQuery.setQuery("update StandardLong1 set 'birthyear' = '1976' WHERE KEY = 'cqlQueryTest_key7'");
cqlQuery.setQuery("update StandardLong1 set 'birthyear' = '1977' WHERE KEY = 'cqlQueryTest_key7'");
cqlQuery.execute();
customColumns++;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.prettyprint.cassandra.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.UnknownHostException;
import java.util.List;
import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.junit.Before;
import org.junit.Test;


public class BaseCassandraClusterTest extends BaseEmbededServerSetupTest {

private ThriftCluster cassandraCluster;
private CassandraHostConfigurator cassandraHostConfigurator;

@Before
public void setupCase() throws TTransportException, TException, IllegalArgumentException,
NotFoundException, UnknownHostException, Exception {
cassandraHostConfigurator = getCHCForTest();
cassandraCluster = new ThriftCluster(clusterName, cassandraHostConfigurator);
}

@Test
public void testDescribeKeyspaces() throws Exception {
List<KeyspaceDefinition> keyspaces = cassandraCluster.describeKeyspaces();
// System
// Keyspace1
// system_traces
assertEquals(3,keyspaces.size());
}

@Test
public void testDescribeKeyspace() throws Exception {
KeyspaceDefinition keyspaceDetail = cassandraCluster.describeKeyspace("Keyspace1");
assertNotNull(keyspaceDetail);
assertEquals(22, keyspaceDetail.getCfDefs().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ public void setupCase() throws TTransportException, TException, IllegalArgumentE
cassandraCluster = new ThriftCluster(clusterName, cassandraHostConfigurator);
}

@Test
public void testDescribeKeyspaces() throws Exception {
List<KeyspaceDefinition> keyspaces = cassandraCluster.describeKeyspaces();
// System
// Keyspace1
// system_auth
// system_traces
assertEquals(4,keyspaces.size());
}

@Test
public void testDescribeClusterName() throws Exception {
assertEquals("Test Cluster",cassandraCluster.describeClusterName());
Expand All @@ -74,15 +64,6 @@ public void testDescribeRing() throws Exception {
assertEquals(1, ring.size());
}



@Test
public void testDescribeKeyspace() throws Exception {
KeyspaceDefinition keyspaceDetail = cassandraCluster.describeKeyspace("Keyspace1");
assertNotNull(keyspaceDetail);
assertEquals(22, keyspaceDetail.getCfDefs().size());
}

@Test
public void testDescribePartitioner() throws Exception {
String partitioner = cassandraCluster.describePartitioner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import me.prettyprint.hector.api.Keyspace;

public abstract class BaseColumnFamilyTemplateTest extends BaseEmbededServerSetupTest {

protected Cluster cluster;
protected Keyspace keyspace;
static final StringSerializer se = StringSerializer.get();

@Before
public void setupLocal() {
Cluster cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170");
cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170");
keyspace = createKeyspace("Keyspace1", cluster);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package me.prettyprint.cassandra.service.template;

import static org.junit.Assert.*;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;

import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HSuperColumn;

import org.junit.Test;


public class SuperCfTemplateTest extends BaseColumnFamilyTemplateTest {

public void afterTest() {
cluster.truncate(keyspace.getKeyspaceName(), "Super1");
}

@Test
public void testSuperCfInsertReadTemplate() {
SuperCfTemplate<String, String, String> sTemplate =
Expand Down
Loading

0 comments on commit 8742f88

Please sign in to comment.