From 1450115061c5a2f95b6a5f8d3ee4359e528fa1d5 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 12 Dec 2024 09:50:05 +0200 Subject: [PATCH] Ensure different group schedule and start event on rollout start (#2144) Signed-off-by: Avgustin Marinov --- .../AbstractAmqpServiceIntegrationTest.java | 10 ++--- ...ssageDispatcherServiceIntegrationTest.java | 40 +++++++++---------- ...pMessageHandlerServiceIntegrationTest.java | 7 ++-- .../integration/DmfTestConfiguration.java | 5 +-- .../listener/DeadletterListener.java | 3 +- .../repository/jpa/JpaRolloutExecutor.java | 4 ++ .../jpa/management/RolloutManagementTest.java | 2 +- 7 files changed, 37 insertions(+), 34 deletions(-) diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java index 2f5f05071..d3d3f5541 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java @@ -65,13 +65,13 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.util.CollectionUtils; /** - * Common class for {@link AmqpMessageHandlerServiceIntegrationTest} and - * {@link AmqpMessageDispatcherServiceIntegrationTest}. + * Common class for {@link AmqpMessageHandlerServiceIntegrationTest} and {@link AmqpMessageDispatcherServiceIntegrationTest}. */ -@ContextConfiguration(classes = { DmfApiConfiguration.class, DmfTestConfiguration.class, +@ContextConfiguration(classes = { + DmfApiConfiguration.class, DmfTestConfiguration.class, RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class }) @Import(TestChannelBinderConfiguration.class) -public abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegrationTest { +abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegrationTest { protected static final String TENANT_EXIST = "DEFAULT"; protected static final String CREATED_BY = "CONTROLLER_PLUG_AND_PLAY"; @@ -85,7 +85,7 @@ public abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpInt private RabbitListenerTestHarness harness; @BeforeEach - public void initListener() { + void initListener() { deadletterListener = harness.getSpy(DeadletterListener.LISTENER_ID); assertThat(deadletterListener).isNotNull(); Mockito.reset(deadletterListener); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java index 6544d1b95..712475dc3 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java @@ -85,7 +85,7 @@ import org.springframework.amqp.core.Message; @Feature("Component Tests - Device Management Federation API") @Story("Amqp Message Dispatcher Service") -public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest { +class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest { private static final String TARGET_PREFIX = "Dmf_disp_"; @@ -101,7 +101,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) - public void sendDownloadAndInstallStatus() { + void sendDownloadAndInstallStatus() { final String controllerId = TARGET_PREFIX + "sendDownloadAndInstallStatus"; registerTargetAndAssignDistributionSet(controllerId); @@ -121,7 +121,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) - public void sendDownloadStatusBeforeMaintenanceWindowStartTime() { + void sendDownloadStatusBeforeMaintenanceWindowStartTime() { final String controllerId = TARGET_PREFIX + "sendDownloadStatusBeforeWindowStartTime"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -146,7 +146,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) - public void sendDownloadAndInstallStatusMessageDuringMaintenanceWindow() { + void sendDownloadAndInstallStatusMessageDuringMaintenanceWindow() { final String controllerId = TARGET_PREFIX + "sendDAndIStatusMessageDuringWindow"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -173,7 +173,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 18), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 3) }) - public void assignDistributionSetMultipleTimes() { + void assignDistributionSetMultipleTimes() { final String controllerId = TARGET_PREFIX + "assignDistributionSetMultipleTimes"; final DistributionSetAssignmentResult assignmentResult = registerTargetAndAssignDistributionSet(controllerId); @@ -221,7 +221,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void assignMultipleDsInMultiAssignMode() { + void assignMultipleDsInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "assignMultipleDsInMultiAssignMode"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -239,7 +239,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify payload of multi action messages.") - public void assertMultiActionMessagePayloads() { + void assertMultiActionMessagePayloads() { final int expectedWeightIfNotSet = 1000; final int weight1 = 600; final String controllerId = UUID.randomUUID().toString(); @@ -303,7 +303,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void cancelActionInMultiAssignMode() { + void cancelActionInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "cancelActionInMultiAssignMode"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -341,7 +341,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void finishActionInMultiAssignMode() { + void finishActionInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "finishActionInMultiAssignMode"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -373,7 +373,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void assignDsMultipleTimesInMultiAssignMode() { + void assignDsMultipleTimesInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "assignDsMultipleTimesInMultiAssignMode"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -407,9 +407,9 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = RolloutCreatedEvent.class, count = 2), @Expect(type = RolloutUpdatedEvent.class, count = 6), @Expect(type = RolloutGroupCreatedEvent.class, count = 2), - @Expect(type = RolloutGroupUpdatedEvent.class, count = 4), + @Expect(type = RolloutGroupUpdatedEvent.class, count = 6), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void startRolloutsWithSameDsInMultiAssignMode() { + void startRolloutsWithSameDsInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "startRolloutsWithSameDsInMultiAssignMode"; @@ -444,9 +444,9 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = RolloutCreatedEvent.class, count = 3), @Expect(type = RolloutUpdatedEvent.class, count = 9), @Expect(type = RolloutGroupCreatedEvent.class, count = 3), - @Expect(type = RolloutGroupUpdatedEvent.class, count = 6), + @Expect(type = RolloutGroupUpdatedEvent.class, count = 9), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) - public void startMultipleRolloutsAndFinishInMultiAssignMode() { + void startMultipleRolloutsAndFinishInMultiAssignMode() { enableMultiAssignments(); final String controllerId = TARGET_PREFIX + "startMultipleRolloutsAndFinishInMultiAssignMode"; @@ -492,7 +492,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) - public void sendCancelStatus() { + void sendCancelStatus() { final String controllerId = TARGET_PREFIX + "sendCancelStatus"; final Long actionId = registerTargetAndCancelActionId(controllerId); @@ -508,7 +508,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TargetDeletedEvent.class, count = 1) }) - public void sendDeleteMessage() { + void sendDeleteMessage() { final String controllerId = TARGET_PREFIX + "sendDeleteMessage"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -530,7 +530,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = TargetAttributesRequestedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) - public void attributeRequestAfterSuccessfulUpdate() { + void attributeRequestAfterSuccessfulUpdate() { final String controllerId = TARGET_PREFIX + "attributeUpdateRequest"; registerAndAssertTargetWithExistingTenant(controllerId); @@ -557,7 +557,7 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) - public void downloadOnlyAssignmentSendsDownloadMessageTopic() { + void downloadOnlyAssignmentSendsDownloadMessageTopic() { final String controllerId = TARGET_PREFIX + "registerTargets_1"; final DistributionSet distributionSet = createTargetAndDistributionSetAndAssign(controllerId, DOWNLOAD_ONLY); @@ -580,13 +580,13 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify payload of batch assignment download and install message.") - public void assertBatchAssignmentsDownloadAndInstall() { + void assertBatchAssignmentsDownloadAndInstall() { assertBatchAssignmentsMessagePayload(BATCH_DOWNLOAD_AND_INSTALL); } @Test @Description("Verify payload of batch assignments download only message.") - public void assertBatchAssignmentsDownloadOnly() { + void assertBatchAssignmentsDownloadOnly() { assertBatchAssignmentsMessagePayload(BATCH_DOWNLOAD); } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java index 1d12a11cd..d54b8850f 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java @@ -84,10 +84,11 @@ import org.springframework.beans.factory.annotation.Autowired; @Story("Amqp Message Handler Service") class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegrationTest { - public static final String DMF_REGISTER_TEST_CONTROLLER_ID = "Dmf_hand_registerTargets_1"; - public static final String DMF_ATTR_TEST_CONTROLLER_ID = "Dmf_hand_updateAttributes"; - public static final String UPDATE_ATTR_TEST_CONTROLLER_ID = "ControllerAttributeTestTarget"; + static final String DMF_REGISTER_TEST_CONTROLLER_ID = "Dmf_hand_registerTargets_1"; + static final String DMF_ATTR_TEST_CONTROLLER_ID = "Dmf_hand_updateAttributes"; + static final String UPDATE_ATTR_TEST_CONTROLLER_ID = "ControllerAttributeTestTarget"; private static final String TARGET_PREFIX = "Dmf_hand_"; + @Autowired private AmqpProperties amqpProperties; diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/DmfTestConfiguration.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/DmfTestConfiguration.java index 90e7d4b5d..ca4000a5b 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/DmfTestConfiguration.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/DmfTestConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @RabbitListenerTest -public class DmfTestConfiguration { +class DmfTestConfiguration { public static final String REPLY_TO_EXCHANGE = "reply.queue"; @@ -52,5 +52,4 @@ public class DmfTestConfiguration { Binding bindQueueToReplyToExchange() { return BindingBuilder.bind(replyToQueue()).to(replyToExchange()); } - -} +} \ No newline at end of file diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/listener/DeadletterListener.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/listener/DeadletterListener.java index 5c337a516..9aac7f0cb 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/listener/DeadletterListener.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/listener/DeadletterListener.java @@ -22,5 +22,4 @@ public class DeadletterListener implements TestRabbitListener { public void handleMessage(Message message) { // currently the message is not needed } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java index 76c6e5631..1212bd417 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java @@ -574,7 +574,11 @@ public class JpaRolloutExecutor implements RolloutExecutor { private boolean ensureAllGroupsAreScheduled(final Rollout rollout) { final JpaRollout jpaRollout = (JpaRollout) rollout; final List groupsToBeScheduled = rolloutGroupRepository.findByRolloutAndStatus(rollout, RolloutGroupStatus.READY); + if (groupsToBeScheduled.isEmpty()) { + return true; + } final long scheduledGroups = groupsToBeScheduled.stream().filter(group -> scheduleRolloutGroup(jpaRollout, group)).count(); + entityManager.flush(); // flush groups so scheduled group to start to have scheduled event return scheduledGroups == groupsToBeScheduled.size(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java index 50ea4b1a8..de49b9471 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java @@ -1816,7 +1816,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest { @Expect(type = RolloutCreatedEvent.class, count = 1), @Expect(type = RolloutUpdatedEvent.class, count = 6), @Expect(type = RolloutDeletedEvent.class, count = 1), - @Expect(type = RolloutGroupUpdatedEvent.class, count = 10), + @Expect(type = RolloutGroupUpdatedEvent.class, count = 11), @Expect(type = RolloutGroupCreatedEvent.class, count = 5) }) void deleteRolloutWhichHasBeenStartedBeforeIsSoftDeleted() { final int amountTargetsForRollout = 10;