Transaction handling refactoring (#771)
* unified new transaction handling in jpa repositories, extended Deployment Management and Action Repository Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * moved Deployment Helper to utilities package Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * removed superfluous utility method from Deployment Helper Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * refactored distribution set to target assignment, fixed PR review findings Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * fixed PR review findings Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * added additional validation of active flag and current status fields for action status update repository method Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * fixed timing issue in amqp message handler integration test, when validating target attributes update Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
b06928d089
commit
a2c1e5f132
@@ -655,7 +655,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
// update mode REPLACE
|
||||
updateAttributesWithUpdateModeReplace(controllerId);
|
||||
|
||||
// update mode REPLACE
|
||||
// update mode MERGE
|
||||
updateAttributesWithUpdateModeMerge(controllerId);
|
||||
|
||||
// update mode REMOVE
|
||||
@@ -675,6 +675,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
final Map<String, String> removeAttributes = new HashMap<>();
|
||||
removeAttributes.put("k1", "foo");
|
||||
removeAttributes.put("k3", "bar");
|
||||
|
||||
final DmfAttributeUpdate remove = new DmfAttributeUpdate();
|
||||
remove.setMode(DmfUpdateMode.REMOVE);
|
||||
remove.getAttributes().putAll(removeAttributes);
|
||||
@@ -694,6 +695,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
final Map<String, String> mergeAttributes = new HashMap<>();
|
||||
mergeAttributes.put("k1", "v1_modified_again");
|
||||
mergeAttributes.put("k4", "v4");
|
||||
|
||||
final DmfAttributeUpdate merge = new DmfAttributeUpdate();
|
||||
merge.setMode(DmfUpdateMode.MERGE);
|
||||
merge.getAttributes().putAll(mergeAttributes);
|
||||
@@ -710,33 +712,33 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
private void updateAttributesWithUpdateModeReplace(final String controllerId) {
|
||||
|
||||
// send a update message with update mode REPLACE
|
||||
final Map<String, String> replacementAttributes = new HashMap<>();
|
||||
replacementAttributes.put("k1", "v1_modified");
|
||||
replacementAttributes.put("k2", "v2");
|
||||
replacementAttributes.put("k3", "v3");
|
||||
final Map<String, String> expectedAttributes = new HashMap<>();
|
||||
expectedAttributes.put("k1", "v1_modified");
|
||||
expectedAttributes.put("k2", "v2");
|
||||
expectedAttributes.put("k3", "v3");
|
||||
|
||||
final DmfAttributeUpdate replace = new DmfAttributeUpdate();
|
||||
replace.setMode(DmfUpdateMode.REPLACE);
|
||||
replace.getAttributes().putAll(replacementAttributes);
|
||||
replace.getAttributes().putAll(expectedAttributes);
|
||||
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, replace);
|
||||
|
||||
// validate
|
||||
final Map<String, String> expectedAttributes = replacementAttributes;
|
||||
assertUpdateAttributes(controllerId, expectedAttributes);
|
||||
}
|
||||
|
||||
@Step
|
||||
private void updateAttributesWithoutUpdateMode(final String controllerId) {
|
||||
|
||||
// send a update message which does not specify a update mode
|
||||
final Map<String, String> initialAttributes = new HashMap<>();
|
||||
initialAttributes.put("k0", "v0");
|
||||
initialAttributes.put("k1", "v1");
|
||||
// send a update message which does not specify an update mode
|
||||
final Map<String, String> expectedAttributes = new HashMap<>();
|
||||
expectedAttributes.put("k0", "v0");
|
||||
expectedAttributes.put("k1", "v1");
|
||||
|
||||
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate();
|
||||
defaultUpdate.getAttributes().putAll(initialAttributes);
|
||||
defaultUpdate.getAttributes().putAll(expectedAttributes);
|
||||
sendUpdateAttributeMessage(controllerId, TENANT_EXIST, defaultUpdate);
|
||||
|
||||
// validate
|
||||
final Map<String, String> expectedAttributes = initialAttributes;
|
||||
assertUpdateAttributes(controllerId, expectedAttributes);
|
||||
}
|
||||
|
||||
@@ -807,7 +809,8 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
verifyNumberOfDeadLetterMessages(3);
|
||||
}
|
||||
|
||||
private void sendUpdateAttributesMessageWithGivenAttributes(final String target, final String key, final String value) {
|
||||
private void sendUpdateAttributesMessageWithGivenAttributes(final String target, final String key,
|
||||
final String value) {
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put(key, value);
|
||||
final Message message = createUpdateAttributesMessage(target, TENANT_EXIST, controllerAttribute);
|
||||
@@ -893,7 +896,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
||||
|
||||
private void verifyNumberOfDeadLetterMessages(final int numberOfInvocations) {
|
||||
assertEmptyReceiverQueueCount();
|
||||
createConditionFactory()
|
||||
.until(() -> Mockito.verify(getDeadletterListener(), Mockito.times(numberOfInvocations)).handleMessage(Mockito.any()));
|
||||
createConditionFactory().until(() -> Mockito.verify(getDeadletterListener(), Mockito.times(numberOfInvocations))
|
||||
.handleMessage(Mockito.any()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
protected void assertRequestAttributesUpdateMessage(final String target) {
|
||||
assertReplyMessageHeader(EventTopic.REQUEST_ATTRIBUTES_UPDATE, target);
|
||||
}
|
||||
|
||||
|
||||
protected void assertRequestAttributesUpdateMessageAbsent() {
|
||||
assertThat(replyToListener.getEventTopicMessages()).doesNotContainKey(EventTopic.REQUEST_ATTRIBUTES_UPDATE);
|
||||
}
|
||||
@@ -352,12 +352,18 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
|
||||
|
||||
@Step
|
||||
protected void assertUpdateAttributes(final String controllerId, final Map<String, String> attributes) {
|
||||
final Target findByControllerId = waitUntilIsPresent(
|
||||
() -> controllerManagement.getByControllerId(controllerId));
|
||||
final Map<String, String> controllerAttributes = targetManagement
|
||||
.getControllerAttributes(findByControllerId.getControllerId());
|
||||
assertThat(controllerAttributes.size()).isEqualTo(attributes.size());
|
||||
attributes.forEach((k, v) -> assertKeyValueInMap(k, v, controllerAttributes));
|
||||
waitUntilIsPresent(() -> controllerManagement.getByControllerId(controllerId));
|
||||
|
||||
createConditionFactory().until(() -> {
|
||||
try {
|
||||
final Map<String, String> controllerAttributes = securityRule
|
||||
.runAsPrivileged(() -> targetManagement.getControllerAttributes(controllerId));
|
||||
assertThat(controllerAttributes.size()).isEqualTo(attributes.size());
|
||||
attributes.forEach((k, v) -> assertKeyValueInMap(k, v, controllerAttributes));
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertKeyValueInMap(final String key, final String value,
|
||||
|
||||
Reference in New Issue
Block a user