Browse Source

Make tests more stable

pull/12616/head
Andrii Landiak 2 years ago
parent
commit
f7923bc009
  1. 10
      application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java
  2. 1
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/ResourcesShortageNotificationRuleTriggerConfig.java
  3. 2
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java

10
application/src/test/java/org/thingsboard/server/service/notification/NotificationRuleApiTest.java

@ -791,10 +791,9 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
public void testNotificationRuleProcessing_resourcesShortage() throws Exception { public void testNotificationRuleProcessing_resourcesShortage() throws Exception {
loginSysAdmin(); loginSysAdmin();
ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder() ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder()
.resource(Resource.CPU.name())
.cpuThreshold(0.01f) .cpuThreshold(0.01f)
.ramThreshold(0.01f) .ramThreshold(1f)
.storageThreshold(0.01f) .storageThreshold(1f)
.build(); .build();
createNotificationRule(triggerConfig, "Test", "Test", createNotificationTarget(tenantAdminUserId).getId()); createNotificationRule(triggerConfig, "Test", "Test", createNotificationTarget(tenantAdminUserId).getId());
loginTenantAdmin(); loginTenantAdmin();
@ -805,15 +804,16 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
TimeUnit.SECONDS.sleep(5); TimeUnit.SECONDS.sleep(5);
assertThat(getMyNotifications(false, 100)).size().isEqualTo(3); assertThat(getMyNotifications(false, 100)).size().isOne();
} }
@Test @Test
public void testNotificationsDeduplication_resourcesShortage() throws Exception { public void testNotificationsDeduplication_resourcesShortage() throws Exception {
loginSysAdmin(); loginSysAdmin();
ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder() ResourcesShortageNotificationRuleTriggerConfig triggerConfig = ResourcesShortageNotificationRuleTriggerConfig.builder()
.resource(Resource.CPU.name())
.cpuThreshold(0.1f) .cpuThreshold(0.1f)
.ramThreshold(1f)
.storageThreshold(1f)
.build(); .build();
createNotificationRule(triggerConfig, "Test", "Test", createNotificationTarget(tenantAdminUserId).getId()); createNotificationRule(triggerConfig, "Test", "Test", createNotificationTarget(tenantAdminUserId).getId());
loginTenantAdmin(); loginTenantAdmin();

1
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/ResourcesShortageNotificationRuleTriggerConfig.java

@ -32,7 +32,6 @@ public class ResourcesShortageNotificationRuleTriggerConfig implements Notificat
@Serial @Serial
private static final long serialVersionUID = 339395299693241424L; private static final long serialVersionUID = 339395299693241424L;
private String resource;
@Max(1) @Max(1)
private float cpuThreshold; // in percents private float cpuThreshold; // in percents
@Max(1) @Max(1)

2
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java

@ -382,7 +382,7 @@ public class DefaultNotifications {
.icon("warning") .icon("warning")
.rule(DefaultRule.builder() .rule(DefaultRule.builder()
.name("Resources shortage") .name("Resources shortage")
.triggerConfig(ResourcesShortageNotificationRuleTriggerConfig.builder().resource(Resource.CPU.name()).cpuThreshold(0.8f).storageThreshold(0.8f).ramThreshold(0.8f).build()) .triggerConfig(ResourcesShortageNotificationRuleTriggerConfig.builder().cpuThreshold(0.8f).storageThreshold(0.8f).ramThreshold(0.8f).build())
.description("Send notification to system admins when resources shortage is running low") .description("Send notification to system admins when resources shortage is running low")
.build()) .build())
.color(RED_COLOR) .color(RED_COLOR)

Loading…
Cancel
Save