<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.Map;
import java.util.TimerTask;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
ArrayList<String> expiredEvents = null;
- for (ConcurrentHashMap.Entry<String, EventData> entry : eventInfo.entrySet()) {
+ for (Map.Entry<String, EventData> entry : eventInfo.entrySet()) {
EventData event = entry.getValue();
startTime = event.getStartTime();
ns = Duration.between(startTime, Instant.now()).getSeconds();
import java.util.Iterator;
import java.util.Properties;
import java.util.Timer;
-import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
private static String hostAddress = null;
private static String component = null;
- private static TimerTask ttrcker = null;
private static boolean isEventTrackerRunning = false;
private static Timer timer = null;
private static void startCleanUp() {
if (!isEventTrackerRunning) {
- ttrcker = new EventTrackInfoHandler();
+ EventTrackInfoHandler ttrcker = new EventTrackInfoHandler();
timer = new Timer(true);
timer.scheduleAtFixedRate(ttrcker, timerDelayTime, checkInterval);
debugLogger.info("EventTrackInfoHandler begins! : " + new Date());
// do nothing
}
+ /*
+ * As the comment above says, these purposely write to System.out rather than a
+ * logger, thus sonar is disabled.
+ */
+
public static void displayMessage(Object message) {
- System.out.println(message);
+ System.out.println(message); // NOSONAR
}
public static void displayErrorMessage(Object msg) {
- System.err.println(msg);
+ System.err.println(msg); // NOSONAR
}
}
className = new FlexLogger().getClassName();
}
- if (!eelfLoggerMap.containsKey(className)) {
- logger = new EelfLogger(clazz, isNewTransaction);
- eelfLoggerMap.put(className, logger);
- } else {
- logger = eelfLoggerMap.get(className);
- if (logger == null) {
- logger = new EelfLogger(clazz, isNewTransaction);
- eelfLoggerMap.put(className, logger);
- }
- // installl already created but it is new transaction
- if (isNewTransaction) {
- String transId = PolicyLogger.postMdcInfoForEvent(null);
- logger.setTransId(transId);
- }
+ logger = eelfLoggerMap.computeIfAbsent(className, key -> new EelfLogger(clazz, isNewTransaction));
+
+ if (isNewTransaction) {
+ String transId = PolicyLogger.postMdcInfoForEvent(null);
+ logger.setTransId(transId);
}
+
displayMessage("eelfLoggerMap size : " + eelfLoggerMap.size() + " class name: " + className);
return logger;
}
private void writeObject(ObjectOutputStream out) throws IOException {
// write out 'methodName', 'className', 'transId' strings
- out.writeObject(methodName);
- out.writeObject(className);
- out.writeObject(transId);
+ out.writeUTF(methodName);
+ out.writeUTF(className);
+ out.writeUTF(transId);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
// read in 'methodName', 'className', 'transId' strings
- methodName = (String) (in.readObject());
- className = (String) (in.readObject());
- transId = (String) (in.readObject());
+ methodName = in.readUTF();
+ className = in.readUTF();
+ transId = in.readUTF();
// look up associated logger
log = Logger.getLogger(className);
* This may be overridden by junit tests.
*/
private static Timer timer = new Timer("PropertyUtil-Timer", true);
+
+ private LazyHolder() {
+ super();
+ }
}
// this table maps canonical file into a 'ListenerRegistration' instance
*/
public static Properties getProperties(File file) throws IOException {
// create an InputStream (may throw a FileNotFoundException)
- FileInputStream fis = new FileInputStream(file);
- try {
+ try (FileInputStream fis = new FileInputStream(file)) {
// create the properties instance
Properties rval = new Properties();
// load properties (may throw an IOException)
rval.load(fis);
return rval;
- } finally {
- // close input stream
- fis.close();
}
}
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@Test
public void testInitNullProperties() {
- PolicyLogger.init(null);
+ assertThatCode(() -> PolicyLogger.init(null)).doesNotThrowAnyException();
}
@Test
properties.setProperty("stop.check.point", "0");
properties.setProperty("logger.property", "LOG4J");
- PolicyLogger.init(properties);
+ assertThatCode(() -> PolicyLogger.init(properties)).doesNotThrowAnyException();
}
@Test
package org.onap.policy.common.logging.flexlogger;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
changedKeys.add("error.level");
changedKeys.add("audit.level");
PropertiesCallBack propertiesCallBack = new PropertiesCallBack("name");
- propertiesCallBack.propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys);
+ assertThatCode(() -> propertiesCallBack
+ .propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys))
+ .doesNotThrowAnyException();
}
}
package org.onap.policy.common.logging.flexlogger;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@Test
public void testLogger4JClassOfQ() {
- new Logger4J(this.getClass());
+ assertThatCode(() -> new Logger4J(this.getClass())).doesNotThrowAnyException();
}
@Test
package org.onap.policy.common.logging.flexlogger;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@Test
public void testSystemOutLoggerClassOfQ() {
- new SystemOutLogger(SystemOutLoggerTest.class);
+ assertThatCode(() -> new SystemOutLogger(SystemOutLoggerTest.class)).doesNotThrowAnyException();
}
@Test