Cleaning up PubSubMessages, as types messages instead of PubSubMetaData untypes dictionary
This commit is contained in:
1 parent
2e0e0658c6
commit
d32d5ef40c
12 files changed
+682
-262
No files matched your search
+177
-177
@@ -1,195 +1,195 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
// using System;
|
||||
// using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
// using NUnit.Framework;
|
||||
|
||||
namespace BCG {
|
||||
// namespace BCG {
|
||||
|
||||
/// <summary>
|
||||
/// Tests the deserialization happening within the pubsub.
|
||||
/// </summary>
|
||||
public class UniversalSerializationTest {
|
||||
protected IBlueTableSchema mySchema;
|
||||
protected BlueTable myTable;
|
||||
protected IBlueDataSerializer mySer = new BlueDataSerializationController();
|
||||
protected IPubsubDeserializer myPubsubDeser = new PubsubDeserializationController();
|
||||
protected IClientDeserializer myClientDeser = new ClientDeserializationController();
|
||||
// /// <summary>
|
||||
// /// Tests the deserialization happening within the pubsub.
|
||||
// /// </summary>
|
||||
// public class UniversalSerializationTest {
|
||||
// protected IBlueTableSchema mySchema;
|
||||
// protected BlueTable myTable;
|
||||
// protected IBlueDataSerializer mySer = new BlueDataSerializationController();
|
||||
// protected IPubsubDeserializer myPubsubDeser = new PubsubDeserializationController();
|
||||
// protected IClientDeserializer myClientDeser = new ClientDeserializationController();
|
||||
|
||||
public UniversalSerializationTest() {
|
||||
mySchema = new BlueTableSchema(myGetTableName(),
|
||||
new ColumnInfo("id", 0, typeof(int)),
|
||||
new ColumnInfo("i1", 1, typeof(int)),
|
||||
new ColumnInfo("d1", 2, typeof(double)),
|
||||
new ColumnInfo("dt", 3, typeof(DateTime)),
|
||||
new ColumnInfo("x", 4, typeof(byte))
|
||||
);
|
||||
}
|
||||
// public UniversalSerializationTest() {
|
||||
// mySchema = new BlueTableSchema(myGetTableName(),
|
||||
// new ColumnInfo("id", 0, typeof(int)),
|
||||
// new ColumnInfo("i1", 1, typeof(int)),
|
||||
// new ColumnInfo("d1", 2, typeof(double)),
|
||||
// new ColumnInfo("dt", 3, typeof(DateTime)),
|
||||
// new ColumnInfo("x", 4, typeof(byte))
|
||||
// );
|
||||
// }
|
||||
|
||||
protected virtual string myGetTableName() {
|
||||
return "testUniversal";
|
||||
}
|
||||
// protected virtual string myGetTableName() {
|
||||
// return "testUniversal";
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Tests the entire cycle. This is done by 'publishing' data to the serializationController (ie a series of
|
||||
/// adds, deletions, changes etc) and getting the bytes and feeding it into a pubsubDeseriazlier and a clientDeserializer.
|
||||
/// At every step the data is tested for consistency. At the end the getState is used to get all the data, and its passed
|
||||
/// through the clientDeserializer to get all the rows.
|
||||
///
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void testEntireProcess() {
|
||||
myTable = new BlueTable(mySchema);
|
||||
byte[] data;
|
||||
int id;
|
||||
//create
|
||||
for (id = 0; id < 100; id++)
|
||||
myTable.addRow(myGetRow(id));
|
||||
// /// <summary>
|
||||
// /// Tests the entire cycle. This is done by 'publishing' data to the serializationController (ie a series of
|
||||
// /// adds, deletions, changes etc) and getting the bytes and feeding it into a pubsubDeseriazlier and a clientDeserializer.
|
||||
// /// At every step the data is tested for consistency. At the end the getState is used to get all the data, and its passed
|
||||
// /// through the clientDeserializer to get all the rows.
|
||||
// ///
|
||||
// /// </summary>
|
||||
// [Test]
|
||||
// public void testEntireProcess() {
|
||||
// myTable = new BlueTable(mySchema);
|
||||
// byte[] data;
|
||||
// int id;
|
||||
// //create
|
||||
// for (id = 0; id < 100; id++)
|
||||
// myTable.addRow(myGetRow(id));
|
||||
|
||||
byte[] ops;
|
||||
Array rows;
|
||||
IBlueRowCollection del, add;
|
||||
IBlueRowCollection[] receivedData;
|
||||
IBlueRow r;
|
||||
// byte[] ops;
|
||||
// Array rows;
|
||||
// IBlueRowCollection del, add;
|
||||
// IBlueRowCollection[] receivedData;
|
||||
// IBlueRow r;
|
||||
|
||||
//create
|
||||
mySer.serialize(StreamOpCode.create, new IBlueRowCollection[] { myTable }, out data);
|
||||
myWrite(StreamOpCode.create, data);
|
||||
myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.create, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(1, receivedData.Length);
|
||||
// //create
|
||||
// mySer.serialize(StreamOpCode.create, new IBlueRowCollection[] { myTable }, out data);
|
||||
// myWrite(StreamOpCode.create, data);
|
||||
// myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.create, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(1, receivedData.Length);
|
||||
|
||||
BlueDataUtility.computeDifferences(receivedData[0], myTable, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], myTable, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
//single add
|
||||
r = myGetRow(id);
|
||||
BlueTable temp = new BlueTable(mySchema);
|
||||
myTable.addRow(r);
|
||||
temp.addRow(r);
|
||||
mySer.serialize(StreamOpCode.add, new IBlueRowCollection[] { temp }, out data);
|
||||
myWrite(StreamOpCode.add, data);
|
||||
myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.add, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(1, receivedData.Length);
|
||||
BlueDataUtility.computeDifferences(receivedData[0], temp, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// //single add
|
||||
// r = myGetRow(id);
|
||||
// BlueTable temp = new BlueTable(mySchema);
|
||||
// myTable.addRow(r);
|
||||
// temp.addRow(r);
|
||||
// mySer.serialize(StreamOpCode.add, new IBlueRowCollection[] { temp }, out data);
|
||||
// myWrite(StreamOpCode.add, data);
|
||||
// myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.add, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(1, receivedData.Length);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], temp, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
//single delete
|
||||
r = myTable[0]; //delete row with id 0
|
||||
temp = new BlueTable(mySchema);
|
||||
myTable.deleteRow(0);
|
||||
temp.addRow(r);
|
||||
mySer.serialize(StreamOpCode.remove, new IBlueRowCollection[] { temp }, out data);
|
||||
myWrite(StreamOpCode.remove, data);
|
||||
myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.remove, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(1, receivedData.Length);
|
||||
BlueDataUtility.computeDifferences(receivedData[0], temp, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// //single delete
|
||||
// r = myTable[0]; //delete row with id 0
|
||||
// temp = new BlueTable(mySchema);
|
||||
// myTable.deleteRow(0);
|
||||
// temp.addRow(r);
|
||||
// mySer.serialize(StreamOpCode.remove, new IBlueRowCollection[] { temp }, out data);
|
||||
// myWrite(StreamOpCode.remove, data);
|
||||
// myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.remove, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(1, receivedData.Length);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], temp, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
//batch deletes and adds
|
||||
//0 was removed earlier, so lets delete from 1 to 24 first, and then add 101 to 124
|
||||
BlueTable delRows = new BlueTable(mySchema), addRows = new BlueTable(mySchema);
|
||||
for (int i = 1; i < 25; i++) {
|
||||
delRows.addRow(myTable[i]);
|
||||
myTable.deleteRow(i);
|
||||
}
|
||||
for (id = 101; id < 125; id++) {
|
||||
r = myGetRow(id);
|
||||
addRows.addRow(r);
|
||||
myTable.addRow(r);
|
||||
}
|
||||
for (int i = 25; i < 125; i++)
|
||||
Assert.AreEqual(true, myTable.containsID(i));
|
||||
Assert.AreEqual(100, myTable.Count);
|
||||
// //batch deletes and adds
|
||||
// //0 was removed earlier, so lets delete from 1 to 24 first, and then add 101 to 124
|
||||
// BlueTable delRows = new BlueTable(mySchema), addRows = new BlueTable(mySchema);
|
||||
// for (int i = 1; i < 25; i++) {
|
||||
// delRows.addRow(myTable[i]);
|
||||
// myTable.deleteRow(i);
|
||||
// }
|
||||
// for (id = 101; id < 125; id++) {
|
||||
// r = myGetRow(id);
|
||||
// addRows.addRow(r);
|
||||
// myTable.addRow(r);
|
||||
// }
|
||||
// for (int i = 25; i < 125; i++)
|
||||
// Assert.AreEqual(true, myTable.containsID(i));
|
||||
// Assert.AreEqual(100, myTable.Count);
|
||||
|
||||
mySer.serialize(StreamOpCode.multipleRemoveAdd, new IBlueRowCollection[] { delRows, addRows }, out data);
|
||||
myWrite(StreamOpCode.multipleRemoveAdd, data);
|
||||
myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.multipleRemoveAdd, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(2, receivedData.Length);
|
||||
BlueDataUtility.computeDifferences(receivedData[0], delRows, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
BlueDataUtility.computeDifferences(receivedData[1], addRows, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// mySer.serialize(StreamOpCode.multipleRemoveAdd, new IBlueRowCollection[] { delRows, addRows }, out data);
|
||||
// myWrite(StreamOpCode.multipleRemoveAdd, data);
|
||||
// myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.multipleRemoveAdd, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(2, receivedData.Length);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], delRows, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
// BlueDataUtility.computeDifferences(receivedData[1], addRows, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
//pure changes only
|
||||
//change the first 25, 25-49
|
||||
BlueTable changedRows = new BlueTable(mySchema);
|
||||
for (int i = 25; i < 50; i++) {
|
||||
MutableBlueRow mr = new MutableBlueRow(myTable[i]);
|
||||
mr.setValue(4, Byte.MaxValue);
|
||||
myTable.changeRow(mr);
|
||||
changedRows.addRow(mr);
|
||||
}
|
||||
mySer.serialize(StreamOpCode.multipleChange, new IBlueRowCollection[] { changedRows }, out data);
|
||||
myWrite(StreamOpCode.multipleChange, data);
|
||||
myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.multipleChange, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(1, receivedData.Length);
|
||||
BlueDataUtility.computeDifferences(receivedData[0], changedRows, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// //pure changes only
|
||||
// //change the first 25, 25-49
|
||||
// BlueTable changedRows = new BlueTable(mySchema);
|
||||
// for (int i = 25; i < 50; i++) {
|
||||
// MutableBlueRow mr = new MutableBlueRow(myTable[i]);
|
||||
// mr.setValue(4, Byte.MaxValue);
|
||||
// myTable.changeRow(mr);
|
||||
// changedRows.addRow(mr);
|
||||
// }
|
||||
// mySer.serialize(StreamOpCode.multipleChange, new IBlueRowCollection[] { changedRows }, out data);
|
||||
// myWrite(StreamOpCode.multipleChange, data);
|
||||
// myPubsubDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// myClientDeser.deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.multipleChange, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(1, receivedData.Length);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], changedRows, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
//final test
|
||||
data = myPubsubDeser.getState();
|
||||
new ClientDeserializationController().deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
Assert.AreEqual(1, ops.Length);
|
||||
Assert.AreEqual(StreamOpCode.create, ops[0]);
|
||||
Assert.AreEqual(1, rows.Length);
|
||||
receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
Assert.AreEqual(1, receivedData.Length);
|
||||
BlueDataUtility.computeDifferences(receivedData[0], myTable, out del, out add);
|
||||
Assert.AreEqual(0, del.Count);
|
||||
Assert.AreEqual(0, add.Count);
|
||||
// //final test
|
||||
// data = myPubsubDeser.getState();
|
||||
// new ClientDeserializationController().deserialize(new Stream[] { new MemoryStream(data) }, out ops, out rows);
|
||||
// Assert.AreEqual(1, ops.Length);
|
||||
// Assert.AreEqual(StreamOpCode.create, ops[0]);
|
||||
// Assert.AreEqual(1, rows.Length);
|
||||
// receivedData = rows.GetValue(0) as IBlueRowCollection[];
|
||||
// Assert.AreEqual(1, receivedData.Length);
|
||||
// BlueDataUtility.computeDifferences(receivedData[0], myTable, out del, out add);
|
||||
// Assert.AreEqual(0, del.Count);
|
||||
// Assert.AreEqual(0, add.Count);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
private IBlueRow myGetRow(int id) {
|
||||
return new BlueRow(mySchema, // the day pp fixed this test.
|
||||
id, id + 10, id * 3.0, new DateTime(2008, 6, 4, 0, 0, 0, DateTimeKind.Unspecified), Convert.ToByte(id));
|
||||
}
|
||||
// private IBlueRow myGetRow(int id) {
|
||||
// return new BlueRow(mySchema, // the day pp fixed this test.
|
||||
// id, id + 10, id * 3.0, new DateTime(2008, 6, 4, 0, 0, 0, DateTimeKind.Unspecified), Convert.ToByte(id));
|
||||
// }
|
||||
|
||||
private void myWrite(byte op, byte[] data) {
|
||||
string s = "";
|
||||
if (op == StreamOpCode.add)
|
||||
s = "add one row";
|
||||
else if (op == StreamOpCode.change)
|
||||
s = "change one row";
|
||||
else if (op == StreamOpCode.create)
|
||||
s = "create";
|
||||
else if (op == StreamOpCode.multipleChange)
|
||||
s = "multiple change";
|
||||
else if (op == StreamOpCode.multipleRemoveAdd)
|
||||
s = "multiple add remove";
|
||||
else if (op == StreamOpCode.remove)
|
||||
s = "remove one row";
|
||||
Console.WriteLine("yes, here , op = {0}, size = {1}", s, data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
// private void myWrite(byte op, byte[] data) {
|
||||
// string s = "";
|
||||
// if (op == StreamOpCode.add)
|
||||
// s = "add one row";
|
||||
// else if (op == StreamOpCode.change)
|
||||
// s = "change one row";
|
||||
// else if (op == StreamOpCode.create)
|
||||
// s = "create";
|
||||
// else if (op == StreamOpCode.multipleChange)
|
||||
// s = "multiple change";
|
||||
// else if (op == StreamOpCode.multipleRemoveAdd)
|
||||
// s = "multiple add remove";
|
||||
// else if (op == StreamOpCode.remove)
|
||||
// s = "remove one row";
|
||||
// //Console.WriteLine("yes, here , op = {0}, size = {1}", s, data.Length);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in new issue
Block a user