mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
removed to toString() method in requests
This commit is contained in:
parent
2f8235dbd2
commit
838a24f202
@ -223,28 +223,6 @@ public class Request {
|
||||
return _cmds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this only surrounded by debug.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String content = _content;
|
||||
if (content == null) {
|
||||
try {
|
||||
content = s_gson.toJson(_cmds);
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("Gson serialization error on Request.toString() " + getClass().getCanonicalName(), e);
|
||||
}
|
||||
}
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("{ ").append(getType());
|
||||
buffer.append(", Seq: ").append(_agentId).append("-").append(_seq).append(", Ver: ").append(_ver.toString());
|
||||
buffer.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via);
|
||||
buffer.append(", Flags: ").append(Integer.toBinaryString(getFlags()));
|
||||
buffer.append(", ").append(content).append(" }");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected String getType() {
|
||||
return "Cmd ";
|
||||
}
|
||||
@ -312,7 +290,7 @@ public class Request {
|
||||
}
|
||||
}
|
||||
|
||||
public String log(String msg, boolean logContent) {
|
||||
protected String log(String msg, boolean logContent) {
|
||||
StringBuilder buf = new StringBuilder("Seq ");
|
||||
buf.append(_agentId).append("-").append(_seq).append(": ");
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cloud.agent.api.transport;
|
||||
package com.cloud.agent.transport;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@ -10,9 +10,15 @@ import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
|
||||
import com.cloud.agent.api.UpdateHostPasswordCommand;
|
||||
import com.cloud.agent.transport.Request;
|
||||
import com.cloud.agent.transport.Response;
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.exception.UnsupportedVersionException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.serializer.GsonHelper;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
@ -44,17 +50,32 @@ public class RequestTest extends TestCase {
|
||||
Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
|
||||
sreq.setSequence(1);
|
||||
|
||||
Logger logger = Logger.getLogger(Request.class);
|
||||
Logger logger = Logger.getLogger(GsonHelper.class);
|
||||
Level level = logger.getLevel();
|
||||
|
||||
logger.setLevel(Level.DEBUG);
|
||||
sreq.log("Debug", true);
|
||||
String log = sreq.log("Debug", true);
|
||||
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
|
||||
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
|
||||
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
|
||||
assert (!log.contains("username"));
|
||||
assert (!log.contains("password"));
|
||||
|
||||
logger.setLevel(Level.TRACE);
|
||||
sreq.log("Trace", true);
|
||||
log = sreq.log("Trace", true);
|
||||
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
|
||||
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
|
||||
assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
|
||||
assert (!log.contains("username"));
|
||||
assert (!log.contains("password"));
|
||||
|
||||
logger.setLevel(Level.INFO);
|
||||
sreq.log("Info", true);
|
||||
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
|
||||
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
|
||||
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
|
||||
assert (!log.contains("username"));
|
||||
assert (!log.contains("password"));
|
||||
|
||||
logger.setLevel(level);
|
||||
|
||||
@ -91,6 +112,21 @@ public class RequestTest extends TestCase {
|
||||
compareRequest(cresp, sresp);
|
||||
}
|
||||
|
||||
public void testDownload() {
|
||||
VMTemplateVO template = new VMTemplateVO(1, "templatename", ImageFormat.QCOW2, true, true, true, TemplateType.USER, "url", true, 32, 1, "chksum", "displayText", true, 30, true,
|
||||
HypervisorType.KVM);
|
||||
DownloadCommand cmd = new DownloadCommand("secUrl", template, 30000000l);
|
||||
Request req = new Request(1, 1, cmd, true);
|
||||
|
||||
req.logD("Debug for Download");
|
||||
|
||||
|
||||
DownloadAnswer answer = new DownloadAnswer("jobId", 50, "errorString", Status.ABANDONED, "filesystempath", "installpath", 10000000, 20000000);
|
||||
Response resp = new Response(req, answer);
|
||||
resp.logD("Debug for Download");
|
||||
|
||||
}
|
||||
|
||||
protected void compareRequest(Request req1, Request req2) {
|
||||
assert req1.getSequence() == req2.getSequence();
|
||||
assert req1.getAgentId() == req2.getAgentId();
|
||||
Loading…
x
Reference in New Issue
Block a user