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

Check that if Embedded Cassandra is already running that don't start a new instance #135

Closed
manuchadha1979 opened this issue Sep 19, 2020 · 1 comment
Assignees

Comments

@manuchadha1979
Copy link

Hi

Would it be possible to add a functionality which allows user to check that if Embedded Cassandra is already running then don't start a new version.

My test cases are organised into specs and the runner runs specs in parallel. Due to parallelism, each spec starts its version of Embedded Cassandra which overwhelms the machine. I can't order the execution of tests. So it will help me greatly if only one instance is stared and others just use it.

thanks

@nosan
Copy link
Owner

nosan commented Sep 19, 2020

Hi @manuchadha1979

You can have a static instance of Cassandra and share it across all your tests.

public class CassandraInstance {

	private static volatile Cassandra cassandra;

	public Cassandra getOrCreate() {
		Cassandra cassandra = CassandraInstance.cassandra;
		if(cassandra==null){
			synchronized (this){
				cassandra = CassandraInstance.cassandra;
				if(cassandra==null){
					cassandra = new EmbeddedCassandraFactory().create();
					cassandra.start();
					CassandraInstance.cassandra = cassandra;
				}
			}
		}
		return cassandra;
	}

}

@nosan nosan closed this as completed Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants