Java Examples for org.cassandraunit.utils.EmbeddedCassandraServerHelper

The following java examples will help you to understand the usage of org.cassandraunit.utils.EmbeddedCassandraServerHelper. These source code samples are taken from different open source projects.

Example 1
Project: cassandra-unit-master  File: AbstractCassandraUnitTestExecutionListener.java View source code
protected void startServer(TestContext testContext) throws Exception {
    EmbeddedCassandra embeddedCassandra = Preconditions.checkNotNull(AnnotationUtils.findAnnotation(testContext.getTestClass(), EmbeddedCassandra.class), "CassandraUnitTestExecutionListener must be used with @EmbeddedCassandra on " + testContext.getTestClass());
    if (!initialized) {
        String yamlFile = Optional.fromNullable(embeddedCassandra.configuration()).get();
        long timeout = embeddedCassandra.timeout();
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(yamlFile, timeout);
        initialized = true;
    }
    CassandraDataSet cassandraDataSet = AnnotationUtils.findAnnotation(testContext.getTestClass(), CassandraDataSet.class);
    if (cassandraDataSet != null) {
        List<String> dataset = null;
        ListIterator<String> datasetIterator = null;
        String keyspace = cassandraDataSet.keyspace();
        dataset = dataSetLocations(testContext, cassandraDataSet);
        datasetIterator = dataset.listIterator();
        CQLDataLoader cqlDataLoader = new CQLDataLoader(EmbeddedCassandraServerHelper.getSession());
        while (datasetIterator.hasNext()) {
            String next = datasetIterator.next();
            boolean dropAndCreateKeyspace = datasetIterator.previousIndex() == 0;
            cqlDataLoader.load(new ClassPathCQLDataSet(next, dropAndCreateKeyspace, dropAndCreateKeyspace, keyspace));
        }
    }
}
Example 2
Project: flipper-reverse-image-search-master  File: AbstractCassandraTest.java View source code
@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"));
}
Example 3
Project: androGister-master  File: AbstractCassandraTest.java View source code
//    @Autowired
//    private CassandraUserRepository counterRepository;
@BeforeClass
public static void beforeClass() throws Exception {
    if (!isInitialized) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra();
        /* create structure and load data */
        String clusterName = "androgister";
        String host = "localhost:9171";
        DataLoader dataLoader = new DataLoader(clusterName, host);
        dataLoader.load(new ClassPathJsonDataSet("dataset/dataset.json"));
        isInitialized = true;
    }
}
Example 4
Project: hecate-master  File: CassandraTestCase.java View source code
@Before
public void initializeCassandra() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
    cluster = Cluster.builder().addContactPoint("localhost").withPort(9142).build();
    Session session = getCluster().newSession();
    logger.debug("Creating keyspace {}...", KEYSPACE_NAME);
    session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};", KEYSPACE_NAME));
    logger.debug("Keyspace {} created successfully.", KEYSPACE_NAME);
    session.close();
}
Example 5
Project: rhizome-master  File: CassandraBootstrap.java View source code
public void start(String yamlFile) {
    if (lock.tryLock()) {
        try {
            EmbeddedCassandraServerHelper.startEmbeddedCassandra(yamlFile, 100000);
            EmbeddedCassandraServerHelper.getCluster().getConfiguration().getSocketOptions().setReadTimeoutMillis(EMBEDDED_TIMEOUT);
        } catch (ConfigurationExceptionTTransportException | IOException |  e) {
            throw new IllegalStateException("Cassandra unable to start.", e);
        }
        logger.info("Started cassandra on port: {}", EmbeddedCassandraServerHelper.getNativeTransportPort());
    }
}
Example 6
Project: cassandra-migration-tool-java-master  File: MigratorTest.java View source code
@BeforeClass
public static void init() throws Exception {
    LOGGER.info("Starting embedded cassandra server");
    EmbeddedCassandraServerHelper.startEmbeddedCassandra("another-cassandra.yaml");
    LOGGER.info("Connect to embedded db");
    cluster = Cluster.builder().addContactPoints(CONTACT_POINT).withPort(PORT).build();
    session = cluster.connect();
}
Example 7
Project: casser-master  File: AbstractEmbeddedCassandraTest.java View source code
@BeforeClass
public static void before() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(BuildProperties.getCassandraConfig());
    cluster = Cluster.builder().addContactPoint(BuildProperties.getCassandraHost()).withPort(BuildProperties.getCassandraNativePort()).build();
    KeyspaceMetadata kmd = cluster.getMetadata().getKeyspace(keyspace);
    if (kmd == null) {
        session = cluster.connect();
        String cql = "CREATE KEYSPACE " + keyspace + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};";
        System.out.println(cql + "\n");
        session.execute(cql);
        cql = "USE " + keyspace + ";";
        System.out.println(cql + "\n");
        session.execute(cql);
    } else {
        session = cluster.connect(keyspace);
    }
}
Example 8
Project: copper-engine-master  File: CassandraTest.java View source code
@BeforeClass
public static synchronized void setUpBeforeClass() throws Exception {
    if (factory == null) {
        //            logger.info("Starting embedded cassandra...");
        //            EmbeddedCassandraServerHelper.startEmbeddedCassandra("unittest-cassandra.yaml", "./build/cassandra");
        //            Thread.sleep(100);
        //            logger.info("Successfully started embedded cassandra.");
        final Cluster cluster = new Builder().addContactPoint("localhost").withPort(CASSANDRA_PORT).build();
        //            final Session session = cluster.newSession();
        //            session.execute("CREATE KEYSPACE copper WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
        factory = new UnitTestCassandraEngineFactory(false);
        factory.setCassandraPort(CASSANDRA_PORT);
        factory.getEngine().startup();
    }
}
Example 9
Project: kaa-master  File: CustomCassandraCQLUnit.java View source code
@Override
protected void load() {
    String hostIp = EmbeddedCassandraServerHelper.getHost();
    int port = EmbeddedCassandraServerHelper.getNativeTransportPort();
    cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions()).build();
    session = cluster.connect();
    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataLoader.load(dataSet);
    session = dataLoader.getSession();
}
Example 10
Project: SimpleFlatMapper-master  File: DatastaxHelper.java View source code
public static void startCassandra() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(DatastaxHelper.class.getClassLoader());
        // deal with multiple classloader
        synchronized (CASSANDRA_STARTED) {
            if (System.getProperty(CASSANDRA_STARTED) == null) {
                fixTypeCodec();
                // cassandra does some check on the java version
                // expect a dot not present in java 9 ea 126
                String vmversion = System.getProperty("java.vm.version");
                if (vmversion.startsWith("9-ea")) {
                    System.out.println("override java version prop");
                    System.setProperty("java.vm.version", "25.51-b03");
                }
                File configFile = new File("target/embeddedCassandra/cu-cassandra.yaml");
                configFile.getParentFile().mkdirs();
                InputStream is = EmbeddedCassandraServerHelper.class.getResourceAsStream("/cu-cassandra.yaml");
                try {
                    OutputStream os = new FileOutputStream(configFile);
                    byte[] buffer = new byte[4096];
                    try {
                        int l;
                        while ((l = is.read(buffer)) != -1) {
                            os.write(buffer, 0, l);
                        }
                    } finally {
                        os.close();
                    }
                } finally {
                    is.close();
                }
                String cassandraConfig = "file:" + configFile.getAbsolutePath();
                System.setProperty("cassandra.config", cassandraConfig);
                System.setProperty("cassandra.native.epoll.enabled", "false");
                System.out.println("Starting Cassandra " + cassandraConfig);
                EmbeddedCassandraServerHelper.startEmbeddedCassandra(300000L);
                System.out.println("Started Cassandra");
                System.setProperty(CASSANDRA_STARTED, "true");
            } else {
                System.out.println("CASSANDRA_STARTED = " + System.getProperty(CASSANDRA_STARTED));
            }
        }
    } finally {
        Thread.currentThread().setContextClassLoader(classLoader);
    }
}
Example 11
Project: spring-data-examples-master  File: Cassandra.java View source code
@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();
}
Example 12
Project: tatami-master  File: AbstractCassandraTatamiTest.java View source code
@BeforeClass
public static void beforeClass() throws Exception {
    synchronized (lock) {
        if (!isInitialized) {
            EmbeddedCassandraServerHelper.startEmbeddedCassandra();
            // create structure and load data
            String clusterName = "Tatami cluster";
            String host = "localhost:9171";
            DataLoader dataLoader = new DataLoader(clusterName, host);
            dataLoader.load(new ClassPathJsonDataSet("dataset/dataset.json"));
            final ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
            builder.put("cluster.name", clusterName);
            final Node node = NodeBuilder.nodeBuilder().settings(builder.build()).local(true).node();
            client = node.client();
            isInitialized = true;
        }
    }
}
Example 13
Project: thingsboard-master  File: CustomCassandraCQLUnit.java View source code
@Override
protected void load() {
    String hostIp = EmbeddedCassandraServerHelper.getHost();
    int port = EmbeddedCassandraServerHelper.getNativeTransportPort();
    cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions()).build();
    session = cluster.connect();
    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataSets.forEach(dataLoader::load);
    session = dataLoader.getSession();
}
Example 14
Project: wildfly-camel-master  File: CassandraIntegrationTest.java View source code
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
    if (!EnvironmentUtils.isAIX()) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra("/camel-cassandra.yaml", "target/camel-cassandra", 30000);
        new LoadableCassandraCQLUnit(new ClassPathCQLDataSet("cassandra/BasicDataSet.cql", KEYSPACE), "/camel-cassandra.yaml").setup();
    }
}
Example 15
Project: c-star-path-j-master  File: CqlStructuredDataSupportSystemTest.java View source code
@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);
}
Example 16
Project: cyclop-master  File: EmbeddedCassandra.java View source code
public void start() throws Exception {
    if (running) {
        return;
    }
    assertNotNull("Missing system property cassandra_yaml", YAML_NAME);
    EmbeddedCassandraServerHelper.startEmbeddedCassandra("/" + YAML_NAME);
    cluster = Cluster.builder().addContactPoints("localhost").withPort(9042).build();
    assertNotNull(cluster);
    session = cluster.connect();
    assertNotNull(session);
    executeScript(session, "/cql/createDemoTables.cql");
    executeScript(session, "/cql/createDemoData.cql");
    createTestData(session);
    running = true;
}
Example 17
Project: spring-xd-master  File: CassandraSinkTests.java View source code
@BeforeClass
public static void setUp() throws ConfigurationException, IOException, TTransportException {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG, "build/embeddedCassandra");
    cluster = Cluster.builder().addContactPoint("localhost").withPort(PORT).build();
    cluster.connect().execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s" + "  WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", STREAM_NAME));
    cassandraTemplate = new CassandraTemplate(cluster.connect(STREAM_NAME));
    new RandomConfigurationSupport();
    application = new SingleNodeApplication().run();
    SingleNodeIntegrationTestSupport integrationTest = new SingleNodeIntegrationTestSupport(application);
    integrationTest.addModuleRegistry(new SingletonModuleRegistry(ModuleType.sink, MODULE_NAME));
}
Example 18
Project: metamodel-master  File: CassandraDataContextTest.java View source code
@BeforeClass
public static void setUpCluster() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    client.connect(cassandraNode, defaultCassandraPort);
    cluster = client.getCluster();
    Session session = cluster.connect();
    createCassandraKeySpaceAndTable(session);
    populateCassandraTableWithSomeData(session);
    populateCassandraCounterTableWithSomeData(session);
    dc = new CassandraDataContext(cluster, keyspaceName);
}
Example 19
Project: hecuba-master  File: CassandraTestBase.java View source code
@Before
public void setup() {
    try {
        ConfigUtils.getInstance().getConfiguration().setProperty(HecubaConstants.GLOBAL_PROP_NAME_PREFIX + ".consistencypolicy.read", "ONE");
        ConfigUtils.getInstance().getConfiguration().setProperty(HecubaConstants.GLOBAL_PROP_NAME_PREFIX + ".consistencypolicy.write", "ONE");
        // Find the test methods that you have in the sub class.
        List<String> columnFamilyNames = getColumnFamilies(testName.getMethodName());
        // now load this information into Cassandra cluster.
        EmbeddedCassandraServerHelper.startEmbeddedCassandra();
        //wait until cluster is ready
        while (true) {
            Cluster cluster = HFactory.getOrCreateCluster(CLUSTER_NAME, LOCATION + ":" + PORT);
            logger.info("Cluster: {}, name: {}", cluster, CLUSTER_NAME);
            if (cluster != null && cluster.getConnectionManager().getActivePools().size() > 0) {
                break;
            } else {
                logger.info("Sleep {}ms to check if server is ready", cassandraServerWaitTime);
                Thread.sleep(cassandraServerWaitTime);
            }
        }
        DataLoader loader = new DataLoader(CLUSTER_NAME, LOCATION + ":" + PORT);
        loader.load(new StringXMLDataSet(createCassandraUnitConfigFile(columnFamilyNames)));
    } catch (ConfigurationExceptionTTransportException | IOException | InterruptedException |  e) {
        throw new RuntimeException(e);
    }
}
Example 20
Project: cassandra-migration-master  File: BaseIT.java View source code
@BeforeClass
public static void beforeSuite() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra-unit.yaml", "target/embeddedCassandra", 200000L);
}
Example 21
Project: Europeana-Cloud-master  File: EmbeddedCassandra.java View source code
private void dropAllKeyspaces() {
    LOGGER.info("Drop all keyspaces...");
    EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
Example 22
Project: ff-master  File: EventRepositoryCassandraTest.java View source code
@BeforeClass
public static void startEmbeddedCassandra() throws Exception {
    // Use Cassandra-Unit 
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(15000);
    conn = new CassandraConnection("127.0.0.1", 9142);
    // <--
    conn.createKeySpace();
}
Example 23
Project: ff4j-master  File: EventRepositoryCassandraTest.java View source code
@BeforeClass
public static void startEmbeddedCassandra() throws Exception {
    // Use Cassandra-Unit 
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(15000);
    conn = new CassandraConnection("127.0.0.1", 9142);
    // <--
    conn.createKeySpace();
}
Example 24
Project: camel-master  File: CassandraUnitUtils.java View source code
/**
     * Start embedded Cassandra.
     */
public static void startEmbeddedCassandra() throws Exception {
    if (canTest()) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra("/camel-cassandra.yaml", "target/camel-cassandra", 30000);
    }
}
Example 25
Project: flags-master  File: CassandraStateRepositoryTest.java View source code
@Before
public void setupTest() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    final Keyspace keyspace = new KeyspaceBuilder("Test Cluster", "TogglzTest").setThriftPort(9171).build();
    stateRepository = CassandraStateRepository.newBuilder(keyspace).build();
}
Example 26
Project: newts-master  File: NewtsInstance.java View source code
@Override
public void before() throws Throwable {
    cassandraUnit = new MyCassandraCQLUnit(getDataSet(CASSANDRA_KEYSPACE, 1));
    cassandraUnit.before();
    host = EmbeddedCassandraServerHelper.getHost();
    port = EmbeddedCassandraServerHelper.getNativeTransportPort();
}
Example 27
Project: togglz-master  File: CassandraStateRepositoryTest.java View source code
@Before
public void setupTest() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    final Keyspace keyspace = new KeyspaceBuilder("Test Cluster", "TogglzTest").setThriftPort(9171).build();
    stateRepository = CassandraStateRepository.newBuilder(keyspace).build();
}
Example 28
Project: spring-cloud-stream-modules-master  File: CassandraSinkIntegrationTests.java View source code
@BeforeClass
public static void setUp() {
    System.setProperty("spring.cassandra.port", "" + EmbeddedCassandraServerHelper.getNativeTransportPort());
}
Example 29
Project: stargate-core-master  File: CQLUnitD.java View source code
@Override
protected void before() throws Exception {
    /* start an embedded Cassandra */
    if (configurationFileName != null) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(configurationFileName);
    } else {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    }
    load();
}
Example 30
Project: datacollector-master  File: TestCassandraTarget.java View source code
@SuppressWarnings("unchecked")
@BeforeClass
public static void setUpClass() throws InterruptedException, TTransportException, ConfigurationException, IOException {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_STARTUP_TIMEOUT);
    cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(CASSANDRA_NATIVE_PORT).withProtocolVersion(ProtocolVersion.V4).build();
    session = cluster.connect();
}