本文整理汇总了Java中org.cassandraunit.utils.EmbeddedCassandraServerHelper类的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedCassandraServerHelper类的具体用法?Java EmbeddedCassandraServerHelper怎么用?Java EmbeddedCassandraServerHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmbeddedCassandraServerHelper类属于org.cassandraunit.utils包,在下文中一共展示了EmbeddedCassandraServerHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: before
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
if (runtimeMode == RuntimeMode.REQUIRE_RUNNING_INSTANCE) {
if (!CassandraSocket.isConnectable(getHost(), getPort())) {
throw new AssumptionViolatedException(
String.format("Cassandra is not reachable at %s:%s.", getHost(), getPort()));
}
}
if (runtimeMode == RuntimeMode.EMBEDDED_IF_NOT_RUNNING) {
if (CassandraSocket.isConnectable(getHost(), getPort())) {
return;
}
}
EmbeddedCassandraServerHelper.startEmbeddedCassandra("embedded-cassandra.yaml");
super.before();
}
示例2: startServer
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException {
if (! started) {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_UNIT_RANDOM_PORT_YAML, CASSANDRA_TIMEOUT);
Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(getNativeTransportPort()).build();
Session session = cluster.connect();
String createQuery = "CREATE KEYSPACE " + CASSANDRA_UNIT_KEYSPACE + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1}";
session.execute(createQuery);
String useKeyspaceQuery = "USE " + CASSANDRA_UNIT_KEYSPACE;
session.execute(useKeyspaceQuery);
CQLDataLoader dataLoader = new CQLDataLoader(session);
applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
started = true;
}
}
示例3: stop
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
/**
* Stops the server
*/
public static void stop() {
LOG.info("Checking if the Cassandra server can be stopped");
// stop the server only if there is a server running
if (serverRunning.compareAndSet(true, false)) {
LOG.info("Stopping the Cassandra server");
// clear all data from the cluster
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
// close the cluster and all sessions, and shutdown the embedded server
session.getCluster().close();
LOG.info("Cassandra server stopped");
} else
LOG.info("Cassandra server not running");
}
示例4: startServer
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9142).build();
Session session = cluster.connect();
CQLDataLoader dataLoader = new CQLDataLoader(session);
dataLoader.load(new ClassPathCQLDataSet("config/cql/create-tables.cql", true, "cassandra_unit_keyspace"));
}
示例5: ensureMockCassandraRunningAndEstablished
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
/**
* Ensures that the Mock Cassandra instance is up and running. Will reinit
* the database every time it is called.
*
* @param cassandraKeyspace Cassandra keyspace to setup.
* @return A cluster object.
* @throws ConfigurationException
* @throws IOException
* @throws InterruptedException
* @throws TTransportException
*/
public static Cluster ensureMockCassandraRunningAndEstablished(String cassandraKeyspace) throws ConfigurationException, IOException, InterruptedException, TTransportException
{
Cluster cluster;
long timeout = 60000;
EmbeddedCassandraServerHelper.startEmbeddedCassandra(timeout);
cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
//Thread.sleep(20000);//time to let cassandra startup
final Metadata metadata = cluster.getMetadata();
Session session = cluster.connect();
Utils.initDatabase(DB_CQL, session);
session = cluster.connect(cassandraKeyspace);
logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
return cluster;
}
示例6: test
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@Test
public void test() throws Exception {
CassandraConnector connector = new CassandraConnector();
connector.setHosts(new String[] { EmbeddedCassandraServerHelper.getHost() });
connector.setPort(server.getNativePort());
connector.setKeyspace(null);
connector.init();
ResultSet rs = connector.session().execute("select release_version from system.local");
Row row = rs.one();
row.getString("release_version");
Assert.assertEquals(row.getString("release_version"), "3.11.0");
connector.session().execute("CREATE KEYSPACE gcplot WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
connector.destroy();
connector = new CassandraConnector();
connector.setHosts(new String[] { EmbeddedCassandraServerHelper.getHost() });
connector.setPort(server.getNativePort());
connector.setKeyspace("gcplot");
connector.init();
connector.destroy();
}
示例7: setUp
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeMethod(groups = {"system"})
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
// default to using cassandra on localhost, but can be overridden with a system property
String cassandraHostsString = System.getProperty(CASSANDRA_HOSTS_SYSTEM_PROPERTY, LOCALHOST_IP);
String[] cassandraHosts = StringUtils.split(cassandraHostsString, ',');
Cluster.Builder clusterBuilder = Cluster.builder();
for (String host : cassandraHosts) {
clusterBuilder.addContactPoint(host);
}
cluster = clusterBuilder.withPort(9142).build();
dropAndCreateSchema();
// get new session using a default keyspace that we now know exists
session = cluster.connect(TEST_KEYSPACE);
session = spy(session);
daoSupport = new CqlStructuredDataSupport<UUID>(tableName, ConsistencyLevel.QUORUM, session);
}
示例8: setUp
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
// default to using cassandra on localhost, but can be overridden with a system property
String cassandraHosts = System.getProperty(CASSANDRA_HOSTS_SYSTEM_PROPERTY, EMBEDDED_CASSANDRA_HOST);
String[] hosts = StringUtils.split(cassandraHosts, ",");
numHosts = hosts.length;
if (EMBEDDED_CASSANDRA_HOST.equals(cassandraHosts)) {
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
}
// default cluster name can also be overridden with a system property
String clusterName = System.getProperty(CLUSTER_NAME_PROPERTY, TEST_CLUSTER);
hostConfigurator = new CassandraHostConfigurator(cassandraHosts);
cluster = HFactory.getOrCreateCluster(clusterName, hostConfigurator);
keyspace = HFactory.createKeyspace(TEST_KEYSPACE, cluster);
dropAndCreateSchema();
sleepAfterSchemaChangeIfNecessary();
}
示例9: initTest
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void initTest() throws Exception {
//this test will be slow because it needs to start Casssandra embedded server.
// For the test to be run on slow machines,
// the embedded cassandra start timeout is set bellow to 32s ! (which is pretty slow for a unit test)
EmbeddedCassandraServerHelper.startEmbeddedCassandra(32000L);
cluster = new Cluster.Builder().addContactPoint("localhost").withPort(9142).build();
session = cluster.connect();
createKeyspace();
personCassandraDao = new PersonCassandraDao("localhost", "9142", CASS_KEYSPACE);
personCassandraDao.init(Person.class);
}
示例10: stopCassandra
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@AfterClass
public static void stopCassandra() {
//Sometimes cleaning request to EmbeddedCassandra timeouts but it is not a big deal not to clean embeddedCassandra
// because keyspace is dropped and recreated in the initialization of this test. It is better not to break the build
// on slow machines
try {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
} catch (OperationTimedOutException e) {
e.printStackTrace();
}
}
示例11: setUpClass
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws InterruptedException, TTransportException, IOException {
System.setProperty("para.cassandra.port", "9142");
System.setProperty("para.app_name", ROOT_APP_NAME);
System.setProperty("para.cluster_name", ROOT_APP_NAME);
EmbeddedCassandraServerHelper.startEmbeddedCassandra(15 * 1000);
CassandraUtils.createTable(ROOT_APP_NAME);
CassandraUtils.createTable(appid1);
CassandraUtils.createTable(appid2);
CassandraUtils.createTable(appid3);
}
示例12: tearDownClass
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
CassandraUtils.deleteTable(ROOT_APP_NAME);
CassandraUtils.deleteTable(appid1);
CassandraUtils.deleteTable(appid2);
CassandraUtils.deleteTable(appid3);
CassandraUtils.shutdownClient();
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
示例13: startServer
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9142).build();
Session session = cluster.connect();
CQLDataLoader dataLoader = new CQLDataLoader(session);
dataLoader.load(new ClassPathCQLDataSet("config/cql/create-tables.cql", true, CASSANDRA_UNIT_KEYSPACE));
applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
}
示例14: startServer
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_TIMEOUT);
Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9142).build();
Session session = cluster.connect();
String createQuery = "CREATE KEYSPACE " + CASSANDRA_UNIT_KEYSPACE + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1}";
session.execute(createQuery);
String useKeyspaceQuery = "USE " + CASSANDRA_UNIT_KEYSPACE;
session.execute(useKeyspaceQuery);
CQLDataLoader dataLoader = new CQLDataLoader(session);
applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
}
示例15: startEmbeddedCassandra
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; //导入依赖的package包/类
private static Session startEmbeddedCassandra(boolean disableCassandra) {
if (disableCassandra) {
logger.warn("Embedded cassandra is NOT starting up because your app configuration explicitly requests "
+ "that it be disabled.");
return null;
}
if (cassandraSession == null) {
File cassandraWorkDir = new File(embeddedClusterWorkDirectory);
if (!cassandraWorkDir.exists()) {
logger.info("Creating the embedded Cassandra folders...{}", cassandraWorkDir.getAbsolutePath());
//noinspection ResultOfMethodCallIgnored
cassandraWorkDir.mkdirs();
}
// Start embedded cassandra
logger.info("Finished Creating the embedded Cassandra folders...{}",
cassandraWorkDir.getAbsolutePath());
logger.info("Starting embedded Cassandra");
try {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(cassandraYamlFile,
embeddedClusterWorkDirectory);
}
catch (Exception e) {
throw new RuntimeException(e);
}
Cluster cassandraCluster = Cluster.builder()
.addContactPoint(embeddedClusterContactPointHost)
.withPort(embeddedClusterContactPointPort)
.build();
cassandraSession = cassandraCluster.connect();
}
return cassandraSession;
}