Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
[W-5911360] fix NPE exception for Notification objects, + additional …
Browse files Browse the repository at this point in the history
…cleanup (alert) (#356)

* Cleaning up print statements

* [W-5911360] fix NPE exception for Notification objects
https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07B0000006UcZVIA0/view
@Rev sudhanshu-bahety@ nkarri@ knawale@
  • Loading branch information
Nikhil Wahi authored and GitHub Enterprise committed Apr 2, 2019
1 parent 6857f74 commit ed104e8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public Notification(String name, Alert alert, String notifierName, List<String>
setNotifierName(notifierName);
setSubscriptions(subscriptions);
setCooldownPeriod(cooldownPeriod);
initializeNotificationData();
}

/**
Expand Down Expand Up @@ -741,15 +742,12 @@ private void setNotificationCustomData(String notificationCustomData) {
}

private JsonObject getJsonObject() {
JsonObject GOCFields = new JsonObject();
JsonObject GOCFields;
try {
GOCFields = new JsonParser().parse(this.notificationCustomData).getAsJsonObject();
} catch (Exception ex) {
_logger.debug("Unable to parse notification object. Creating a new object. Exception: {}", ex);
GOCFields.addProperty(ARTICLE_NUMBER_KEY, "");
GOCFields.addProperty(EVENT_NAME_KEY, "");
GOCFields.addProperty(ELEMENT_NAME_KEY, "");
GOCFields.addProperty(PRODUCT_TAG_KEY, "");
_logger.debug("Unable to parse notification object. Creating a new object. Exception: {}", ex.getMessage());
GOCFields = getEmptyNotificationCustomData();
}
return GOCFields;
}
Expand All @@ -769,6 +767,19 @@ private String getGOCField(final String fieldName) {
}
}

private JsonObject getEmptyNotificationCustomData() {
JsonObject GOCFields = new JsonObject();
GOCFields.addProperty(ARTICLE_NUMBER_KEY, "");
GOCFields.addProperty(EVENT_NAME_KEY, "");
GOCFields.addProperty(ELEMENT_NAME_KEY, "");
GOCFields.addProperty(PRODUCT_TAG_KEY, "");
return GOCFields;
}

private void initializeNotificationData() {
this.notificationCustomData = getEmptyNotificationCustomData().toString();
}

@Override
public int hashCode() {
int hash = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand All @@ -15,6 +17,8 @@

public class AnnotationTest {

private final Logger _logger = LoggerFactory.getLogger(AnnotationTest.class);

@Test
public void testGetSizeBytes() throws Exception {
Annotation a = new Annotation("source",
Expand Down Expand Up @@ -58,7 +62,7 @@ public void testGetSizeBytes() throws Exception {
fail(String.format("Unsupported type=%s for field=%s, please update this test", t, f.getName()));
}
}
System.out.println(String.format("field=%s, size=%d", f.getName(), expectedSize));
_logger.debug(String.format("field=%s, size=%d", f.getName(), expectedSize));
}

int size = a.computeSizeBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public void testNumHoursUntilNextFlushBloomFilter() {
// Will wait 24 hours before next flush if at same hour boundary
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int secondsUntil = _esSchemaService.getNumSecondsUntilTargetHour(hour);
System.out.println(secondsUntil);
assertTrue(secondsUntil >= 23 * 60 * 60 && secondsUntil <= 24 * 60 * 60);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.util.TreeMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -53,6 +55,8 @@ public class AbstractTSDBServiceTest {

static private SystemMain system;

private final Logger _logger = LoggerFactory.getLogger(AbstractTSDBServiceTest.class);

@BeforeClass
static public void setUpClass() {
system = TestUtils.getInstance();
Expand Down Expand Up @@ -388,7 +392,7 @@ public void testCyclingIterator() {
Iterator<String> iter = service.constructCyclingIterator(endpoints);
List<Thread> threads = new ArrayList<>();
ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
System.out.println(String.format("Trying %d .next() calls with %d threads calling cycling iterator on endpoints %s", RUNS, THREADS, String.join(", ", endpoints)));
_logger.debug(String.format("Trying %d .next() calls with %d threads calling cycling iterator on endpoints %s", RUNS, THREADS, String.join(", ", endpoints)));
for (int i = 0; i < THREADS; i++) {
Thread thread = new Thread(new IterateTask(iter, queue));
threads.add(thread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public void testCronLoop() {
try {
Thread.sleep(200);
}catch (Exception e) {
System.out.println("Exiting");
return;
}
testCronTrigger();
Expand All @@ -145,13 +144,6 @@ public void testCronTrigger() {

Date nextFireTime = cronTrigger.getFireTimeAfter(previousMinuteLastSecondTime);

if(nextFireTime.equals(fireTime))
{
System.out.println(String.format("Current Time %s: Fire Time %s Matches", sdf.format(new Date()), sdf.format(nextFireTime)));
} else {
System.out.println(String.format("Current Time %s: Fire Time %s", sdf.format(new Date()), sdf.format(nextFireTime)));
}

assertTrue(nextFireTime.equals(fireTime));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ public void testConvertCronEntryToQuartzCronEntry() {
quartzCron = Cron.convertToQuartzCronEntry(inputCrons[i]);
converted = true;
isValid = Cron.isCronEntryValid(inputCron);
if (!isValid)
System.out.println(String.format("%d: '%s' -> '%s' is %sa valid quartz cron.", i, inputCron, quartzCron, isValid ? "": "NOT "));
// if (!isValid)
// System.out.println(String.format("%d: '%s' -> '%s' is %sa valid quartz cron.", i, inputCron, quartzCron, isValid ? "": "NOT "));
}
catch (Exception e)
{
Expand Down Expand Up @@ -495,9 +495,9 @@ private boolean compareTranslations(String cronExpr, int steps)

if (!isSame)
{
System.out.println(String.format("Testing Cron '%s' -> old = '%s', new = '%s' --> Comparison failed at step %d", cronExpr, oldQuartz, newQuartz, i ));
System.out.println(String.format("%s %s %s", i,
oldWhen.toString(), isSame ? "==" : "!=", newWhen.toString()));
// System.out.println(String.format("Testing Cron '%s' -> old = '%s', new = '%s' --> Comparison failed at step %d", cronExpr, oldQuartz, newQuartz, i ));
// System.out.println(String.format("%s %s %s", i,
// oldWhen.toString(), isSame ? "==" : "!=", newWhen.toString()));
success = false;
break;
}
Expand All @@ -506,7 +506,6 @@ private boolean compareTranslations(String cronExpr, int steps)
}
catch (RuntimeException e)
{
System.out.println(String.format("Error in test: %s", e.getMessage()));
e.printStackTrace();
success = false;
}
Expand Down

0 comments on commit ed104e8

Please sign in to comment.