Package org.cassandraunit.utils

Source Code of org.cassandraunit.utils.EmbeddedCassandraServerHelperTest

package org.cassandraunit.utils;

import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import org.junit.Test;

import java.util.Random;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

/**
*
* @author Jeremy Sevellec
*
*/
public class EmbeddedCassandraServerHelperTest {

  @Test
  public void shouldStartAndCleanAnEmbeddedCassandra() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    testIfTheEmbeddedCassandraServerIsUpOnHost("127.0.0.1:9171");
        EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    testIfTheEmbeddedCassandraServerIsUpOnHost("127.0.0.1:9171");
        EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
  }

  private void testIfTheEmbeddedCassandraServerIsUpOnHost(String hostAndPort) {
        Random random = new Random();
    Cluster cluster = HFactory.getOrCreateCluster("TestCluster" + random.nextInt(), new CassandraHostConfigurator(hostAndPort));
    assertThat(cluster.getConnectionManager().getActivePools().size(), is(1));
    KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace("system");
    assertThat(keyspaceDefinition, notNullValue());
    assertThat(keyspaceDefinition.getReplicationFactor(), is(1));
  }

}
TOP

Related Classes of org.cassandraunit.utils.EmbeddedCassandraServerHelperTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.