Permalink
Browse files

#346 Async: implement simple and important JSON parameters for comman…

…ds -switched to parameters, not JSON
  • Loading branch information...
ipolevoy committed Jun 21, 2017
1 parent 9dc2817 commit 33c8abeebecba76b38b9ba7c4040aedad641bfe4
View
@@ -0,0 +1 @@
mvn clean install -Dmaven.test.skip=true
@@ -40,7 +40,7 @@
private String jmsMessageId;
private Map params = map("class", getClass().getSimpleName());
private Map<String, String> params = map("class", getClass().getSimpleName());
private static final XStream X_STREAM = new XStream(new CDATAXppDriver());
@@ -114,20 +114,21 @@ public void setJMSMessageID(String jmsMessageId) {
}
/**
* Adds parameters and their values to reflect by the {@link #toJsonLog()} method.
* Adds parameters and their values to reflect by the {@link #getParams()} method.
*
* @param params important parameters of this command - tings you want to see in a log file.
* @param namesAndValues important parameters of this command - tings you want to see in a log file.
*/
public void addJsonParams(Map params){
this.params.putAll(params);
@SuppressWarnings("unchecked")
public void addParams(String ... namesAndValues){
this.params.putAll(map(namesAndValues));
}
/**
* Used by writing returned value to the log.
* Used to understand important values related to this command (in log files).
*
* @return JSON representation of this command.
* @return important values related to processing of this command.
*/
public String toJsonLog(){
return JsonHelper.toJsonString(params);
public Map<String, String> getParams(){
return params;
}
}
@@ -45,8 +45,8 @@ public void onMessage(Message message) {
}
long start = System.currentTimeMillis();
onCommand(command);
command.toJsonLog();
LOGGER.info(JsonHelper.toJsonString(map("processed_millis", (System.currentTimeMillis() - start), "info", command.toJsonLog())));
LOGGER.info(JsonHelper.toJsonString(map("processed_millis", (System.currentTimeMillis() - start), "info", command.getParams())));
} catch (Exception e) {
throw new AsyncException("Failed to process command", e);
}
@@ -3,8 +3,10 @@
import org.junit.Test;
import java.io.IOException;
import java.util.Map;
import static org.javalite.test.jspec.JSpec.a;
import static org.javalite.test.jspec.JSpec.the;
/**
* @author Igor Polevoy on 1/31/16.
@@ -29,4 +31,12 @@ public void shouldSerializeDeserializeBinary() throws IOException {
a(helloCommand1.getMessage()).shouldBeEqual("Thanks for all the fish...");
a(helloCommand).shouldNotBeTheSameAs(helloCommand1);
}
@Test
public void shouldGenerateParams() throws IOException {
HelloCommand helloCommand = new HelloCommand("Thanks for all the fish...");
Map<String, String> params = helloCommand.getParams();
the(params.get("class")).shouldBeEqual("HelloCommand");
the(params.get("message")).shouldBeEqual("Thanks for all the fish...");
}
}
@@ -13,6 +13,7 @@
public HelloCommand(String message) {
this.message = message;
addParams("message", message);
}
public HelloCommand() {} //necessary to provide

0 comments on commit 33c8abe

Please sign in to comment.