Performance optimizations for Multi-Assignments (#858)
* Add remote event test for the new MultiActionEvent * Improve test descriptions * Improve sendMultiActionRequestMessages * Moved action filtering to the database query level (#12) * Use @ExpectedEvents instead of EventHandlerStubs * Removed @Param from 'existsByTargetControllerIdAndStatusAndActiveIsTrue' * Reverted metadata initialization * Fix hawkBit bot findings Signed-off-by: Stefan Behl <stefan.behl@bosch-si.com> Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com>
This commit is contained in:
@@ -135,21 +135,21 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer
|
||||
@Test
|
||||
@Description("Verify that a distribution assignment multiple times send cancel and assign events with right softwaremodules")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
|
||||
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 1),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
|
||||
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6),
|
||||
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 12),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 3) })
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 2) })
|
||||
public void assignDistributionSetMultipleTimes() {
|
||||
final String controllerId = TARGET_PREFIX + "assignDistributionSetMultipleTimes";
|
||||
|
||||
final DistributionSetAssignmentResult assignmentResult = registerTargetAndAssignDistributionSet(controllerId);
|
||||
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
||||
registerTargetAndAssignDistributionSet(distributionSet2.getId(), TargetUpdateStatus.PENDING,
|
||||
getDistributionSet().getModules(), controllerId);
|
||||
testdataFactory.addSoftwareModuleMetadata(distributionSet2);
|
||||
assignDistributionSet(distributionSet2.getId(), controllerId);
|
||||
assertDownloadAndInstallMessage(distributionSet2.getModules(), controllerId);
|
||||
assertCancelActionMessage(assignmentResult.getActionIds().get(0), controllerId);
|
||||
|
||||
createAndSendThingCreated(controllerId, TENANT_EXIST);
|
||||
|
||||
@@ -57,50 +57,27 @@ public final class SoftwareModuleJsonMatcher {
|
||||
this.expectedModules = expectedModules;
|
||||
}
|
||||
|
||||
static boolean containsExactly(final Object actual, final List<DmfSoftwareModule> expected) {
|
||||
boolean containsExactly(final Object actual) {
|
||||
if (actual == null) {
|
||||
return expected == null;
|
||||
return expectedModules == null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Collection<SoftwareModule> modules = (Collection<SoftwareModule>) actual;
|
||||
|
||||
if (modules.size() != expected.size()) {
|
||||
return false;
|
||||
}
|
||||
return expectedModules.stream().allMatch(e -> existsIn(e, modules));
|
||||
}
|
||||
|
||||
for (final SoftwareModule repoSoftwareModule : modules) {
|
||||
boolean containsElement = false;
|
||||
|
||||
for (final DmfSoftwareModule jsonSoftwareModule : expected) {
|
||||
if (!jsonSoftwareModule.getModuleId().equals(repoSoftwareModule.getId())) {
|
||||
continue;
|
||||
}
|
||||
containsElement = true;
|
||||
|
||||
if (!jsonSoftwareModule.getModuleType().equals(repoSoftwareModule.getType().getKey())) {
|
||||
return false;
|
||||
}
|
||||
if (!jsonSoftwareModule.getModuleVersion().equals(repoSoftwareModule.getVersion())) {
|
||||
return false;
|
||||
}
|
||||
if (jsonSoftwareModule.getArtifacts().size() != repoSoftwareModule.getArtifacts().size()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!containsElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
private static boolean existsIn(final DmfSoftwareModule module, final Collection<SoftwareModule> actual) {
|
||||
return actual.stream()
|
||||
.anyMatch(e -> module.getModuleType().equals(e.getType().getKey())
|
||||
&& module.getModuleVersion().equals(e.getVersion())
|
||||
&& module.getArtifacts().size() == e.getArtifacts().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(final Object actualValue) {
|
||||
return containsExactly(actualValue, expectedModules);
|
||||
return containsExactly(actualValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user