public class HelenusJUnit extends Object implements org.junit.rules.MethodRule
HelenusJUnit class provides the JUnit 4 definition for a
@Rule service that will take care of initializing an embedded
Cassandra server and the Helenus driver.
Note: This file is largely based on cassandra-unit.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_CFG_FILE
Constant for the default Cassandra configuration file which starts the
Cassandra daemon on a random free port.
|
static long |
DEFAULT_READ_TIMEOUT
Constant for the default timeout for read operations to the Cassandra daemon
before failing.
|
static long |
DEFAULT_STARTUP_TIMEOUT
Constant for the default timeout to wait for the Cassandra daemon to start
before failing.
|
| Constructor and Description |
|---|
HelenusJUnit()
Instantiates a new
HelenusJUnit object. |
HelenusJUnit(long startupTimeout)
Instantiates a new
HelenusJUnit object. |
HelenusJUnit(long startupTimeout,
long readTimeout)
Instantiates a new
HelenusJUnit object. |
HelenusJUnit(String cfgname,
long startupTimeout)
Instantiates a new
HelenusJUnit object. |
HelenusJUnit(String cfgname,
long startupTimeout,
long readTimeout)
Instantiates a new
HelenusJUnit object. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after(org.junit.runners.model.FrameworkMethod method,
Object target)
Called to tear down the Helenus/Cassandra environment.
|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runners.model.FrameworkMethod method,
Object target) |
protected void |
before(org.junit.runners.model.FrameworkMethod method,
Object target)
Called to initialize the Helenus/Cassandra environment.
|
HelenusJUnit |
clear()
Clears the database and the Helenus layer by resetting them to the same
state they were before the previous test case.
|
HelenusJUnit |
createSchema(Class<?> clazz)
Creates the schema for the specified pojo class onto the embedded Cassandra
database.
|
void |
disableAllStatementsTraces()
Disables all statements to be traced automatically regardless of the
statement tracing setting (see
GenericStatement.isTracing()). |
void |
disableFullTraces()
Disables tracing large statements beyond 2K.
|
void |
disableInternalCQLTracing()
Disables internal CQL statements tracing.
|
boolean |
dumpCaptures(Logger logger,
Level level)
Dumps the content of all the capture lists.
|
void |
enableAllStatementsTraces()
Enables all statements to be traced regardless of the statement tracing
setting (see
GenericStatement.isTracing()). |
void |
enableFullTraces()
Enables tracing large statements beyond 2K.
|
void |
enableInternalCQLTracing()
Enables internal CQL statements tracing.
|
HelenusJUnit |
execute(Iterable<String> statements)
Executes the specified simple statements.
|
HelenusJUnit |
execute(Iterator<String> statements)
Execute the specified simple statements in sequence.
|
HelenusJUnit |
execute(java.util.stream.Stream<String> statements)
Executes the specified simple statements in sequence.
|
HelenusJUnit |
execute(String... statements)
Executes the specified simple statements.
|
<E extends Throwable> |
inhibitCapturing(ERunnable<E> cmd)
Executes a command while disabling all capture lists.
|
static boolean |
isCassandraDaemonThread(Thread thread)
Checks if the specified thread is a Cassandra daemon thread.
|
HelenusJUnit |
populate(java.util.function.Function<Map<String,String>,? super Object> objs)
Populates the database with objects returned by the specified function.
|
HelenusJUnit |
populate(Iterable<? super Object> objs)
Populates the database with the specified objects.
|
HelenusJUnit |
populate(Iterator<? super Object> objs)
Populates the database with the specified objects.
|
HelenusJUnit |
populate(Object... objs)
Populates the database with the specified objects.
|
HelenusJUnit |
populate(java.util.stream.Stream<? super Object> objs)
Populates the database with the specified objects.
|
HelenusJUnit |
populate(java.util.function.Supplier<? super Object> objs)
Populates the database with objects returned by the specified supplier.
|
HelenusJUnit |
schema(Class<?>... classes)
Initializes the schema for the specified pojo classes in the database.
|
HelenusJUnit |
schema(Iterable<Class<?>> classes)
Initializes the schema for the specified pojo classes in the database.
|
HelenusJUnit |
schema(Iterator<Class<?>> classes)
Initializes the schema for the specified pojo classes in the database.
|
HelenusJUnit |
schema(java.util.stream.Stream<Class<?>> classes)
Initializes the schema for the specified pojo classes in the database.
|
void |
setNumberReadRetries(int retries)
Sets the number of times to retry a read operation that timed out.
|
void |
setNumberRetries(int retries)
Sets the number of times to retry a read or write operation that timed out.
|
void |
setNumberWriteRetries(int retries)
Sets the number of times to retry a write operation that timed out.
|
HelenusJUnit |
truncate(Class<?>... classes)
Truncates all tables for the specified pojo classes from the database.
|
HelenusJUnit |
truncate(Iterable<Class<?>> classes)
Truncates all tables for the specified pojo classes from the database.
|
HelenusJUnit |
truncate(Iterator<Class<?>> classes)
Truncates all tables for the specified pojo classes from the database.
|
HelenusJUnit |
truncate(java.util.stream.Stream<Class<?>> classes)
Truncates all tables for the specified pojo classes from the database.
|
HelenusJUnit |
whenSent(java.util.function.Consumer<GenericStatement<?,?>> consumer)
Registers a callback to be notified when a statement is sent to Cassandra.
|
StatementCaptureList<GenericStatement> |
withCapture()
Starts capturing all object statements that have had their executions
requested with the Helenus statement manager in the order they are occurring
to the returned list.
|
<T extends GenericStatement> |
withCapture(Class<T> clazz)
Starts capturing all statements of the specified class that have had their
executions requested with the Helenus statement manager in the order they
are occurring to the returned list.
|
HelenusJUnit |
withoutCapture()
Stops capturing object statements with all capture lists.
|
public static final long DEFAULT_STARTUP_TIMEOUT
public static final long DEFAULT_READ_TIMEOUT
public static final String DEFAULT_CFG_FILE
public HelenusJUnit()
HelenusJUnit object.
Note: Defaults to 60 seconds timeout to wait for the Cassandra daemon to start on a free port and 12 seconds for read operations before failing.
public HelenusJUnit(long startupTimeout)
HelenusJUnit object.
Note: Defaults to 12 seconds for read operations on the Cassandra daemon before failing.
startupTimeout - the maximum amount of time in milliseconds to wait for
Cassandra daemon to start before failingpublic HelenusJUnit(long startupTimeout,
long readTimeout)
HelenusJUnit object.startupTimeout - the maximum amount of time in milliseconds to wait for
Cassandra daemon to start before failingreadTimeout - the maximum amount of time in milliseconds to wait for
read operations on the Cassandra daemon before failingpublic HelenusJUnit(String cfgname, long startupTimeout)
HelenusJUnit object.
Note: Defaults to 12 seconds for read operations on the Cassandra daemon before failing.
cfgname - the config file resource name to use to initialize the
Cassandra daemonstartupTimeout - the maximum amount of time in milliseconds to wait for
Cassandra daemon to start before failingNullPointerException - if cfgname is nullpublic HelenusJUnit(String cfgname, long startupTimeout, long readTimeout)
HelenusJUnit object.cfgname - the config file resource name to use to initialize the
Cassandra daemonstartupTimeout - the maximum amount of time in milliseconds to wait for
Cassandra daemon to start before failingreadTimeout - the maximum amount of time in milliseconds to wait for
read operations on the Cassandra daemon before failingNullPointerException - if cfgname is nullpublic static boolean isCassandraDaemonThread(Thread thread)
thread - the thread to check if it is a Cassandra daemon threadtrue if the specified is a Cassandra daemon thread;
false if it is notprotected void before(org.junit.runners.model.FrameworkMethod method,
Object target)
method - the test method to be runtarget - the test object on which the method will be runAssertionError - if an error occurs while initializing the cassandra
daemon or the helenus statement managerprotected void after(org.junit.runners.model.FrameworkMethod method,
Object target)
method - the test method to be runtarget - the test object on which the method will be runpublic void setNumberRetries(int retries)
Note: Defaults to none.
retries - the number of times to retry a read or write operation that
timed outpublic void setNumberReadRetries(int retries)
Note: Defaults to none.
retries - the number of times to retry a read operation that timed outpublic void setNumberWriteRetries(int retries)
Note: Defaults to none.
retries - the number of times to retry a write operation that timed outpublic void enableInternalCQLTracing()
public void disableInternalCQLTracing()
public void enableFullTraces()
public void disableFullTraces()
public void enableAllStatementsTraces()
GenericStatement.isTracing()).public void disableAllStatementsTraces()
GenericStatement.isTracing()).public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runners.model.FrameworkMethod method,
Object target)
apply in interface org.junit.rules.MethodRuleMethodRule.apply(org.junit.runners.model.Statement, org.junit.runners.model.FrameworkMethod, java.lang.Object)public HelenusJUnit clear()
AssertionError - if a failure occurs while cleanuppublic HelenusJUnit createSchema(Class<?> clazz)
clazz - the pojo class for which to create the schemaNullPointerException - if clazz is nullAssertionError - if a failure occurs while creating the schemapublic HelenusJUnit populate(java.util.function.Supplier<? super Object> objs)
Note: The supplier can return an array, a Collection,
an Iterable, an Iterator, an Enumeration, or a
Stream of pojo objects or a single object to insert in the database.
objs - the supplier of objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit populate(java.util.function.Function<Map<String,String>,? super Object> objs)
populate() allows one to receive a map of all
keyspace key values defined in the test environment using the
PartitionKeyValues annotations. As such, the function might be called
multiple times with each combination of keyspace key values.
Note: The function can return an array, a Collection,
an Iterable, an Iterator, an Enumeration, or a
Stream of pojo objects or a single object to insert in the database.
objs - the function to receive a map of keyspace key values and return
objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit populate(Object... objs)
objs - the objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit populate(Iterable<? super Object> objs)
objs - the objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit populate(Iterator<? super Object> objs)
objs - the objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit populate(java.util.stream.Stream<? super Object> objs)
objs - the objects to populate the database withAssertionError - if any error occurspublic HelenusJUnit truncate(Class<?>... classes)
classes - the pojo classes for which to truncate all the tables
contentAssertionError - if any error occurspublic HelenusJUnit truncate(Iterable<Class<?>> classes)
classes - the pojo classes for which to truncate all the tables
contentAssertionError - if any error occurspublic HelenusJUnit truncate(Iterator<Class<?>> classes)
classes - the pojo classes for which to truncate all the tables
contentAssertionError - if any error occurspublic HelenusJUnit truncate(java.util.stream.Stream<Class<?>> classes)
classes - the pojo classes for which to truncate all the tables
contentAssertionError - if any error occurspublic HelenusJUnit execute(String... statements)
statements - the simple statements to executeAssertionError - if any error occurspublic HelenusJUnit execute(Iterable<String> statements)
statements - the simple statements to executeAssertionError - if any error occurspublic HelenusJUnit execute(Iterator<String> statements)
statements - the simple statements to executeAssertionError - if any error occurspublic HelenusJUnit execute(java.util.stream.Stream<String> statements)
statements - the simple statements to executeAssertionError - if any error occurspublic HelenusJUnit schema(Class<?>... classes)
classes - the pojo classes for which to initialize the schemaAssertionError - if any error occurspublic HelenusJUnit schema(Iterable<Class<?>> classes)
classes - the pojo classes for which to initialize the schemaAssertionError - if any error occurspublic HelenusJUnit schema(Iterator<Class<?>> classes)
classes - the pojo classes for which to initialize the schemaAssertionError - if any error occurspublic HelenusJUnit schema(java.util.stream.Stream<Class<?>> classes)
classes - the pojo classes for which to initialize the schemaAssertionError - if any error occurspublic StatementCaptureList<GenericStatement> withCapture()
Note: In the case of Group-based statements, all grouped
statements will be captured individually.
null statements capture list where the statements
will be recordedpublic <T extends GenericStatement> StatementCaptureList<T> withCapture(Class<T> clazz)
Note: In the case of Group-based statements, all grouped
statements will be captured individually.
T - the type of statements to captureclazz - the class of object statements to capturenull statements capture list where the statements
will be recordedNullPointerException - if clazz is nullpublic HelenusJUnit withoutCapture()
public <E extends Throwable> HelenusJUnit inhibitCapturing(ERunnable<E> cmd) throws E extends Throwable
E - the type of exceptions that can be thrown outcmd - the command to execute while capturing is inhibitedE - if thrown by the commandE extends Throwablepublic boolean dumpCaptures(Logger logger, Level level)
logger - the logger where to dump the content of the capture listslevel - the log level to use when dumpingtrue if anything was dumped; false otherwisepublic HelenusJUnit whenSent(java.util.function.Consumer<GenericStatement<?,?>> consumer)
consumer - the consumer to register to be notified every time a
statement is sent to CassandraCopyright (C) 2015-2017 The Helenus Driver Project Authors.