Browse files

fix for issue #223, cassandra-all should be a test dependency

  • Loading branch information...
1 parent 7c57f0d commit 1406c96843a59b618e69e0f6a2d045cec5ad8a18 @sbridges sbridges committed Aug 11, 2011
View
12 core/pom.xml
@@ -3,7 +3,7 @@
<parent>
<groupId>me.prettyprint</groupId>
<artifactId>hector</artifactId>
- <version>0.8.0-2-SNAPSHOT</version>
+ <version>0.8.0-3-SNAPSHOT</version>
</parent>
<artifactId>hector-core</artifactId>
<packaging>bundle</packaging>
@@ -104,17 +104,19 @@
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
- <artifactId>cassandra-all</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-thrift</artifactId>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
</dependency>
<dependency>
+ <groupId>me.prettyprint</groupId>
+ <artifactId>hector-test</artifactId>
+ <version>${pom.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.6</version>
View
22 core/src/main/java/me/prettyprint/cassandra/connection/BackgroundCassandraHostService.java
@@ -7,6 +7,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.cassandra.utils.DaemonThreadPoolFactory;
public abstract class BackgroundCassandraHostService {
@@ -20,7 +21,7 @@
public BackgroundCassandraHostService(HConnectionManager connectionManager,
CassandraHostConfigurator cassandraHostConfigurator) {
- executor = Executors.newScheduledThreadPool(1, new DaemonThreadPoolFactory("Hector." + getClass().getSimpleName() + "Thread"));
+ executor = Executors.newScheduledThreadPool(1, new DaemonThreadPoolFactory(getClass()));
this.connectionManager = connectionManager;
this.cassandraHostConfigurator = cassandraHostConfigurator;
@@ -40,24 +41,7 @@ public void setRetryDelayInSeconds(int retryDelayInSeconds) {
this.retryDelayInSeconds = retryDelayInSeconds;
}
- private static class DaemonThreadPoolFactory implements ThreadFactory {
-
- private static final AtomicInteger count = new AtomicInteger();
- private final String name;
-
- public DaemonThreadPoolFactory(String name) {
- this.name = name;
- }
-
- @Override
- public Thread newThread(Runnable r) {
- Thread t = new Thread(r);
- t.setDaemon(true);
- t.setName(name + "-" + count.incrementAndGet());
- return t;
- }
-
- }
+
}
View
21 core/src/main/java/me/prettyprint/cassandra/connection/DynamicLoadBalancingPolicy.java
@@ -8,11 +8,13 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import me.prettyprint.cassandra.service.CassandraHost;
+import me.prettyprint.cassandra.utils.DaemonThreadPoolFactory;
-import org.apache.cassandra.concurrent.RetryingScheduledThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,7 +31,8 @@
private static final long serialVersionUID = -1044985880174118325L;
private static final Logger log = LoggerFactory.getLogger(DynamicLoadBalancingPolicy.class);
- public static RetryingScheduledThreadPoolExecutor tasks = new RetryingScheduledThreadPoolExecutor("BGTasks");
+
+ private final ScheduledExecutorService tasks = new ScheduledThreadPoolExecutor(1, new DaemonThreadPoolFactory(getClass()));
// references which is used to make the real time requests faster.
private Map<HClientPool, Double> scores = Maps.newConcurrentMap();
@@ -45,15 +48,23 @@ public DynamicLoadBalancingPolicy() {
// Pre-calculate the scores so as we can compare it fast.
Runnable updateThread = new Runnable() {
public void run() {
- updateScores();
+ try {
+ updateScores();
+ } catch(Exception e) {
+ log.info("exception updating scores", e);
+ }
}
};
// Clear Stats.
Runnable resetThread = new Runnable() {
public void run() {
- for (LatencyAwareHClientPool pool : allPools) {
- pool.clear();
+ try {
+ for (LatencyAwareHClientPool pool : allPools) {
+ pool.clear();
+ }
+ } catch(Exception e) {
+ log.info("exceotuib reseting stats", e);
}
}
};
View
32 core/src/main/java/me/prettyprint/cassandra/constants/CFMetaDataDefaults.java
@@ -0,0 +1,32 @@
+package me.prettyprint.cassandra.constants;
+
+/**
+ * Defaults
+ */
+public class CFMetaDataDefaults {
+ public final static double DEFAULT_ROW_CACHE_SIZE = 0.0;
+ public final static double DEFAULT_KEY_CACHE_SIZE = 200000;
+ public final static double DEFAULT_READ_REPAIR_CHANCE = 1.0;
+ public final static boolean DEFAULT_REPLICATE_ON_WRITE = true;
+ public final static int DEFAULT_SYSTEM_MEMTABLE_THROUGHPUT_IN_MB = 8;
+ public final static int DEFAULT_ROW_CACHE_SAVE_PERIOD_IN_SECONDS = 0;
+ public final static int DEFAULT_KEY_CACHE_SAVE_PERIOD_IN_SECONDS = 4 * 3600;
+ public final static int DEFAULT_GC_GRACE_SECONDS = 864000;
+ public final static int DEFAULT_MIN_COMPACTION_THRESHOLD = 4;
+ public final static int DEFAULT_MAX_COMPACTION_THRESHOLD = 32;
+ public final static int DEFAULT_MEMTABLE_LIFETIME_IN_MINS = 60 * 24;
+ public final static double DEFAULT_MERGE_SHARDS_CHANCE = 0.1;
+ //this defaults to ram / 16 / 1MB on the server
+ //but we are on the client, so we don't know how much
+ //ram is on the server, assume a conservative 8G
+ public final static int DEFAULT_MEMTABLE_THROUGHPUT_IN_MB = 500;
+ public final static double DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS =
+ sizeMemtableOperations(DEFAULT_MEMTABLE_THROUGHPUT_IN_MB);
+
+
+ private static double sizeMemtableOperations(int mem_throughput)
+ {
+ return 0.3 * mem_throughput / 64.0;
+ }
+
+}
View
42 core/src/main/java/me/prettyprint/cassandra/service/ThriftCfDef.java
@@ -10,7 +10,7 @@
import me.prettyprint.hector.api.ddl.ColumnType;
import me.prettyprint.hector.api.ddl.ComparatorType;
-import org.apache.cassandra.config.CFMetaData;
+import me.prettyprint.cassandra.constants.CFMetaDataDefaults;
import org.apache.cassandra.thrift.CfDef;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -59,15 +59,15 @@ public ThriftCfDef(CfDef d) {
defaultValidationClass = d.default_validation_class;
id = d.id;
minCompactionThreshold = d.min_compaction_threshold == 0 ?
- CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD : d.min_compaction_threshold;
+ CFMetaDataDefaults.DEFAULT_MIN_COMPACTION_THRESHOLD : d.min_compaction_threshold;
maxCompactionThreshold = d.max_compaction_threshold == 0 ?
- CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD : d.max_compaction_threshold;
+ CFMetaDataDefaults.DEFAULT_MAX_COMPACTION_THRESHOLD : d.max_compaction_threshold;
memtableOperationsInMillions = d.memtable_operations_in_millions == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS : d.memtable_operations_in_millions;
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS : d.memtable_operations_in_millions;
memtableFlushAfterMins = d.memtable_flush_after_mins == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_LIFETIME_IN_MINS : d.memtable_flush_after_mins;
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_LIFETIME_IN_MINS : d.memtable_flush_after_mins;
memtableThroughputInMb = d.memtable_throughput_in_mb == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB : d.memtable_throughput_in_mb;
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB : d.memtable_throughput_in_mb;
replicateOnWrite = d.replicate_on_write;
}
@@ -90,15 +90,15 @@ public ThriftCfDef(ColumnFamilyDefinition columnFamilyDefinition) {
defaultValidationClass = columnFamilyDefinition.getDefaultValidationClass();
id = columnFamilyDefinition.getId();
minCompactionThreshold = columnFamilyDefinition.getMinCompactionThreshold() == 0 ?
- CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD : columnFamilyDefinition.getMinCompactionThreshold();
+ CFMetaDataDefaults.DEFAULT_MIN_COMPACTION_THRESHOLD : columnFamilyDefinition.getMinCompactionThreshold();
maxCompactionThreshold = columnFamilyDefinition.getMaxCompactionThreshold() == 0 ?
- CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD : columnFamilyDefinition.getMaxCompactionThreshold();
+ CFMetaDataDefaults.DEFAULT_MAX_COMPACTION_THRESHOLD : columnFamilyDefinition.getMaxCompactionThreshold();
memtableFlushAfterMins = columnFamilyDefinition.getMemtableFlushAfterMins() == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_LIFETIME_IN_MINS : columnFamilyDefinition.getMemtableFlushAfterMins();
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_LIFETIME_IN_MINS : columnFamilyDefinition.getMemtableFlushAfterMins();
memtableThroughputInMb = columnFamilyDefinition.getMemtableThroughputInMb() == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB : columnFamilyDefinition.getMemtableThroughputInMb();
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB : columnFamilyDefinition.getMemtableThroughputInMb();
memtableOperationsInMillions = columnFamilyDefinition.getMemtableOperationsInMillions() == 0 ?
- CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS : columnFamilyDefinition.getMemtableOperationsInMillions();
+ CFMetaDataDefaults.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS : columnFamilyDefinition.getMemtableOperationsInMillions();
replicateOnWrite = columnFamilyDefinition.isReplicateOnWrite();
}
@@ -109,16 +109,16 @@ public ThriftCfDef(String keyspace, String columnFamilyName) {
columnType = ColumnType.STANDARD;
comparatorType = ComparatorType.BYTESTYPE;
- readRepairChance = CFMetaData.DEFAULT_READ_REPAIR_CHANCE;
- keyCacheSize = CFMetaData.DEFAULT_KEY_CACHE_SIZE;
- keyCacheSavePeriodInSeconds = CFMetaData.DEFAULT_KEY_CACHE_SAVE_PERIOD_IN_SECONDS;
- gcGraceSeconds = CFMetaData.DEFAULT_GC_GRACE_SECONDS;
- minCompactionThreshold = CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD;
- maxCompactionThreshold = CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD;
- memtableFlushAfterMins = CFMetaData.DEFAULT_MEMTABLE_LIFETIME_IN_MINS;
- memtableThroughputInMb = CFMetaData.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB;
- memtableOperationsInMillions = CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS;
- replicateOnWrite = CFMetaData.DEFAULT_REPLICATE_ON_WRITE;
+ readRepairChance = CFMetaDataDefaults.DEFAULT_READ_REPAIR_CHANCE;
+ keyCacheSize = CFMetaDataDefaults.DEFAULT_KEY_CACHE_SIZE;
+ keyCacheSavePeriodInSeconds = CFMetaDataDefaults.DEFAULT_KEY_CACHE_SAVE_PERIOD_IN_SECONDS;
+ gcGraceSeconds = CFMetaDataDefaults.DEFAULT_GC_GRACE_SECONDS;
+ minCompactionThreshold = CFMetaDataDefaults.DEFAULT_MIN_COMPACTION_THRESHOLD;
+ maxCompactionThreshold = CFMetaDataDefaults.DEFAULT_MAX_COMPACTION_THRESHOLD;
+ memtableFlushAfterMins = CFMetaDataDefaults.DEFAULT_MEMTABLE_LIFETIME_IN_MINS;
+ memtableThroughputInMb = CFMetaDataDefaults.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB;
+ memtableOperationsInMillions = CFMetaDataDefaults.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS;
+ replicateOnWrite = CFMetaDataDefaults.DEFAULT_REPLICATE_ON_WRITE;
}
public ThriftCfDef(String keyspace, String columnFamilyName, ComparatorType comparatorType) {
View
33 core/src/main/java/me/prettyprint/cassandra/utils/DaemonThreadPoolFactory.java
@@ -0,0 +1,33 @@
+package me.prettyprint.cassandra.utils;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DaemonThreadPoolFactory implements ThreadFactory {
+
+ private ConcurrentHashMap<String, AtomicInteger> counters =
+ new ConcurrentHashMap<String, AtomicInteger>();
+
+ private final String name;
+
+ public DaemonThreadPoolFactory(Class<?> parentClass) {
+ this.name = "Hector." + parentClass.getName();
+ }
+
+ private int getNextThreadNumber() {
+ if(!counters.containsKey(name)) {
+ counters.putIfAbsent(name, new AtomicInteger());
+ }
+ return counters.get(name).incrementAndGet();
+ }
+
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r);
+ t.setDaemon(true);
+ t.setName(name + "-" + getNextThreadNumber());
+ return t;
+ }
+
+}
View
7 core/src/main/java/me/prettyprint/hector/api/beans/AbstractComposite.java
@@ -30,10 +30,10 @@
import me.prettyprint.cassandra.utils.ByteBufferOutputStream;
import me.prettyprint.hector.api.Serializer;
-import org.apache.cassandra.utils.ByteBufferUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
@@ -370,7 +370,8 @@ private String getComparator(int i, ByteBuffer bb) {
try {
int header = getShortLength(bb);
if ((header & 0x8000) == 0) {
- name = ByteBufferUtil.string(getBytes(bb, header));
+
+ name = Charsets.UTF_8.newDecoder().decode(getBytes(bb, header).duplicate()).toString();
} else {
byte a = (byte) (header & 0xFF);
name = aliasToComparatorMapping.get(a);
@@ -667,7 +668,7 @@ public ByteBuffer serialize() {
out.writeShort((short) (0x8000 | a));
} else {
out.writeShort((short) comparator.length());
- out.write(ByteBufferUtil.bytes(comparator));
+ out.write(ByteBuffer.wrap(comparator.getBytes(Charsets.UTF_8)));
}
// if (comparator.equals(BYTESTYPE.getTypeName()) && (cb.remaining() ==
// 0)) {
View
2 core/src/test/java/me/prettyprint/cassandra/BaseEmbededServerSetupTest.java
@@ -4,7 +4,7 @@
import me.prettyprint.cassandra.connection.HConnectionManager;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
-import me.prettyprint.cassandra.testutils.EmbeddedServerHelper;
+import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
View
2 core/src/test/java/me/prettyprint/cassandra/examples/ExampleDaoV2Test.java
@@ -11,9 +11,9 @@
import java.util.Map;
import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.testutils.EmbeddedServerHelper;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.exceptions.HectorException;
+import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
View
1 core/src/test/java/me/prettyprint/cassandra/model/RangeSlicesCounterQueryTest.java
@@ -13,6 +13,7 @@
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.RangeSlicesCounterQuery;
import me.prettyprint.hector.api.query.RangeSlicesQuery;
+
import org.junit.Before;
import org.junit.Test;
View
2 core/src/test/java/me/prettyprint/cassandra/service/CassandraAuthTest.java
@@ -22,12 +22,12 @@
import me.prettyprint.cassandra.connection.HConnectionManager;
import me.prettyprint.cassandra.model.QuorumAllConsistencyLevelPolicy;
import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.testutils.EmbeddedServerHelper;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.io.util.FileUtils;
View
1 core/src/test/java/me/prettyprint/cassandra/utils/TimeUUIDUtilsTest.java
@@ -6,7 +6,6 @@
import java.util.Date;
import java.util.UUID;
-import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.cassandra.service.clock.MicrosecondsClockResolution;
import me.prettyprint.cassandra.service.clock.MicrosecondsSyncClockResolution;
import me.prettyprint.hector.api.ClockResolution;
View
11 object-mapper/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>me.prettyprint</groupId>
<artifactId>hector</artifactId>
- <version>0.8.0-2-SNAPSHOT</version>
+ <version>0.8.0-3-SNAPSHOT</version>
</parent>
<artifactId>hector-object-mapper</artifactId>
<name>hector-object-mapper</name>
@@ -40,7 +40,7 @@
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
- <version>0.8.0-2-SNAPSHOT</version>
+ <version>0.8.0-3-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -51,8 +51,13 @@
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
+ </dependency>
+ <dependency>
+ <groupId>me.prettyprint</groupId>
+ <artifactId>hector-test</artifactId>
+ <version>0.8.0-3-SNAPSHOT</version>
+ <scope>test</scope>
</dependency>
-
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
View
9 object-mapper/src/main/java/me/prettyprint/hom/CFMappingDef.java
@@ -12,9 +12,9 @@
import javax.persistence.Entity;
import javax.persistence.InheritanceType;
-import me.prettyprint.hom.cache.HectorObjectMapperException;
+import com.google.common.collect.Sets;
-import org.apache.commons.collections.collection.CompositeCollection;
+import me.prettyprint.hom.cache.HectorObjectMapperException;
/**
* Holder for the mapping between a Class annotated with {@link Entity} and the
@@ -183,8 +183,9 @@ public KeyDefinition getKeyDef() {
if (null == cfSuperMapDef) {
allMappedProps = propSet;
} else {
- allMappedProps = new CompositeCollection(
- new Collection[] { propSet, cfSuperMapDef.getAllProperties() });
+ allMappedProps = Sets.union(
+ propSet, (Set) cfSuperMapDef.getAllProperties()
+ );
}
}
View
2 object-mapper/src/test/java/me/prettyprint/hom/CassandraTestBase.java
@@ -8,10 +8,10 @@
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.cassandra.service.ThriftKsDef;
-import me.prettyprint.cassandra.testutils.EmbeddedServerHelper;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner;
View
3 pom.xml
@@ -10,7 +10,7 @@
<groupId>me.prettyprint</groupId>
<artifactId>hector</artifactId>
<packaging>pom</packaging>
- <version>0.8.0-2-SNAPSHOT</version>
+ <version>0.8.0-3-SNAPSHOT</version>
<name>hector</name>
<description>Cassandra Java Client Library</description>
<url>http://github.com/rantav/hector</url>
@@ -81,6 +81,7 @@
<modules>
<module>core</module>
<module>object-mapper</module>
+ <module>test</module>
</modules>
<dependencyManagement>
View
292 test/pom.xml
@@ -0,0 +1,292 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>me.prettyprint</groupId>
+ <artifactId>hector</artifactId>
+ <version>0.8.0-3-SNAPSHOT</version>
+ </parent>
+ <artifactId>hector-test</artifactId>
+ <packaging>jar</packaging>
+ <name>test</name>
+ <properties>
+ <!-- OSGi bundle properties -->
+ <bundle.symbolicName>me.prettyprint.hector</bundle.symbolicName>
+ <bundle.namespace>me.prettyprint</bundle.namespace>
+ </properties>
+
+ <build>
+ <plugins>
+
+ <!--
+ run examples thusly: mvn exec:java
+ -Dexec.mainClass="me.prettyprint.cassandra.examples.ExampleDao"
+ -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.ops4j</groupId>
+ <artifactId>maven-pax-plugin</artifactId>
+ <version>1.4</version>
+ <configuration>
+ <provision>
+ <param>--platform=equinox</param>
+ </provision>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
+ <Bundle-Version>${pom.version}</Bundle-Version>
+ <Embed-Dependency>
+ libthrift;scope=compile|runtime;type=!pom;inline=false,
+ cassandra;scope=compile|runtime;type=!pom;inline=false,
+ <!-- *;scope=compile|runtime;type=!pom;inline=false -->
+ </Embed-Dependency>
+
+ <Export-Package>
+ <!-- !${bundle.namespace}.internal.*, -->
+ ${bundle.namespace}.*;version="${pom.version}"
+ </Export-Package>
+
+ <Import-Package>
+ !org.apache.avro.*,
+ !javax.jms.*,
+ !javax.mail.*,
+ !javax.servlet.*,
+ !com.sun.*,
+ !org.antlr.*,
+ !jline.*,
+ !sun.misc.*,
+ *;resolution:=optional
+ </Import-Package>
+ <Private-Package>
+ <!-- ${bundle.namespace}.internal.* -->
+ </Private-Package>
+ <_include>-osgi.bnd</_include>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>always</forkMode>
+ <argLine>-Xmx512M -Xms512M -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.5.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cassandra</groupId>
+ <artifactId>cassandra-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cassandra</groupId>
+ <artifactId>cassandra-thrift</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.thrift</groupId>
+ <artifactId>libthrift</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>r08</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cassandra.deps</groupId>
+ <artifactId>avro</artifactId>
+ <version>1.4.0-cassandra-1</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>netty</artifactId>
+ <groupId>org.jboss.netty</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>paranamer</artifactId>
+ <groupId>com.thoughtworks.paranamer</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>paranamer-ant</artifactId>
+ <groupId>com.thoughtworks.paranamer</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>velocity</artifactId>
+ <groupId>org.apache.velocity</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <version>3.1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
+ <artifactId>concurrentlinkedhashmap-lru</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.github.stephenc.high-scale-lib</groupId>
+ <artifactId>high-scale-lib</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cassandra</groupId>
+ <artifactId>cassandra-javautils</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.github.stephenc.eaio-uuid</groupId>
+ <artifactId>uuid</artifactId>
+ <version>3.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ecyrd.speed4j</groupId>
+ <artifactId>speed4j</artifactId>
+ <version>0.9</version>
+ </dependency>
+
+ <!-- Note the optional tag. If you need to use fastinfoset serialization, you must include this dependency in your project! -->
+ <dependency>
+ <artifactId>FastInfoset</artifactId>
+ <groupId>com.sun.xml.fastinfoset</groupId>
+ <version>1.2.2</version>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- OSGi deps -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_core</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_compendium</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${org.springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${org.springframework.version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${org.springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>riptano</id>
+ <distributionManagement>
+ <repository>
+ <id>riptano</id>
+ <name>riptano</name>
+ <url>http://mvn.riptano.com/content/repositories/public/</url>
+ </repository>
+ </distributionManagement>
+ </profile>
+ </profiles>
+ <repositories>
+ <repository>
+ <id>riptano</id>
+ <name>riptano</name>
+ <url>http://mvn.riptano.com/content/repositories/public/</url>
+ </repository>
+ <repository>
+ <id>apache-staging</id>
+ <name>apache-staging</name>
+ <url>https://repository.apache.org/content/repositories/orgapachecassandra-114</url>
+ </repository>
+ </repositories>
+</project>
View
146 test/src/main/java/me/prettyprint/hector/testutils/EmbeddedSchemaLoader.java
@@ -0,0 +1,146 @@
+package me.prettyprint.hector.testutils;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.db.ColumnFamilyType;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.AsciiType;
+import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.CompositeType;
+import org.apache.cassandra.db.marshal.CounterColumnType;
+import org.apache.cassandra.db.marshal.IntegerType;
+import org.apache.cassandra.db.marshal.LongType;
+import org.apache.cassandra.db.marshal.TimeUUIDType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.SimpleStrategy;
+import org.apache.cassandra.thrift.IndexType;
+
+import com.google.common.base.Charsets;
+
+public class EmbeddedSchemaLoader {
+ public static void loadSchema() {
+ try {
+ for (KSMetaData ksm : schemaDefinition()) {
+ for (CFMetaData cfm : ksm.cfMetaData().values())
+ CFMetaData.map(cfm);
+ DatabaseDescriptor.setTableDefinition(ksm, DatabaseDescriptor
+ .getDefsVersion());
+ }
+ } catch (ConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Collection<KSMetaData> schemaDefinition() {
+ List<KSMetaData> schema = new ArrayList<KSMetaData>();
+
+ // A whole bucket of shorthand
+ String ks1 = "Keyspace1";
+ String ks2 = "Keyspace2";
+
+ Class<? extends AbstractReplicationStrategy> simple = SimpleStrategy.class;
+ Map<String, String> opts = new HashMap<String, String>();
+ opts.put("replication_factor", Integer.toString(1));
+
+ ColumnFamilyType st = ColumnFamilyType.Standard;
+ ColumnFamilyType su = ColumnFamilyType.Super;
+ AbstractType bytes = BytesType.instance;
+
+ List<AbstractType> subComparators = new ArrayList<AbstractType>();
+ subComparators.add(BytesType.instance);
+ subComparators.add(TimeUUIDType.instance);
+ subComparators.add(IntegerType.instance);
+
+ // Keyspace 1
+ schema.add(new KSMetaData(
+ ks1,
+ simple,
+ opts,
+
+ // Column Families
+ standardCFMD(ks1, "Standard1"), standardCFMD(ks1, "Standard2"),
+ standardCFMD(ks1, "Standard3"), standardCFMD(ks1, "Standard4"),
+ cqlTestCf(ks1, "StandardLong1",UTF8Type.instance),
+ standardCFMD(ks1, "StandardLong2").keyValidator(UTF8Type.instance),
+ superCFMD(ks1, "Super1", BytesType.instance),
+ superCFMD(ks1, "Super2", LongType.instance),
+ superCFMD(ks1, "Super3", LongType.instance),
+ superCFMD(ks1, "Super4", UTF8Type.instance),
+ superCFMD(ks1, "Super5", bytes),
+ indexCFMD(ks1, "Indexed1", true),
+ indexCFMD(ks1, "Indexed2", false),
+ new CFMetaData(ks1, "StandardInteger1", st, IntegerType.instance, null).keyCacheSize(0),
+ new CFMetaData(ks1, "Counter1", st, bytes, null).replicateOnWrite(true).defaultValidator(CounterColumnType.instance),
+ new CFMetaData(ks1, "Counter2", st, bytes, null).replicateOnWrite(true).defaultValidator(CounterColumnType.instance),
+ new CFMetaData(ks1, "SuperCounter1", su, bytes, bytes).replicateOnWrite(true).defaultValidator(CounterColumnType.instance),
+ jdbcCFMD(ks1, "JdbcInteger", IntegerType.instance),
+ jdbcCFMD(ks1, "JdbcUtf8", UTF8Type.instance),
+ jdbcCFMD(ks1, "JdbcLong", LongType.instance),
+ jdbcCFMD(ks1, "JdbcBytes", bytes),
+ jdbcCFMD(ks1, "JdbcAscii", AsciiType.instance)));
+
+ // Keyspace 2
+
+ return schema;
+ }
+
+ private static CFMetaData compositeCFMD(String ksName, String cfName, AbstractType... types) {
+ try {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null);
+ } catch (ConfigurationException e) {
+
+ }
+ return null;
+ }
+
+ private static CFMetaData standardCFMD(String ksName, String cfName) {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard,
+ BytesType.instance, null).keyCacheSize(0);
+ }
+
+ private static CFMetaData superCFMD(String ksName, String cfName,
+ AbstractType subcc) {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Super,
+ BytesType.instance, subcc).keyCacheSize(0);
+ }
+
+ private static CFMetaData indexCFMD(String ksName, String cfName, final Boolean withIdxType)
+ {
+ return standardCFMD(ksName, cfName)
+ .columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
+ {{
+ ByteBuffer cName = ByteBuffer.wrap("birthyear".getBytes(Charsets.UTF_8));
+ IndexType keys = withIdxType ? IndexType.KEYS : null;
+ put(cName, new ColumnDefinition(cName, LongType.instance, keys, null));
+ }});
+ }
+
+ private static CFMetaData jdbcCFMD(String ksName, String cfName,
+ AbstractType comp) {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null)
+ .defaultValidator(comp);
+ }
+
+ private static CFMetaData cqlTestCf(String ksName, String cfName,
+ AbstractType comp) {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null)
+ .keyValidator(UTF8Type.instance).columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
+ {{
+ ByteBuffer cName = ByteBuffer.wrap("birthyear".getBytes(Charsets.UTF_8));
+ put(cName, new ColumnDefinition(cName, LongType.instance, null, null));
+ }});
+ }
+}
+
View
193 test/src/main/java/me/prettyprint/hector/testutils/EmbeddedServerHelper.java
@@ -0,0 +1,193 @@
+package me.prettyprint.hector.testutils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.commitlog.CommitLog;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.thrift.CassandraDaemon;
+import org.apache.thrift.transport.TTransportException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Ran Tavory (rantav@gmail.com)
+ *
+ */
+public class EmbeddedServerHelper {
+ private static Logger log = LoggerFactory.getLogger(EmbeddedServerHelper.class);
+
+ private static final String TMP = "tmp";
+
+ private final String yamlFile;
+ static CassandraDaemon cassandraDaemon;
+
+ public EmbeddedServerHelper() {
+ this("/cassandra.yaml");
+ }
+
+ public EmbeddedServerHelper(String yamlFile) {
+ this.yamlFile = yamlFile;
+ }
+
+ static ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ /**
+ * Set embedded cassandra up and spawn it in a new thread.
+ *
+ * @throws TTransportException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public void setup() throws TTransportException, IOException,
+ InterruptedException, ConfigurationException {
+ // delete tmp dir first
+ rmdir(TMP);
+ // make a tmp dir and copy cassandra.yaml and log4j.properties to it
+ copy("/log4j.properties", TMP);
+ copy(yamlFile, TMP);
+ System.setProperty("cassandra.config", "file:" + TMP + yamlFile);
+ System.setProperty("log4j.configuration", "file:" + TMP + "/log4j.properties");
+ System.setProperty("cassandra-foreground","true");
+
+ cleanupAndLeaveDirs();
+ loadSchemaFromYaml();
+ //loadYamlTables();
+ log.info("Starting executor");
+
+ executor.execute(new CassandraRunner());
+ log.info("Started executor");
+ try
+ {
+ TimeUnit.SECONDS.sleep(3);
+ log.info("Done sleeping");
+ }
+ catch (InterruptedException e)
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+
+
+ public static void teardown() {
+ //if ( cassandraDaemon != null )
+ //cassandraDaemon.stop();
+ executor.shutdown();
+ executor.shutdownNow();
+ log.info("Teardown complete");
+ }
+
+ private static void rmdir(String dir) throws IOException {
+ File dirFile = new File(dir);
+ if (dirFile.exists()) {
+ FileUtils.deleteRecursive(new File(dir));
+ }
+ }
+
+ /**
+ * Copies a resource from within the jar to a directory.
+ *
+ * @param resource
+ * @param directory
+ * @throws IOException
+ */
+ private static void copy(String resource, String directory)
+ throws IOException {
+ mkdir(directory);
+ InputStream is = EmbeddedServerHelper.class.getResourceAsStream(resource);
+ String fileName = resource.substring(resource.lastIndexOf("/") + 1);
+ File file = new File(directory + System.getProperty("file.separator")
+ + fileName);
+ OutputStream out = new FileOutputStream(file);
+ byte buf[] = new byte[1024];
+ int len;
+ while ((len = is.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ is.close();
+ }
+
+ /**
+ * Creates a directory
+ *
+ * @param dir
+ * @throws IOException
+ */
+ private static void mkdir(String dir) throws IOException {
+ FileUtils.createDirectory(dir);
+ }
+
+
+ public static void cleanupAndLeaveDirs() throws IOException
+ {
+ mkdirs();
+ cleanup();
+ mkdirs();
+ CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this brings it back to safe state
+ }
+
+ public static void cleanup() throws IOException
+ {
+ // clean up commitlog
+ String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), };
+ for (String dirName : directoryNames)
+ {
+ File dir = new File(dirName);
+ if (!dir.exists())
+ throw new RuntimeException("No such directory: " + dir.getAbsolutePath());
+ FileUtils.deleteRecursive(dir);
+ }
+
+ // clean up data directory which are stored as data directory/table/data files
+ for (String dirName : DatabaseDescriptor.getAllDataFileLocations())
+ {
+ File dir = new File(dirName);
+ if (!dir.exists())
+ throw new RuntimeException("No such directory: " + dir.getAbsolutePath());
+ FileUtils.deleteRecursive(dir);
+ }
+ }
+
+ public static void mkdirs()
+ {
+ try
+ {
+ DatabaseDescriptor.createAllDirectories();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void loadSchemaFromYaml()
+ {
+ EmbeddedSchemaLoader.loadSchema();
+
+ }
+
+
+ class CassandraRunner implements Runnable {
+
+ @Override
+ public void run() {
+
+ cassandraDaemon = new CassandraDaemon();
+
+ cassandraDaemon.activate();
+
+ }
+
+ }
+}

0 comments on commit 1406c96

Please sign in to comment.