tobiasrieger commented on a change in pull request #1075:
URL: https://github.com/apache/systemds/pull/1075#discussion_r499147241
##########
File path:
src/test/java/org/apache/sysds/test/component/paramserv/SerializationTest.java
##########
@@ -29,40 +35,90 @@
import org.apache.sysds.runtime.instructions.cp.ListObject;
import org.apache.sysds.runtime.util.DataConverter;
import org.apache.sysds.runtime.util.ProgramConverter;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+@RunWith(Parameterized.class)
public class SerializationTest {
+ private int _named;
+
+ @Parameterized.Parameters
+ public static Collection named() {
+ return Arrays.asList(new Object[][] {
+ { 0 },
+ { 1 }
+ });
+ }
+
+ public SerializationTest(Integer named) {
+ this._named = named;
+ }
@Test
- public void serializeUnnamedListObject() {
+ public void serializeListObject() {
MatrixObject mo1 = generateDummyMatrix(10);
MatrixObject mo2 = generateDummyMatrix(20);
IntObject io = new IntObject(30);
- ListObject lo = new ListObject(Arrays.asList(mo1, mo2, io));
- String serial = ProgramConverter.serializeDataObject("key", lo);
- Object[] obj = ProgramConverter.parseDataObject(serial);
- ListObject actualLO = (ListObject) obj[1];
- MatrixObject actualMO1 = (MatrixObject) actualLO.slice(0);
- MatrixObject actualMO2 = (MatrixObject) actualLO.slice(1);
- IntObject actualIO = (IntObject) actualLO.slice(2);
-
Assert.assertArrayEquals(mo1.acquireRead().getDenseBlockValues(),
actualMO1.acquireRead().getDenseBlockValues(), 0);
-
Assert.assertArrayEquals(mo2.acquireRead().getDenseBlockValues(),
actualMO2.acquireRead().getDenseBlockValues(), 0);
- Assert.assertEquals(io.getLongValue(), actualIO.getLongValue());
+ ListObject lot = new ListObject(Arrays.asList(mo2));
+ ListObject lo;
+
+ if (_named == 1)
+ lo = new ListObject(Arrays.asList(mo1, lot, io),
Arrays.asList("e1", "e2", "e3"));
+ else
+ lo = new ListObject(Arrays.asList(mo1, lot, io));
+
+ ListObject loDeserialized = null;
+
+ // serialize and back
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bos);
+ out.writeObject(lo);
+ out.flush();
+ byte[] loBytes = bos.toByteArray();
+
+ ByteArrayInputStream bis = new
ByteArrayInputStream(loBytes);
+ ObjectInput in = new ObjectInputStream(bis);
+ loDeserialized = (ListObject) in.readObject();
Review comment:
Thanks 😁
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]