Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the EmbeddedServerHelper more dynamic by allowing more parameters in the constructor #230

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
23 changes: 23 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.9</version>
<scope>compile</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>
<groupId>javax.servlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.prettyprint.cassandra.utils.EmbeddedServerTests;

import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.testutils.EmbeddedServerConfigurator;
import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.utils.EstimatedHistogram;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class AdvancedConfiguratorConstructorTest {
static String clusterName = "Alfonso";
static int thriftPort = 2204;
ThriftCluster cassandraCluster;
static EmbeddedServerHelper embedded;


@BeforeClass
public static void testSimpleConfiguratorConstructor() {

EmbeddedServerConfigurator esc = new EmbeddedServerConfigurator();
esc.setFolder("apple/pie");
esc.setClusterName(clusterName);
esc.setThriftPort(thriftPort);

embedded = new EmbeddedServerHelper(esc);
try {
embedded.setup();
}catch (Exception e) {}
}

@AfterClass
public static void teardown() {
try {
embedded.teardown();
}
catch ( Exception e){}
}

@Test
public void testConnection() {
CassandraHostConfigurator chc = new CassandraHostConfigurator();
chc = new CassandraHostConfigurator("localhost:" + thriftPort);

try {
cassandraCluster = new ThriftCluster("Test Cluster", chc);
assertTrue(cassandraCluster.describeClusterName().equals(clusterName));
}
catch(Exception e) {
// Should never have reached here
assertTrue("Exception " + e.toString(),false);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.prettyprint.cassandra.utils.EmbeddedServerTests;

import me.prettyprint.hector.testutils.EmbeddedSchemaLoader;
import me.prettyprint.hector.testutils.EmbeddedServerConfigurator;
import me.prettyprint.hector.testutils.EmbeddedServerHelper;

import org.apache.cassandra.service.EmbeddedCassandraService;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
* @author Felipe Seré
*/
public class DefaultConstructorTest {
public static Logger log = LoggerFactory.getLogger(DefaultConstructorTest.class);

@Test
public void testDefaultConstructor() {

EmbeddedServerHelper embedded = new EmbeddedServerHelper();
try {
embedded.setup();
TimeUnit.SECONDS.sleep(10);
embedded.teardown();

}
catch(Exception e) {
// Should never have reached here
assertTrue("Exception " + e.toString(),false);

}

embedded = null;

assertTrue(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package me.prettyprint.cassandra.utils.EmbeddedServerTests;

import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.testutils.EmbeddedServerConfigurator;
import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import sun.misc.IOUtils;

import java.awt.geom.Path2D;
import java.io.*;
import java.net.URL;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class ExternalYamlConfiguratorConstructorTest {
static String clusterName = "Alfonso";
static int thriftPort = 2204;
ThriftCluster cassandraCluster;
static EmbeddedServerHelper embedded;
static File yamlFile;
private static final String sep = File.separator;
private static final String pathName = sep + "me" + sep + "prettyprint" + sep + "cassandra" + sep + "utils" + sep + "EmbeddedServerTests" + sep + "test-cassandra.yaml";

@BeforeClass
public static void getYamlFile() throws IOException {

// Get the resource
URL resource = ExternalYamlConfiguratorConstructorTest.class.getResource(pathName);
yamlFile = File.createTempFile("test-cassandra","yaml");


// Transfer it to a tempfile for later use
BufferedReader br = new BufferedReader(new InputStreamReader(ExternalYamlConfiguratorConstructorTest.class.getResourceAsStream(pathName)));
PrintWriter pw = new PrintWriter(yamlFile);
String line = null;
while((line = br.readLine()) != null) {
pw.println(line);
}

br.close();
pw.close();

}

@Test
public void constructorTest() {

EmbeddedServerConfigurator esc = EmbeddedServerConfigurator.createFromYaml(yamlFile.getPath());

assertTrue("ClusterName mismatch: esc " + esc.getClusterName() + " and " + clusterName, esc.getClusterName().equals(clusterName));
assertTrue("Thirft port mismatch: esc " + esc.getThriftPort() + " and " + thriftPort , esc.getThriftPort() == thriftPort);
embedded = new EmbeddedServerHelper(esc);
try {
embedded.setup();
}catch (Exception e) {}
}

@AfterClass
public static void teardown() {
try {
embedded.teardown();
}
catch ( Exception e){}
}

@Test
public void testConnection() {
CassandraHostConfigurator chc = new CassandraHostConfigurator();
chc = new CassandraHostConfigurator("localhost:" + thriftPort);

try {
cassandraCluster = new ThriftCluster("Test Cluster", chc);
assertTrue(cassandraCluster.describeClusterName().equals(clusterName));
}
catch(Exception e) {
// Should never have reached here
assertTrue("Exception " + e.toString(),false);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.prettyprint.cassandra.utils.EmbeddedServerTests;

import me.prettyprint.hector.testutils.EmbeddedServerConfigurator;
import me.prettyprint.hector.testutils.EmbeddedServerHelper;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertTrue;

public class SimpleConfiguratorConstructorTest {
@Test
public void testSimpleConfiguratorConstructor() {

EmbeddedServerConfigurator esc = new EmbeddedServerConfigurator();

EmbeddedServerHelper embedded = new EmbeddedServerHelper(esc);
try {
embedded.setup();
TimeUnit.SECONDS.sleep(10);
embedded.teardown();

}
catch(Exception e) {
// Should never have reached here
assertTrue("Exception " + e.toString(),false);

}

embedded = null;

assertTrue(true);
}
}
Loading