Package de.gebit.integrity.runner
Class TestModel
- java.lang.Object
-
- de.gebit.integrity.runner.TestModel
-
public class TestModel extends java.lang.Object
The test model. There's not much more to say ;-)- Author:
- Rene Schneider - initial API and implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<AmbiguousDefinition>
ambiguousDefinitions
Ambiguous definitions which are found during variable/suite/etc.protected java.util.Map<java.lang.String,CallDefinition>
callMap
Call names -> Calls.protected java.util.TreeSet<ConstantDefinition>
constantDefinitionsInPackages
Stores an ordered list of global constant definitions.protected java.util.Map<java.lang.String,AmbiguousDefinition>
duplicateMap
This map is used to find duplicates which then end up inambiguousDefinitions
.protected java.util.Map<java.lang.String,ForkDefinition>
forkMap
Fork names -> Forks.protected com.google.inject.Injector
injector
The Google Guice Injector.protected java.util.List<InMemoryTestResourceProvider>
inMemoryResourceProviders
This list stores copies of theloadedResourceProviders
which refer to resources which have been fully loaded in memory.protected java.util.List<TestResourceProvider>
loadedResourceProviders
All resource providers that this model has been filled from.protected java.util.Queue<TestResource>
loadedResources
All successfully loaded resources, in the order in which they were loaded.protected static int
MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING
The maximum number of scripts which are always loaded in "verbose" mode.protected java.util.List<Model>
models
All models.protected ModelSourceExplorer
modelSourceExplorer
The model source explorer.protected static int
MULTITHREADED_SECTIONS_THREAD_COUNT_DEFAULT_MAX
The maximum of multithreaded threads if default determination is used.protected static java.lang.String
MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY
The system property that allows to override the number of threads used to do some time-critical sections in the test runner, such as defining constants and variables.protected TestRunnerPerformanceLogger
performanceLogger
The performance logger.static java.lang.String
PRINT_ALL_LOADED_SCRIPTS_PROPERTY
Set this system property to turn on verbose script loading.protected java.lang.Object
resourceLoadingSyncObject
This sync object is used to synchronize access toXtextResourceFactory
,XtextResource
andXtextResourceSet
.protected java.lang.Object
statusOutputSyncObject
Used to synchronize potential printouts - printing to stdout with multiple threads can quickly lead to chaos.protected java.util.Map<java.lang.String,SuiteDefinition>
suiteMap
Suite names -> Suites.protected java.util.Map<java.lang.String,TestDefinition>
testMap
Test names -> Tests.protected java.util.Map<java.lang.String,VariableOrConstantEntity>
variableAndConstantMap
Variable/constant names -> Entities.protected java.util.Map<VariableOrConstantEntity,java.lang.String>
variableAndConstantReverseMap
The reverse ofvariableAndConstantMap
.protected java.util.TreeSet<VariableDefinition>
variableDefinitionsInPackages
Stores an ordered list of global variable definitions.protected java.util.Map<java.lang.String,VariantDefinition>
variantMap
Variant names -> Variants.protected boolean
verboseScriptLoading
Whether to load scripts in a verbose fashion (=printing every load).
-
Constructor Summary
Constructors Constructor Description TestModel()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIntegrityScriptModel(Model aModel)
Adds a given Integrity script file to the test model.void
addIntegrityScriptModels(java.util.List<Model> someModels)
Adds all given Integrity script files to the test model.protected java.util.List<Diagnostic>
customValidateSingleModel(Model aModel)
Performs validation of a single model.java.util.Collection<CallDefinition>
getAllCalls()
Returns all calls in the test model.java.util.Collection<ForkDefinition>
getAllForks()
Returns all forks in the test model.java.util.Collection<SuiteDefinition>
getAllSuites()
Returns all suites in the test model.java.util.Collection<TestDefinition>
getAllTests()
Returns all tests in the test model.java.util.Collection<VariantDefinition>
getAllVariants()
CallDefinition
getCallByName(java.lang.String aFullyQualifiedCallName)
Resolves a fully qualified call name to the actual call definition.java.util.TreeSet<ConstantDefinition>
getConstantDefinitionsInPackages()
Iterates through the whole model and searches for constant definitions.java.util.Set<AmbiguousDefinition>
getDuplicateDefinitions()
ForkDefinition
getForkByName(java.lang.String aFullyQualifiedForkName)
Resolves a fully qualified fork name to the actual fork definition.java.lang.String
getFullyQualifiedVariableOrConstantName(VariableOrConstantEntity anEntity)
Returns the fully-qualified name of a variable/constant entity.com.google.inject.Injector
getInjector()
java.util.List<InMemoryTestResourceProvider>
getInMemoryResourceProviders()
Returns a list of duplicates of all resource providers ever used to load test scripts into thisTestModel
.java.util.List<TestResourceProvider>
getLoadedResourceProviders()
java.util.List<TestResource>
getLoadedResources()
java.util.List<Model>
getModels()
int
getMultithreadedSectionsThreadCount()
Returns the number of threads to use during multithreaded sections, such as defining constants and variables.protected int
getMultithreadedSectionsThreadCountDefault()
Returns the default number of threads to use during multithreaded sections, such as defining constants and variables.SuiteDefinition
getSuiteByName(java.lang.String aFullyQualifiedSuiteName)
Resolves a fully qualified suite name to the actual suite definition.TestDefinition
getTestByName(java.lang.String aFullyQualifiedTestName)
Resolves a fully qualified test name to the actual test definition.java.util.TreeSet<VariableDefinition>
getVariableDefinitionsInPackages()
Iterates through the whole model and searches for variable definitions hosted in packages (global variables).VariableOrConstantEntity
getVariableOrConstantByName(java.lang.String aFullyQualifiedName)
Resolves a fully qualified variable/constant name to the actual entity.VariantDefinition
getVariantByName(java.lang.String aFullyQualifiedVariantName)
Resolves a fully qualified variant name to the actual variant definition.TestRunner
initializeTestRunner(TestRunnerCallback aCallback, java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants, java.lang.String aResultLocale, java.lang.Integer aRemotingPort, java.lang.String aRemotingBindHost, java.lang.Long aRandomSeed, java.lang.String[] someCommandLineArguments)
Initializes a fresh test runner instance, based on this test model.static TestModel
instantiateTestModel(java.lang.ClassLoader aClassLoader, java.lang.Class<? extends IntegrityDSLSetup> aSetupClass, boolean aSkipModelChecksFlag)
Instantiates a TestModel using the provided setup class.protected java.util.List<Diagnostic>
loadSingleResource(TestResourceProvider aResourceProvider, TestResource aResourceName, org.eclipse.xtext.resource.XtextResourceSet aResourceSet, org.eclipse.xtext.resource.IResourceFactory aResourceFactory, boolean aVerboseFlag)
Loads a singleTestResource
from the givenTestResourceProvider
.static TestModel
loadTestModel(TestResourceProvider aResourceProvider, boolean aSkipModelChecksFlag, boolean aPerformModelValidationFlag, java.lang.Class<? extends IntegrityDSLSetup> aSetupClass)
Loads aTestModel
from a givenTestResourceProvider
.java.util.List<Diagnostic>
readIntegrityScriptFiles(TestResourceProvider aResourceProvider, boolean aPerformModelValidationFlag)
Reads all Integrity scripts from the provided resource provider and initializes this test model with them.
-
-
-
Field Detail
-
models
protected java.util.List<Model> models
All models. Every file is a model of itself (though they are all linked, of course).
-
suiteMap
protected java.util.Map<java.lang.String,SuiteDefinition> suiteMap
Suite names -> Suites.
-
variantMap
protected java.util.Map<java.lang.String,VariantDefinition> variantMap
Variant names -> Variants.
-
forkMap
protected java.util.Map<java.lang.String,ForkDefinition> forkMap
Fork names -> Forks.
-
callMap
protected java.util.Map<java.lang.String,CallDefinition> callMap
Call names -> Calls.
-
testMap
protected java.util.Map<java.lang.String,TestDefinition> testMap
Test names -> Tests.
-
variableAndConstantMap
protected java.util.Map<java.lang.String,VariableOrConstantEntity> variableAndConstantMap
Variable/constant names -> Entities.
-
variableAndConstantReverseMap
protected java.util.Map<VariableOrConstantEntity,java.lang.String> variableAndConstantReverseMap
The reverse ofvariableAndConstantMap
.
-
ambiguousDefinitions
protected java.util.Set<AmbiguousDefinition> ambiguousDefinitions
Ambiguous definitions which are found during variable/suite/etc. indexing are collected here.
-
duplicateMap
protected java.util.Map<java.lang.String,AmbiguousDefinition> duplicateMap
This map is used to find duplicates which then end up inambiguousDefinitions
.
-
constantDefinitionsInPackages
protected java.util.TreeSet<ConstantDefinition> constantDefinitionsInPackages
Stores an ordered list of global constant definitions. This is intended as a cache - if it's null, it must be recreated.
-
variableDefinitionsInPackages
protected java.util.TreeSet<VariableDefinition> variableDefinitionsInPackages
Stores an ordered list of global variable definitions. This is intended as a cache - if it's null, it must be recreated.
-
injector
@Inject protected com.google.inject.Injector injector
The Google Guice Injector.
-
modelSourceExplorer
@Inject protected ModelSourceExplorer modelSourceExplorer
The model source explorer.
-
performanceLogger
@Inject protected TestRunnerPerformanceLogger performanceLogger
The performance logger.
-
loadedResources
protected java.util.Queue<TestResource> loadedResources
All successfully loaded resources, in the order in which they were loaded.
-
loadedResourceProviders
protected java.util.List<TestResourceProvider> loadedResourceProviders
All resource providers that this model has been filled from.
-
inMemoryResourceProviders
protected java.util.List<InMemoryTestResourceProvider> inMemoryResourceProviders
This list stores copies of theloadedResourceProviders
which refer to resources which have been fully loaded in memory. It is intended as a cache to avoid repeated duplication of the sameTestResourceProvider
s. If it is null, the cache is empty and must be recreated. If not, it can be used.
-
PRINT_ALL_LOADED_SCRIPTS_PROPERTY
public static final java.lang.String PRINT_ALL_LOADED_SCRIPTS_PROPERTY
Set this system property to turn on verbose script loading. This makes Integrity list all scripts that it loads, regardless of the number of scripts being loaded. If this is turned off, only a summary is printed if more thanMAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING
scripts are being loaded.- See Also:
- Constant Field Values
-
MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING
protected static final int MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING
The maximum number of scripts which are always loaded in "verbose" mode.- See Also:
- Constant Field Values
-
verboseScriptLoading
protected final boolean verboseScriptLoading
Whether to load scripts in a verbose fashion (=printing every load).
-
MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY
protected static final java.lang.String MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY
The system property that allows to override the number of threads used to do some time-critical sections in the test runner, such as defining constants and variables.- See Also:
- Constant Field Values
-
MULTITHREADED_SECTIONS_THREAD_COUNT_DEFAULT_MAX
protected static final int MULTITHREADED_SECTIONS_THREAD_COUNT_DEFAULT_MAX
The maximum of multithreaded threads if default determination is used. This is not taken into account if a custom number of threads is set viaMULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY
.- See Also:
- Constant Field Values
-
resourceLoadingSyncObject
protected java.lang.Object resourceLoadingSyncObject
This sync object is used to synchronize access toXtextResourceFactory
,XtextResource
andXtextResourceSet
. I'm not sure if those are parallelizable, so better be safe than sorry.
-
statusOutputSyncObject
protected java.lang.Object statusOutputSyncObject
Used to synchronize potential printouts - printing to stdout with multiple threads can quickly lead to chaos.
-
-
Method Detail
-
getMultithreadedSectionsThreadCount
public int getMultithreadedSectionsThreadCount()
Returns the number of threads to use during multithreaded sections, such as defining constants and variables. This public method is located here for practical reasons - the test model and test runner both need this information, but the model needs it first, so I've placed it here.
-
getMultithreadedSectionsThreadCountDefault
protected int getMultithreadedSectionsThreadCountDefault()
Returns the default number of threads to use during multithreaded sections, such as defining constants and variables.
-
addIntegrityScriptModels
public void addIntegrityScriptModels(java.util.List<Model> someModels)
Adds all given Integrity script files to the test model.- Parameters:
someModels
- the models to add
-
addIntegrityScriptModel
public void addIntegrityScriptModel(Model aModel)
Adds a given Integrity script file to the test model.- Parameters:
aModel
- the model to add
-
readIntegrityScriptFiles
public java.util.List<Diagnostic> readIntegrityScriptFiles(TestResourceProvider aResourceProvider, boolean aPerformModelValidationFlag) throws ModelLoadException
Reads all Integrity scripts from the provided resource provider and initializes this test model with them. This is an "additive" operation, meaning that it is possible to call this method on a model multiple times and inject more and more scripts.
For each successfully loaded resource provider, a reference to the provider is stored in the model as well. The same is done for each successfully loaded resource (seeTestResource
). These references may later be retrieved bygetLoadedResourceProviders()
andgetLoadedResources()
.- Parameters:
aResourceProvider
- the resource provider to use for loadingaPerformModelValidationFlag
- whether model validation is to be done- Returns:
- any errors that happened while loading or validating
- Throws:
ModelLoadException
-
loadSingleResource
protected java.util.List<Diagnostic> loadSingleResource(TestResourceProvider aResourceProvider, TestResource aResourceName, org.eclipse.xtext.resource.XtextResourceSet aResourceSet, org.eclipse.xtext.resource.IResourceFactory aResourceFactory, boolean aVerboseFlag) throws ModelLoadException
Loads a singleTestResource
from the givenTestResourceProvider
. This method is deliberately designed to be thread-safe and shall be invoked in parallel for parallelized script loading.- Parameters:
aResourceProvider
- the resource provider to load fromaResourceName
- the resource to loadaResourceSet
- the resource set to add the resource toaResourceFactory
- the resource factory to useaVerboseFlag
- whether to make verbose output- Returns:
- a list of errors
- Throws:
ModelLoadException
-
customValidateSingleModel
protected java.util.List<Diagnostic> customValidateSingleModel(Model aModel)
Performs validation of a single model. THIS IS NOT THREAD-SAFE, as the model is being lazy-resolved during validation, which may trigger modifications to other models' internal structures.- Parameters:
aModel
- the model to validate- Returns:
- a list of validation errors (only errors are reported)
-
getInjector
public com.google.inject.Injector getInjector()
-
getModels
public java.util.List<Model> getModels()
-
getLoadedResources
public java.util.List<TestResource> getLoadedResources()
-
getLoadedResourceProviders
public java.util.List<TestResourceProvider> getLoadedResourceProviders()
-
getDuplicateDefinitions
public java.util.Set<AmbiguousDefinition> getDuplicateDefinitions()
-
getSuiteByName
public SuiteDefinition getSuiteByName(java.lang.String aFullyQualifiedSuiteName)
Resolves a fully qualified suite name to the actual suite definition.- Parameters:
aFullyQualifiedSuiteName
- the suite name- Returns:
- the suite, or null if none was found
-
getAllSuites
public java.util.Collection<SuiteDefinition> getAllSuites()
Returns all suites in the test model.- Returns:
- all suites
-
getVariantByName
public VariantDefinition getVariantByName(java.lang.String aFullyQualifiedVariantName)
Resolves a fully qualified variant name to the actual variant definition.- Parameters:
aFullyQualifiedVariantName
- the variant name- Returns:
- the variant, or null if none was found
-
getAllVariants
public java.util.Collection<VariantDefinition> getAllVariants()
-
getForkByName
public ForkDefinition getForkByName(java.lang.String aFullyQualifiedForkName)
Resolves a fully qualified fork name to the actual fork definition.- Parameters:
aFullyQualifiedForkName
- the fork name- Returns:
- the fork, or null if none was found
-
getAllForks
public java.util.Collection<ForkDefinition> getAllForks()
Returns all forks in the test model.- Returns:
- all forks
-
getCallByName
public CallDefinition getCallByName(java.lang.String aFullyQualifiedCallName)
Resolves a fully qualified call name to the actual call definition.- Parameters:
aFullyQualifiedCallName
- the call name- Returns:
- the call definition, or null if none was found
-
getAllCalls
public java.util.Collection<CallDefinition> getAllCalls()
Returns all calls in the test model.- Returns:
- all calls
-
getTestByName
public TestDefinition getTestByName(java.lang.String aFullyQualifiedTestName)
Resolves a fully qualified test name to the actual test definition.- Parameters:
aFullyQualifiedTestName
- the call name- Returns:
- the test definition, or null if none was found
-
getAllTests
public java.util.Collection<TestDefinition> getAllTests()
Returns all tests in the test model.- Returns:
- all tests
-
getVariableOrConstantByName
public VariableOrConstantEntity getVariableOrConstantByName(java.lang.String aFullyQualifiedName)
Resolves a fully qualified variable/constant name to the actual entity.- Parameters:
aFullyQualifiedName
- the name to resolve- Returns:
- the entity, or null if none was found
-
getFullyQualifiedVariableOrConstantName
public java.lang.String getFullyQualifiedVariableOrConstantName(VariableOrConstantEntity anEntity)
Returns the fully-qualified name of a variable/constant entity. The stuff returned by this equalsIntegrityDSLUtil.getQualifiedVariableEntityName(VariableOrConstantEntity, boolean)
with the boolean value set to true.- Parameters:
anEntity
- the entity to resolve- Returns:
- the name, or null if none was found
-
getVariableDefinitionsInPackages
public java.util.TreeSet<VariableDefinition> getVariableDefinitionsInPackages()
Iterates through the whole model and searches for variable definitions hosted in packages (global variables).- Returns:
- a set of variable definitions (sorted by fully qualified name)
-
getConstantDefinitionsInPackages
public java.util.TreeSet<ConstantDefinition> getConstantDefinitionsInPackages()
Iterates through the whole model and searches for constant definitions.- Returns:
- a set of constant definitions (sorted by fully qualified name)
-
loadTestModel
public static TestModel loadTestModel(TestResourceProvider aResourceProvider, boolean aSkipModelChecksFlag, boolean aPerformModelValidationFlag, java.lang.Class<? extends IntegrityDSLSetup> aSetupClass) throws ModelLoadException
Loads aTestModel
from a givenTestResourceProvider
. During this process, the files provided by the resource provider are parsed, the resulting models are linked and stored in theTestModel
container.
Errors, like unresolved symbols, will cause an exception. If a model is returned by this method, you can be sure that everything was linked fine and the model can be executed by theTestRunner
.- Parameters:
aResourceProvider
- The resource provider to use for loading the test scripts for the model.aSkipModelChecksFlag
- if true, the test runner will skip the model consistency checks it would otherwise perform during the dry runaPerformModelValidationFlag
- if true, the test runner will perform extensive model validationaSetupClass
- the setup class to use for EMF setup and Guice initialization (if null, the default class is used)- Returns:
- the test model ready for execution
- Throws:
ModelLoadException
- if any errors occur during loading (syntax errors or unresolvable references)
-
instantiateTestModel
public static TestModel instantiateTestModel(java.lang.ClassLoader aClassLoader, java.lang.Class<? extends IntegrityDSLSetup> aSetupClass, boolean aSkipModelChecksFlag)
Instantiates a TestModel using the provided setup class.- Parameters:
aClassLoader
- the class loader to use for Integrity stuffaSetupClass
- the setup class to use for EMF setup and Guice initialization (if null, the default class is used)aSkipModelChecksFlag
- if true, the test runner will skip the model consistency checks it would otherwise perform during the dry run- Returns:
- the new (but still empty) test model
-
initializeTestRunner
public TestRunner initializeTestRunner(TestRunnerCallback aCallback, java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants, java.lang.String aResultLocale, java.lang.Integer aRemotingPort, java.lang.String aRemotingBindHost, java.lang.Long aRandomSeed, java.lang.String[] someCommandLineArguments) throws java.io.IOException
Initializes a fresh test runner instance, based on this test model.- Parameters:
aCallback
- the callback to use to report test resultssomeParameterizedConstants
- Maps fully qualified constant names (must be those with the "parameterized" keyword) to their desired value. This way, test execution can be parameterized from outside.aRemotingPort
- the port on which the remoting server should listen, or null if remoting should be disabledaRemotingBindHost
- the host name (or IP) to which the remoting server should bindaRandomSeed
- the seed for theRandomNumberOperation
(optional; randomly determined if not given).someCommandLineArguments
- all command line arguments as given to the original Java programs' main routine (required for forking!)- Returns:
- the initialized test runner instance
- Throws:
java.io.IOException
- if the remoting server startup fails
-
getInMemoryResourceProviders
public java.util.List<InMemoryTestResourceProvider> getInMemoryResourceProviders() throws java.io.IOException
Returns a list of duplicates of all resource providers ever used to load test scripts into thisTestModel
. These duplicates are instances ofInMemoryTestResourceProvider
, meaning they contain the whole script data inside their instances, so nothing has to be loaded from the file system or other sources anymore. They also are transferable via Serialization, so they can be used to initialize Forks, which is their primary use!- Returns:
- duplicates of the used resource providers
- Throws:
java.io.IOException
- in case of errors during duplication
-
-