Skip to content

Commit

Permalink
Resolving some quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cfillol committed Apr 1, 2014
1 parent fcd886f commit a9b7e7e
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 201 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.classpath
.project
.settings
target
!/sonar-jmeter-plugin/src/test/resources/test-project/target

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

public class JMeterReportClient {

private static final Logger log = LoggerFactory.getLogger(JMeterReportClient.class);
private static final boolean LOG_DEBUG = log.isDebugEnabled();
private static final Logger LOG = LoggerFactory.getLogger(JMeterReportClient.class);
private static final boolean LOG_DEBUG = LOG.isDebugEnabled();

private String serverHost = JMeterReportConst.DEFAULT_HOST;
private int serverPort = JMeterReportConst.DEFAULT_PORT;
Expand Down Expand Up @@ -70,8 +70,8 @@ protected Socket openSocket() throws IOException {
*/
public GlobalSummary getGlobalSummary(String config) {
if (LOG_DEBUG) {
log.debug("getGlobalSummary");
log.debug("config: " + config);
LOG.debug("getGlobalSummary");
LOG.debug("config: " + config);
}

Socket socket = null;
Expand Down Expand Up @@ -130,10 +130,10 @@ public GlobalSummary getGlobalSummary(String config) {
*/
public StreamReader<GlobalSummary> getRunningGlobalSummary(String config, boolean startNewIfNone, int sleepTime) {
if (LOG_DEBUG) {
log.debug("getRunningGlobalSummary");
log.debug("config: " + config);
log.debug("startNewIfNone: " + startNewIfNone);
log.debug("sleepTime: " + sleepTime);
LOG.debug("getRunningGlobalSummary");
LOG.debug("config: " + config);
LOG.debug("startNewIfNone: " + startNewIfNone);
LOG.debug("sleepTime: " + sleepTime);
}

Socket socket = null;
Expand Down Expand Up @@ -169,10 +169,10 @@ public StreamReader<GlobalSummary> getRunningGlobalSummary(String config, boolea
public StreamReader<Measure> getBuckedMeasures(String config, String metric,
int millisBucket) {
if (LOG_DEBUG) {
log.debug("getBuckedMeasures");
log.debug("config: " + config);
log.debug("metric: " + metric);
log.debug("millisBucket: " + millisBucket);
LOG.debug("getBuckedMeasures");
LOG.debug("config: " + config);
LOG.debug("metric: " + metric);
LOG.debug("millisBucket: " + millisBucket);
}

Socket socket = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package es.excentia.jmeter.report.client;

public class JMeterReportConst {

private JMeterReportConst() {}

public static final String REPORT_SERVER_PROPERTIES = "jmeter-report-server.properties";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public abstract class BasicWriter<T> extends StreamWriter<T> {

DataOutputStream dos;
protected DataOutputStream dos;

public BasicWriter(OutputStream os) {
super(os);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.OutputStream;

public abstract class StreamWriter<T> {
OutputStream os;
protected OutputStream os;

public StreamWriter(OutputStream os) {
this.os = os;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import java.util.regex.Pattern;

/**
* Util class for working with strings
* Utility class for checking java version
*/
public class JavaUtil {

private JavaUtil() {}

private static Pattern JAVA_VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\w+)");

public static String getVersion() {
Expand All @@ -39,20 +41,20 @@ private static String getGroup(int groupidx) {
if (m.matches()) {
return m.group(groupidx);
}
return null;
return "0";
}

/**
* Return jre major version
* Return jre major version or 0 if couldn't parse java.version
*/
public static int getJREMajorVersion() {
public static Integer getJREMajorVersion() {
return Integer.parseInt(getGroup(1));
}

/**
* Return jre minor version
* Return jre minor version or 0 if couldn't parse java.version
*/
public static int getJREMinorVersion() {
public static Integer getJREMinorVersion() {
return Integer.parseInt(getGroup(2));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
package es.excentia.jmeter.report.client.util;

/**
* Util class for working with strings
* Utility class for working with strings
*/
public class StringUtil {

private StringUtil() {}

/**
* Return true if the string is null, empty or only have white spaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
*/
public class JMeterReportServer {

private static final Logger log = LoggerFactory.getLogger(JMeterReportServer.class);
private static final boolean LOG_DEBUG = log.isDebugEnabled();
private static final boolean LOG_TRACE = log.isTraceEnabled();
private static final Logger LOG = LoggerFactory.getLogger(JMeterReportServer.class);
private static final boolean LOG_DEBUG = LOG.isDebugEnabled();
private static final boolean LOG_TRACE = LOG.isTraceEnabled();

private ServerSocket listener;
private Thread serverThread;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void run() {

int op = in.readInt();
if (LOG_DEBUG) {
log.debug("Attending client request operation: " + op);
LOG.debug("Attending client request operation: " + op);
}

try {
Expand Down Expand Up @@ -109,24 +109,24 @@ public void run() {
}

} catch (IOException ioe) {
log.error("IOException on socket when serving request", ioe);
LOG.error("IOException on socket when serving request", ioe);
} catch (Exception e) {
log.error("Report request exception", e);
LOG.error("Report request exception", e);

// Send error to client
out.writeInt(JMeterReportConst.RETURN_CODE_ERROR);
out.writeUTF(e.toString());
}

} catch (IOException ioe) {
log.error("Could not get socket streams", ioe);
LOG.error("Could not get socket streams", ioe);
} finally {
try {
connections--;
socket.close();
log.debug("Request finished");
LOG.debug("Request finished");
} catch (Exception e) {
log.error("Could not close server socket", e);
LOG.error("Could not close server socket", e);
}
}
}
Expand All @@ -139,12 +139,12 @@ public void run() {
*/
private void connectionLimitExceeded(Socket socket) {
if (LOG_DEBUG) {
log.debug("Connection limit exceeded ("+maxConnections+"). Closing socket ...");
LOG.debug("Connection limit exceeded ("+maxConnections+"). Closing socket ...");
}
try {
socket.close();
} catch (Exception e) {
log.error("Could not close server socket", e);
LOG.error("Could not close server socket", e);
}
}

Expand All @@ -157,7 +157,7 @@ private void startListening() {
try {

int port = configService.getPort();
log.info("Starting server on port " + port);
LOG.info("Starting server on port " + port);

maxConnections = configService.getMaxConnections();

Expand All @@ -181,13 +181,13 @@ private void startListening() {

} catch (IOException ioe) {
if (LOG_TRACE) {
log.trace("IOException on socket listen", ioe);
LOG.trace("IOException on socket listen", ioe);
} else if (!stopWhenPossible) {
log.error("IOException on socket listen", ioe);
LOG.error("IOException on socket listen", ioe);
}
}

log.info("Server stopped");
LOG.info("Server stopped");
}

/**
Expand All @@ -208,14 +208,14 @@ public void run() {

public void stop() {
if (listener != null) {
log.info("Stopping server ...");
LOG.info("Stopping server ...");

stopWhenPossible = true;

try {
listener.close();
} catch (IOException e) {
log.error("Error stoping server", e);
LOG.error("Error stoping server", e);
} finally {
listener = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected ReportData createSummaryData(Class<?> summaryDataClass) {

@Override
public String toString() {
StringBuffer buff = new StringBuffer();
StringBuilder buff = new StringBuilder();

buff.append("\n** Request Global Scope **");
for (int phase = 0; phase < 2; phase++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

public abstract class ReportThread extends Thread {

private static final Logger log = LoggerFactory.getLogger(ReportThread.class);
private static final Logger LOG = LoggerFactory.getLogger(ReportThread.class);


private RuntimeException resultException;
private Report report;
private StreamReader<SampleMix> reader;
private boolean ok = false;


public ReportThread(Report report, StreamReader<SampleMix> reader) {
public ReportThread(Report report, StreamReader<SampleMix> reader) {
this.report = report;
this.reader = reader;
}

public boolean isOk() { return ok; }
public Report getReport() { return report; }
public RuntimeException getResultException() { return resultException; }

Expand All @@ -49,12 +49,13 @@ public void run() {

try {
report.extract(reader);
ok = true;
} catch(RuntimeException ex) {
log.debug("ReportThread running finished with exception", ex);
LOG.debug("ReportThread finished with exception", ex);
resultException = ex;
} finally {
onFinished();
}

onFinished();
}

public abstract void onFinished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

public class ServiceFactory {

private ServiceFactory() {}

private static final String IMPL_PACKAGE = "es.excentia.jmeter.report.server.service.impl";

private static Map<Class<? extends Service>, Service> map = new HashMap<Class<? extends Service>, Service>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class ConfigServiceImpl implements ConfigService {

private static final Logger log = LoggerFactory.getLogger(ConfigServiceImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(ConfigServiceImpl.class);

private static final String PORT_KEY = "port";
private static final String MAX_CONNECTIONS_KEY = "maxConnections";
Expand Down Expand Up @@ -90,20 +90,20 @@ public int getNaturalProperty(String key, int defaultValue) {

String strValue = getProperty(key);
if (strValue == null) {
log.debug(
LOG.debug(
"No " + key + " configured. "+
"Using default value " + defaultValue + "."
);
} else {
try {
value = Integer.parseInt(getProperty(key));
} catch (NumberFormatException e) {
log.warn("Could not parse " + key + ": " + e.getMessage());
LOG.warn("Could not parse " + key + ": " + e.getMessage());
}
}

if (value < 0) {
log.warn(
LOG.warn(
"The value of " + key + " cannot be negative: " + value+ ". "+
"Using default value " + defaultValue + "."
);
Expand Down
Loading

0 comments on commit a9b7e7e

Please sign in to comment.