Package sync
Class SyncMultiTypeWrapper
java.lang.Object
sync.SyncMultiTypeWrapper
public class SyncMultiTypeWrapper
extends java.lang.Object
An intensive test of multi-threading using MultiTypeWrapper as the test subject.
This primarily tests the functionality of the InstanceTracker class and its
multi-threading synchronization capabilities. The test intentionally
tries to create race conditions and deadlock by spinning up thousands of threads
all trying to access the same two instancesTrackers for MultiTypeWrapper.
-
Field Summary
Fields Modifier and Type Field Description static org.apache.logging.log4j.Logger
logger
The constant logger.static int
RANDOM_INSTANCES
The constant RANDOM_INSTANCES.static int
RANDOM_INVALID_INSTANCES
The constant RANDOM_INVALID_INSTANCES.static java.util.List<Lambda0<java.lang.Object>>
RANDOM_LAMBDAS
The constant RANDOM_LAMBDAS.static int
THREADS
The constant THREADS.static int
WARM_UP_ITERATIONS
The constant WARM_UP_ITERATIONS. -
Constructor Summary
Constructors Constructor Description SyncMultiTypeWrapper(Lambda0<java.util.Map<java.lang.String,java.lang.Object>> both, Lambda0<java.util.Map<java.lang.String,java.lang.Object>> from, Lambda0<java.util.Map<java.lang.Object,java.lang.String>> to, Lambda0<java.util.Map<java.lang.Class,org.apache.logging.log4j.Level>> loggingLevels)
Instantiates a new Sync multi type wrapper with the provided params -
Method Summary
Modifier and Type Method Description static java.util.Collection
getTestParams()
Gets test params.void
logCounter()
Logs the number of MultiTypeWrappers that were instantiated during the teststatic <K, V> java.util.LinkedHashMap<K,V>
randomizeMapOrder(java.util.Map<K,V> orig)
Randomize map order linked hash map.void
restoreDefaultLoggingLevels()
Restore default logging levels.void
run()
Starts all the test threads, and then waits for them to finish.void
runWarmUps()
Run single-threaded warm ups, to ensure the JVM is prepared for the testvoid
setTargetLoggingLevels()
Sets target logging levels, to prevent excessive output to the console
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger loggerThe constant logger. -
THREADS
public static final int THREADSThe constant THREADS.- See Also:
- Constant Field Values
-
WARM_UP_ITERATIONS
public static final int WARM_UP_ITERATIONSThe constant WARM_UP_ITERATIONS.- See Also:
- Constant Field Values
-
RANDOM_INSTANCES
public static final int RANDOM_INSTANCESThe constant RANDOM_INSTANCES.- See Also:
- Constant Field Values
-
RANDOM_INVALID_INSTANCES
public static final int RANDOM_INVALID_INSTANCESThe constant RANDOM_INVALID_INSTANCES.- See Also:
- Constant Field Values
-
RANDOM_LAMBDAS
The constant RANDOM_LAMBDAS.
-
-
Constructor Details
-
SyncMultiTypeWrapper
public SyncMultiTypeWrapper(Lambda0<java.util.Map<java.lang.String,java.lang.Object>> both, Lambda0<java.util.Map<java.lang.String,java.lang.Object>> from, Lambda0<java.util.Map<java.lang.Object,java.lang.String>> to, Lambda0<java.util.Map<java.lang.Class,org.apache.logging.log4j.Level>> loggingLevels)Instantiates a new Sync multi type wrapper with the provided params- Parameters:
both
- the bothfrom
- the fromto
- the tologgingLevels
- the logging levels
-
-
Method Details
-
randomizeMapOrder
public static <K, V> java.util.LinkedHashMap<K,V> randomizeMapOrder(java.util.Map<K,V> orig)Randomize map order linked hash map.- Type Parameters:
K
- the type parameterV
- the type parameter- Parameters:
orig
- the orig- Returns:
- the linked hash map
-
getTestParams
public static java.util.Collection getTestParams()Gets test params.- Returns:
- the test params
-
setTargetLoggingLevels
public void setTargetLoggingLevels()Sets target logging levels, to prevent excessive output to the console -
restoreDefaultLoggingLevels
public void restoreDefaultLoggingLevels()Restore default logging levels. -
logCounter
public void logCounter()Logs the number of MultiTypeWrappers that were instantiated during the test -
run
public void run() throws java.lang.InterruptedExceptionStarts all the test threads, and then waits for them to finish.- Throws:
java.lang.InterruptedException
- if there was an issue waiting for one of the threads to finish
-
runWarmUps
public void runWarmUps()Run single-threaded warm ups, to ensure the JVM is prepared for the test
-