-
Notifications
You must be signed in to change notification settings - Fork 46
Call entityManager.flush()
on every entityManager
usage and dynamically remove failing UtStatementCallModel
s
#2550
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4d2f6d
Introduce deep `UtModel` mapper
IlyaMuravjov 0216ec1
Add `flush` after every `entityManager` usage
IlyaMuravjov d790ad0
Move setting up Spring specific RD responses to `SpringUtExecutionIns…
IlyaMuravjov fb342ad
Remove unused `getBean` rd call
IlyaMuravjov 66cd141
Dynamically remove failing `UtStatementModel`s
IlyaMuravjov d43d1b4
Comment out unsafe class loading of `javax.servlet.http.Cookie` (unti…
IlyaMuravjov cab471b
Avoid `mockMvc.perform((RequestBuilder) null)` tests
IlyaMuravjov 1a253c4
Address comments from #2550
IlyaMuravjov 79ef8e0
Clarify that we discard `mockMvc.perform((RequestBuilder) null)` test
IlyaMuravjov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/mapper/UtModelDeepMapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package org.utbot.framework.plugin.api.mapper | ||
|
||
import org.utbot.framework.plugin.api.UtArrayModel | ||
import org.utbot.framework.plugin.api.UtAssembleModel | ||
import org.utbot.framework.plugin.api.UtClassRefModel | ||
import org.utbot.framework.plugin.api.UtCompositeModel | ||
import org.utbot.framework.plugin.api.UtCustomModel | ||
import org.utbot.framework.plugin.api.UtEnumConstantModel | ||
import org.utbot.framework.plugin.api.UtLambdaModel | ||
import org.utbot.framework.plugin.api.UtModel | ||
import org.utbot.framework.plugin.api.UtNullModel | ||
import org.utbot.framework.plugin.api.UtPrimitiveModel | ||
import org.utbot.framework.plugin.api.UtReferenceModel | ||
import org.utbot.framework.plugin.api.UtVoidModel | ||
|
||
/** | ||
* Performs deep mapping of [UtModel]s. | ||
* | ||
* NOTE: | ||
* - [shallowMapper] is invoked on models **before** mapping their sub models. | ||
* - [shallowMapper] is responsible for caching own results (it may be called repeatedly on same models). | ||
*/ | ||
class UtModelDeepMapper private constructor( | ||
private val shallowMapper: UtModelMapper | ||
) : UtModelMapper { | ||
constructor(shallowMapper: (UtModel) -> UtModel) : this(UtModelSafeCastingCachingShallowMapper(shallowMapper)) | ||
|
||
/** | ||
* Keys are models that have been shallowly mapped by [shallowMapper]. | ||
* Values are models that have been deeply mapped by this [UtModelDeepMapper]. | ||
* Models are only associated with models of the same type (i.e. the cache type is actually `MutableMap<T, T>`) | ||
*/ | ||
private val cache = mutableMapOf<UtModel, UtModel>() | ||
|
||
private val allInputtedModels get() = cache.keys | ||
private val allOutputtedModels get() = cache.values | ||
|
||
override fun <T : UtModel> map(model: T, clazz: Class<T>): T = | ||
clazz.cast(mapNestedModels(shallowMapper.map(model, clazz))) | ||
|
||
/** | ||
* Maps models contained inside [model], but not the [model] itself. | ||
*/ | ||
private fun mapNestedModels(model: UtModel): UtModel = cache.getOrPut(model) { | ||
when (model) { | ||
is UtNullModel, | ||
is UtPrimitiveModel, | ||
is UtEnumConstantModel, | ||
is UtClassRefModel, | ||
is UtVoidModel -> model | ||
is UtArrayModel -> mapNestedModels(model) | ||
is UtCompositeModel -> mapNestedModels(model) | ||
is UtLambdaModel -> mapNestedModels(model) | ||
is UtAssembleModel -> mapNestedModels(model) | ||
is UtCustomModel -> mapNestedModels(model) | ||
|
||
// PythonModel, JsUtModel may be here | ||
else -> throw UnsupportedOperationException("UtModel $this cannot be mapped") | ||
} | ||
} | ||
|
||
private fun mapNestedModels(model: UtArrayModel): UtReferenceModel { | ||
val mappedModel = UtArrayModel( | ||
id = model.id, | ||
classId = model.classId, | ||
length = model.length, | ||
constModel = model.constModel, | ||
stores = model.stores, | ||
) | ||
cache[model] = mappedModel | ||
|
||
mappedModel.constModel = model.constModel.map(this) | ||
mappedModel.stores.putAll(model.stores.mapModelValues(this)) | ||
|
||
return mappedModel | ||
} | ||
|
||
private fun mapNestedModels(model: UtCompositeModel): UtCompositeModel { | ||
val mappedModel = UtCompositeModel( | ||
id = model.id, | ||
classId = model.classId, | ||
isMock = model.isMock, | ||
) | ||
cache[model] = mappedModel | ||
|
||
mappedModel.fields.putAll(model.fields.mapModelValues(this)) | ||
mappedModel.mocks.putAll(model.mocks.mapValuesTo(mutableMapOf()) { it.value.mapModels(this@UtModelDeepMapper) }) | ||
|
||
return mappedModel | ||
} | ||
|
||
private fun mapNestedModels(model: UtLambdaModel): UtReferenceModel = UtLambdaModel( | ||
id = model.id, | ||
samType = model.samType, | ||
declaringClass = model.declaringClass, | ||
lambdaName = model.lambdaName, | ||
capturedValues = model.capturedValues.mapModels(this@UtModelDeepMapper).toMutableList() | ||
) | ||
|
||
private fun mapNestedModels(model: UtAssembleModel): UtReferenceModel = UtAssembleModel( | ||
id = model.id, | ||
classId = model.classId, | ||
modelName = model.modelName, | ||
instantiationCall = model.instantiationCall.mapModels(this), | ||
modificationsChainProvider = { | ||
cache[model] = this@UtAssembleModel | ||
model.modificationsChain.map { it.mapModels(this@UtModelDeepMapper) } | ||
}, | ||
origin = model.origin?.mapPreservingType<UtCompositeModel>(this) | ||
) | ||
|
||
private fun mapNestedModels(model: UtCustomModel): UtReferenceModel = | ||
model.shallowMap(this) | ||
|
||
companion object { | ||
/** | ||
* Creates identity deep mapper, runs [block] on it, and returns the set of all models that | ||
* were mapped (i.e. deeply collects all models reachable from models passed to `collector`). | ||
*/ | ||
fun collectAllModels(block: (collector: UtModelDeepMapper) -> Unit): Set<UtModel> = | ||
UtModelDeepMapper(UtModelNoopMapper).also(block).allInputtedModels | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/mapper/UtModelMapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.utbot.framework.plugin.api.mapper | ||
|
||
import org.utbot.framework.plugin.api.UtCompositeModel | ||
import org.utbot.framework.plugin.api.UtModel | ||
import org.utbot.framework.plugin.api.UtModelWithCompositeOrigin | ||
|
||
interface UtModelMapper { | ||
/** | ||
* Performs depending on the implementation deep or shallow mapping of the [model]. | ||
* | ||
* In some cases (e.g. when mapping [UtModelWithCompositeOrigin.origin]) you may want to get result | ||
* of some specific type (e.g. [UtCompositeModel]), only then you should specify specific value for [clazz]. | ||
* | ||
* NOTE: if you are fine with result model and [model] having different types, then you should | ||
* use `UtModel::class.java` as a value for [clazz] or just use [UtModel.map]. | ||
*/ | ||
fun <T : UtModel> map(model: T, clazz: Class<T>): T | ||
EgorkaKulikov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
7 changes: 7 additions & 0 deletions
7
...-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/mapper/UtModelNoopMapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.utbot.framework.plugin.api.mapper | ||
|
||
import org.utbot.framework.plugin.api.UtModel | ||
|
||
object UtModelNoopMapper : UtModelMapper { | ||
EgorkaKulikov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
override fun <T : UtModel> map(model: T, clazz: Class<T>): T = model | ||
} |
15 changes: 15 additions & 0 deletions
15
...in/kotlin/org/utbot/framework/plugin/api/mapper/UtModelSafeCastingCachingShallowMapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.utbot.framework.plugin.api.mapper | ||
|
||
import org.utbot.framework.plugin.api.UtModel | ||
|
||
class UtModelSafeCastingCachingShallowMapper( | ||
val mapper: (UtModel) -> UtModel | ||
) : UtModelMapper { | ||
private val cache = mutableMapOf<UtModel, UtModel>() | ||
|
||
override fun <T : UtModel> map(model: T, clazz: Class<T>): T { | ||
val mapped = cache.getOrPut(model) { mapper(model) } | ||
return if (clazz.isInstance(mapped)) clazz.cast(mapped) | ||
else model | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/mapper/Utils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.utbot.framework.plugin.api.mapper | ||
|
||
import org.utbot.framework.plugin.api.EnvironmentModels | ||
import org.utbot.framework.plugin.api.UtDirectGetFieldModel | ||
import org.utbot.framework.plugin.api.UtDirectSetFieldModel | ||
import org.utbot.framework.plugin.api.UtExecutableCallModel | ||
import org.utbot.framework.plugin.api.UtExecution | ||
import org.utbot.framework.plugin.api.UtInstrumentation | ||
import org.utbot.framework.plugin.api.UtModel | ||
import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation | ||
import org.utbot.framework.plugin.api.UtReferenceModel | ||
import org.utbot.framework.plugin.api.UtStatementCallModel | ||
import org.utbot.framework.plugin.api.UtStatementModel | ||
import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation | ||
|
||
inline fun <reified T : UtModel> T.mapPreservingType(mapper: UtModelMapper): T = | ||
mapper.map(this, T::class.java) | ||
|
||
fun UtModel.map(mapper: UtModelMapper) = mapPreservingType<UtModel>(mapper) | ||
|
||
fun List<UtModel>.mapModels(mapper: UtModelMapper): List<UtModel> = | ||
map { model -> model.map(mapper) } | ||
|
||
fun <K> Map<K, UtModel>.mapModelValues(mapper: UtModelMapper): Map<K, UtModel> = | ||
mapValues { (_, model) -> model.map(mapper) } | ||
|
||
fun UtStatementModel.mapModels(mapper: UtModelMapper): UtStatementModel = | ||
when(this) { | ||
is UtStatementCallModel -> mapModels(mapper) | ||
is UtDirectSetFieldModel -> UtDirectSetFieldModel( | ||
instance = instance.mapPreservingType<UtReferenceModel>(mapper), | ||
fieldId = fieldId, | ||
fieldModel = fieldModel.map(mapper) | ||
) | ||
} | ||
|
||
fun UtStatementCallModel.mapModels(mapper: UtModelMapper): UtStatementCallModel = | ||
when(this) { | ||
is UtDirectGetFieldModel -> UtDirectGetFieldModel( | ||
instance = instance.mapPreservingType<UtReferenceModel>(mapper), | ||
fieldAccess = fieldAccess, | ||
) | ||
is UtExecutableCallModel -> UtExecutableCallModel( | ||
instance = instance?.mapPreservingType<UtReferenceModel>(mapper), | ||
executable = executable, | ||
params = params.mapModels(mapper) | ||
) | ||
} | ||
|
||
fun EnvironmentModels.mapModels(mapper: UtModelMapper) = EnvironmentModels( | ||
thisInstance = thisInstance?.map(mapper), | ||
statics = statics.mapModelValues(mapper), | ||
parameters = parameters.mapModels(mapper), | ||
executableToCall = executableToCall, | ||
) | ||
|
||
fun UtInstrumentation.mapModels(mapper: UtModelMapper) = when (this) { | ||
is UtNewInstanceInstrumentation -> copy(instances = instances.mapModels(mapper)) | ||
is UtStaticMethodInstrumentation -> copy(values = values.mapModels(mapper)) | ||
} | ||
|
||
fun UtExecution.mapStateBeforeModels(mapper: UtModelMapper) = copy( | ||
stateBefore = stateBefore.mapModels(mapper) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.