Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Tests plumbing - adding libraries and building a test skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
rantav committed Feb 11, 2010
1 parent 6bad8d4 commit a3b567f
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 117 deletions.
128 changes: 84 additions & 44 deletions pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,9 +40,60 @@
</developer> </developer>
</developers> </developers>


<!-- <build>
- relative lib <plugins>
--> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/testlib/google-collections-1.0-rc1.jar</additionalClasspathElement>
<additionalClasspathElement>${basedir}/testlib/clhm-production-1.0.jar</additionalClasspathElement>
<additionalClasspathElement>${basedir}/testlib/flexjson-1.7.jar</additionalClasspathElement>
<additionalClasspathElement>${basedir}/testlib/high-scale-lib-1.0.jar</additionalClasspathElement>
<additionalClasspathElement>${basedir}/testlib/commons-collections-3.0.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<!-- Setup the build for JAVA 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

<!-- Configure the JUnit Env -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>storage-config</name>
<value>${basedir}/src/test/conf</value>
</property>
</systemProperties>
<forkMode>always</forkMode>
</configuration>
</plugin>

<!-- cobertura code coverage reports -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>commons-pool</groupId> <groupId>commons-pool</groupId>
Expand Down Expand Up @@ -98,50 +149,39 @@
<version>4.6</version> <version>4.6</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!--
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0-rc1</version>
<scope>t</scope>
<systemPath>${basedir}/testlib/google-collections-1.0-rc1.jar</systemPath>
</dependency>
<dependency>
<groupId>high-scale-lib</groupId>
<artifactId>high-scale-lib</artifactId>
<version>1.0</version>
<scope>test</scope>
<systemPath>${basedir}/testlib/high-scale-lib-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>flexjson</groupId>
<artifactId>flexjson</artifactId>
<version>1.7</version>
<scope>test</scope>
<systemPath>${basedir}/testlib/flexjson-1.7.jar</systemPath>
</dependency>
<dependency>
<groupId>clhm-production</groupId>
<artifactId>clhm-production</artifactId>
<version>1.0</version>
<scope>test</scope>
<systemPath>${basedir}/testlib/clhm-production-1.0.jar</systemPath>
</dependency>
-->
</dependencies> </dependencies>




<build>
<plugins>
<!-- Setup the build for JAVA 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

<!-- Configure the JUnit Env -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>storage-config</name>
<value>${basedir}/src/test/conf</value>
</property>
</systemProperties>
<forkMode>always</forkMode>
</configuration>
</plugin>

<!-- cobertura code coverage reports -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
</configuration>
</plugin>
</plugins>
</build>


<reporting> <reporting>
<plugins> <plugins>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,10 +2,63 @@


import static org.junit.Assert.*; import static org.junit.Assert.*;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner;
import org.apache.cassandra.service.EmbeddedCassandraService;
import org.apache.cassandra.utils.FileUtils;
import org.apache.thrift.transport.TTransportException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;


/**
*
* @author Ran Tavory (rantav@gmail.com)
*
*/
public class CassandraClientTest { public class CassandraClientTest {


private static EmbeddedCassandraService cassandra;

private static final String TMP = "tmp";

/**
* Set embedded cassandra up and spawn it in a new thread.
*
* @throws TTransportException
* @throws IOException
* @throws InterruptedException
*/
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException {
// delete tmp dir first
rmdir(TMP);
// make a tmp dir and copy storag-conf.xml and log4j.properties to it
copy("/storage-conf.xml", TMP);
copy("/log4j.properties", TMP);
System.setProperty("storage-config", TMP);

CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner();
cleaner.prepare();
cassandra = new EmbeddedCassandraService();
cassandra.init();
Thread t = new Thread(cassandra);
t.setDaemon(true);
t.start();
}

@AfterClass
public static void teardown() throws IOException {
CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner();
cleaner.cleanupDataDirectories();
rmdir(TMP);
}

@Test @Test
public void testGetKeySpaceString() { public void testGetKeySpaceString() {
fail("Not yet implemented"); fail("Not yet implemented");
Expand Down Expand Up @@ -41,4 +94,41 @@ public void testGetConfigFile() {
fail("Not yet implemented"); fail("Not yet implemented");
} }


private static void rmdir(String dir) throws IOException {
File dirFile = new File(dir);
if (dirFile.exists()) {
FileUtils.deleteDir(new File(dir));
}
}
/**
* Copies a resource from within the jar to a directory.
*
* @param resourceName
* @param directory
* @throws IOException
*/
private static void copy(String resource, String directory) throws IOException {
mkdir(directory);
InputStream is = CassandraClientTest.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);
}

} }
14 changes: 7 additions & 7 deletions src/test/resources/log4j.properties
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.


# for production, you should probably set the root to INFO
# and the pattern to %c instead of %l. (%l is slower.)


log4j.rootLogger=DEBUG,R # output messages into a rolling log file as well as stdout
log4j.rootLogger=DEBUG,stdout


# rolling log file ("system.log # stdout
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.R.DatePattern='.'yyyy-MM-dd-HH log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
log4j.appender.R.File=build/test/logs/system.log
Loading

0 comments on commit a3b567f

Please sign in to comment.