use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ByteificationComparisonFail method test_21_FromCommandPacket_1024B.
/**
*
* @param byteificationComparison
* @throws UnsupportedEncodingException
* @throws JSONException
* @throws ClientException
* @throws NoSuchAlgorithmException
* @throws RequestParseException
*/
// FIXME: THIS TEST IS FAILING at new CommandPacket(bytes)
@Test
public void test_21_FromCommandPacket_1024B(ByteificationComparisonFail byteificationComparison) throws UnsupportedEncodingException, JSONException, ClientException, NoSuchAlgorithmException, RequestParseException {
CommandPacket packet = GNSCommand.fieldRead(new String(Util.getRandomAlphanumericBytes(512)), new String(Util.getRandomAlphanumericBytes(512)), null);
//CommandPacket packet = new CommandPacket(CommandUtils.createCommand(CommandType.ReadArrayOneUnsigned, "", GNSProtocol.GUID.toString(), new String(Util.getRandomAlphanumericBytes(512)), GNSProtocol.FIELD.toString(),new String(Util.getRandomAlphanumericBytes(512))));
byte[] bytes = packet.toBytes();
long startTime = System.nanoTime();
for (int i = 0; i < TEST_RUNS; i++) {
new CommandPacket(bytes);
}
long endTime = System.nanoTime();
double avg = (endTime - startTime) / (TEST_RUNS);
CommandPacket outputPacket = new CommandPacket(bytes);
System.out.println("Average time CommandPacket from bytes 1024B was " + avg + " nanoseconds.");
assert (Arrays.equals(bytes, outputPacket.toBytes()));
//CommandPacket outputPacket = CommandPacket.fromBytes(bytes);
//assert(packet.toJSONObject().toString().equals(outputPacket.toJSONObject().toString()));
}
use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ByteificationComparisonFail method test_20_FromCommandPacket_128B.
/**
*
* @param byteificationComparison
* @throws UnsupportedEncodingException
* @throws JSONException
* @throws ClientException
* @throws NoSuchAlgorithmException
* @throws RequestParseException
*/
// FIXME: THIS TEST IS FAILING at new CommandPacket(bytes)
@Test
public void test_20_FromCommandPacket_128B(ByteificationComparisonFail byteificationComparison) throws UnsupportedEncodingException, JSONException, ClientException, NoSuchAlgorithmException, RequestParseException {
GuidEntry querier = null;
CommandPacket packet = GNSCommand.fieldRead(new String(Util.getRandomAlphanumericBytes(64)), new String(Util.getRandomAlphanumericBytes(64)), querier);
//CommandPacket packet = new CommandPacket(CommandUtils.createCommand(CommandType.ReadArrayOneUnsigned, "", GNSProtocol.GUID.toString(), new String(Util.getRandomAlphanumericBytes(512)), GNSProtocol.FIELD.toString(),new String(Util.getRandomAlphanumericBytes(512))));
String jsonBefore = packet.toJSONObject().toString();
byte[] bytes = packet.toBytes();
//System.out.println(jsonBefore + "\n\n" + packet.toJSONObject().toString());
assert (jsonBefore.equals(packet.toJSONObject().toString()));
long startTime = System.nanoTime();
for (int i = 0; i < TEST_RUNS; i++) {
new CommandPacket(bytes);
}
long endTime = System.nanoTime();
double avg = (endTime - startTime) / (TEST_RUNS);
CommandPacket outputPacket = new CommandPacket(bytes);
System.out.println("Average time CommandPacket from bytes 128B unsigned was " + avg + " nanoseconds.");
assert (Arrays.equals(bytes, outputPacket.toBytes()));
String canonicalJSON = CanonicalJSON.getCanonicalForm(jsonBefore);
String canonicalJSONOutput = CanonicalJSON.getCanonicalForm(outputPacket.toJSONObject());
//System.out.println(canonicalJSONOutput);
assert (canonicalJSON.equals(canonicalJSONOutput));
//CommandPacket outputPacket = CommandPacket.fromBytes(bytes);
//assert(packet.toJSONObject().toString().equals(outputPacket.toJSONObject().toString()));
}
Aggregations