Skip to content

Commit

Permalink
Enable single daily by default + update tests (RedHatInsights#2671)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-duval authored Apr 24, 2024
1 parent 60cafa8 commit 8e0c0a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .rhcicd/clowdapp-aggregator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ parameters:
description: Should the aggregation cron job be disabled?
value: "false"
- name: NOTIFICATIONS_BUNDLE_LEVEL_DIGEST_ENABLED
value: "false"
value: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static String toggleName(String feature) {
@Deprecated(forRemoval = true, since = "To be removed when we're done migrating to Unleash in all environments")
boolean unleashEnabled;

@ConfigProperty(name = "notifications.bundle.level.digest.enabled", defaultValue = "false")
@ConfigProperty(name = "notifications.bundle.level.digest.enabled", defaultValue = "true")
@Deprecated(forRemoval = true, since = "To be removed when we're done migrating to Unleash in all environments")
boolean singleDailyDigestEnabled;

Expand Down Expand Up @@ -63,7 +63,7 @@ void logConfigAtStartup(@Observes Startup event) {

public boolean isSingleDailyDigestEnabled() {
if (unleashEnabled) {
return unleash.isEnabled(singleDailyDigestToggle, false);
return unleash.isEnabled(singleDailyDigestToggle, true);
} else {
return singleDailyDigestEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.redhat.cloud.notifications;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.cloud.notifications.helpers.ResourceHelpers;
import com.redhat.cloud.notifications.ingress.Action;
import com.redhat.cloud.notifications.ingress.Event;
import com.redhat.cloud.notifications.ingress.Parser;
import com.redhat.cloud.notifications.models.AggregationCommand;
import com.redhat.cloud.notifications.models.AggregationOrgConfig;
Expand Down Expand Up @@ -75,20 +75,22 @@ void initAggregationParameters() {
testee.defaultDailyDigestTime = LocalTime.now(ZoneOffset.UTC);
}

List<AggregationCommand> getRecordsFromKafka() throws JsonProcessingException {
List<AggregationCommand> getRecordsFromKafka() {
List<AggregationCommand> aggregationCommands = new ArrayList<>();

InMemorySink<String> results = connector.sink(DailyEmailAggregationJob.EGRESS_CHANNEL);
for (Message message : results.received()) {
Action action = Parser.decode(String.valueOf(message.getPayload()));
aggregationCommands.add(objectMapper.convertValue(action.getEvents().get(0).getPayload().getAdditionalProperties(), AggregationCommand.class));
for (Event event : action.getEvents()) {
aggregationCommands.add(objectMapper.convertValue(event.getPayload().getAdditionalProperties(), AggregationCommand.class));
}
}

return aggregationCommands;
}

@Test
void shouldSentFourAggregationsToKafkaTopic() throws JsonProcessingException {
void shouldSentFourAggregationsToKafkaTopic() {

helpers.addEmailAggregation("someOrgId", "rhel", "policies", "somePolicyId", "someHostId");
helpers.addEmailAggregation("anotherOrgId", "rhel", "policies", "somePolicyId", "someHostId");
Expand All @@ -100,14 +102,14 @@ void shouldSentFourAggregationsToKafkaTopic() throws JsonProcessingException {

List<AggregationCommand> listCommand = getRecordsFromKafka();
assertEquals(4, listCommand.size());
checkAggCommand(listCommand.get(0), "anotherOrgId", "rhel", "policies");
checkAggCommand(listCommand.get(1), "anotherOrgId", "rhel", "unknown-application");
checkAggCommand(listCommand.get(2), "someOrgId", "rhel", "policies");
checkAggCommand(listCommand.get(3), "someOrgId", "rhel", "unknown-application");
checkAggCommand(listCommand, "anotherOrgId", "rhel", "policies");
checkAggCommand(listCommand, "anotherOrgId", "rhel", "unknown-application");
checkAggCommand(listCommand, "someOrgId", "rhel", "policies");
checkAggCommand(listCommand, "someOrgId", "rhel", "unknown-application");
}

@Test
void shouldSentTwoAggregationsToKafkaTopic() throws JsonProcessingException {
void shouldSentTwoAggregationsToKafkaTopic() {
LocalTime now = LocalTime.now(ZoneOffset.UTC);
helpers.addEmailAggregation("someOrgId", "rhel", "policies", "somePolicyId", "someHostId");
helpers.addEmailAggregation("anotherOrgId", "rhel", "policies", "somePolicyId", "someHostId");
Expand All @@ -123,8 +125,8 @@ void shouldSentTwoAggregationsToKafkaTopic() throws JsonProcessingException {
List<AggregationCommand> listCommand = getRecordsFromKafka();
assertEquals(2, listCommand.size());

checkAggCommand(listCommand.get(0), "anotherOrgId", "rhel", "policies");
checkAggCommand(listCommand.get(1), "anotherOrgId", "rhel", "unknown-application");
checkAggCommand(listCommand, "anotherOrgId", "rhel", "policies");
checkAggCommand(listCommand, "anotherOrgId", "rhel", "unknown-application");

// remove all preferences, and set default hour in the past, nothing should be processed
helpers.purgeAggregationOrgConfig();
Expand All @@ -148,15 +150,17 @@ void shouldSentTwoAggregationsToKafkaTopic() throws JsonProcessingException {
listCommand = getRecordsFromKafka();
assertEquals(2, listCommand.size());

checkAggCommand(listCommand.get(0), "someOrgId", "rhel", "policies");
checkAggCommand(listCommand.get(1), "someOrgId", "rhel", "unknown-application");
checkAggCommand(listCommand, "someOrgId", "rhel", "policies");
checkAggCommand(listCommand, "someOrgId", "rhel", "unknown-application");
}

private void checkAggCommand(AggregationCommand command, String orgId, String bundle, String application) {
assertEquals(orgId, command.getAggregationKey().getOrgId());
assertEquals(bundle, command.getAggregationKey().getBundle());
assertEquals(application, command.getAggregationKey().getApplication());
assertEquals(DAILY, command.getSubscriptionType());
private void checkAggCommand(List<AggregationCommand> commands, String orgId, String bundle, String application) {
assertTrue(commands.stream().anyMatch(
com -> orgId.equals(com.getAggregationKey().getOrgId()) &&
bundle.equals(com.getAggregationKey().getBundle()) &&
application.equals(com.getAggregationKey().getApplication()) &&
DAILY.equals(com.getSubscriptionType())
));
}

@Test
Expand Down

0 comments on commit 8e0c0a1

Please sign in to comment.