Ensure different group schedule and start event on rollout start (#2144)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-12 09:50:05 +02:00
committed by GitHub
parent f813be87e5
commit 1450115061
7 changed files with 37 additions and 34 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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());
}
}
}

View File

@@ -22,5 +22,4 @@ public class DeadletterListener implements TestRabbitListener {
public void handleMessage(Message message) {
// currently the message is not needed
}
}
}

View File

@@ -574,7 +574,11 @@ public class JpaRolloutExecutor implements RolloutExecutor {
private boolean ensureAllGroupsAreScheduled(final Rollout rollout) {
final JpaRollout jpaRollout = (JpaRollout) rollout;
final List<JpaRolloutGroup> 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();
}

View File

@@ -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;