Skip to content

Commit bb7a72b

Browse files
committed
Add unit test for DataTO/DataStoreTO serializer/deserializer adapter.
1 parent e0ab845 commit bb7a72b

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎core/src/com/cloud/serializer/GsonHelper.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static Gson setDefaultGsonConfig(GsonBuilder builder) {
6868
builder.registerTypeAdapter(new TypeToken<Pair<Long, Long>>() {
6969
}.getType(), new NwGroupsCommandTypeAdaptor());
7070
Gson gson = builder.create();
71+
dsAdaptor.initGson(gson);
72+
dtAdaptor.initGson(gson);
7173
cmdAdaptor.initGson(gson);
7274
ansAdaptor.initGson(gson);
7375
return gson;

‎core/test/com/cloud/agent/transport/RequestTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.agent.api.Command;
3131
import com.cloud.agent.api.GetHostStatsCommand;
3232
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
33+
import com.cloud.agent.api.SecStorageSetupCommand;
3334
import com.cloud.agent.api.UpdateHostPasswordCommand;
3435
import com.cloud.agent.api.storage.DownloadAnswer;
3536
import com.cloud.agent.api.to.NfsTO;
@@ -129,6 +130,36 @@ public void testSerDeser() {
129130
compareRequest(cresp, sresp);
130131
}
131132

133+
134+
public void testSerDeserTO() {
135+
s_logger.info("Testing serializing and deserializing interface TO works as expected");
136+
137+
NfsTO nfs = new NfsTO("nfs://192.168.56.10/opt/storage/secondary", DataStoreRole.Image);
138+
SecStorageSetupCommand cmd = new SecStorageSetupCommand(nfs, "nfs://192.168.56.10/opt/storage/secondary", null);
139+
Request sreq = new Request(2, 3, cmd, true);
140+
sreq.setSequence(892403718);
141+
142+
143+
byte[] bytes = sreq.getBytes();
144+
145+
assert Request.getSequence(bytes) == 892403718;
146+
assert Request.getManagementServerId(bytes) == 3;
147+
assert Request.getAgentId(bytes) == 2;
148+
assert Request.getViaAgentId(bytes) == 2;
149+
Request creq = null;
150+
try {
151+
creq = Request.parse(bytes);
152+
} catch (ClassNotFoundException e) {
153+
s_logger.error("Unable to parse bytes: ", e);
154+
} catch (UnsupportedVersionException e) {
155+
s_logger.error("Unable to parse bytes: ", e);
156+
}
157+
158+
assert creq != null : "Couldn't get the request back";
159+
160+
compareRequest(creq, sreq);
161+
}
162+
132163
public void testDownload() {
133164
s_logger.info("Testing Download answer");
134165
VMTemplateVO template = new VMTemplateVO(1, "templatename", ImageFormat.QCOW2, true, true, true, TemplateType.USER, "url", true, 32, 1, "chksum", "displayText", true, 30, true,

0 commit comments

Comments
 (0)