All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cassandraunit.BaseCassandraUnit Maven / Gradle / Ivy

There is a newer version: 4.3.1.0
Show newest version
package org.cassandraunit;

import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.rules.ExternalResource;

import com.datastax.driver.core.SocketOptions;

/**
 * @author Marcin Szymaniuk
 */
public abstract class BaseCassandraUnit extends ExternalResource {

	protected String configurationFileName;
	protected long startupTimeoutMillis;
	protected int readTimeoutMillis = 12000;

	public BaseCassandraUnit() {
		this(EmbeddedCassandraServerHelper.DEFAULT_STARTUP_TIMEOUT);
	}

	public BaseCassandraUnit(long startupTimeoutMillis) {
		this.startupTimeoutMillis = startupTimeoutMillis;
	}

	@Override
	protected void before() throws Exception {
		/* start an embedded Cassandra */
		if (configurationFileName != null) {
			EmbeddedCassandraServerHelper.startEmbeddedCassandra(configurationFileName, startupTimeoutMillis);
		} else {
			EmbeddedCassandraServerHelper.startEmbeddedCassandra(startupTimeoutMillis);
		}

		/* create structure and load data */
		load();
	}

	protected abstract void load();

	/**
	 * Gets a base SocketOptions with an overridden readTimeoutMillis.
	 */
	protected SocketOptions getSocketOptions() {
		SocketOptions socketOptions = new SocketOptions();
		socketOptions.setReadTimeoutMillis(this.readTimeoutMillis);
		return socketOptions;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy