Search in sources :

Example 16 with CommandPacket

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()));
}
Also used : CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 17 with CommandPacket

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()));
}
Also used : CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Aggregations

CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)17 JSONObject (org.json.JSONObject)6 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)5 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)5 Test (org.junit.Test)5 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)4 IOException (java.io.IOException)4 Request (edu.umass.cs.gigapaxos.interfaces.Request)3 ResponsePacket (edu.umass.cs.gnscommon.packets.ResponsePacket)3 JSONException (org.json.JSONException)3 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)2 InternalCommandPacket (edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket)2 JSONArray (org.json.JSONArray)2 Callback (edu.umass.cs.gigapaxos.interfaces.Callback)1 RequestIdentifier (edu.umass.cs.gigapaxos.interfaces.RequestIdentifier)1 GNSClient (edu.umass.cs.gnsclient.client.GNSClient)1 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)1 CommandType (edu.umass.cs.gnscommon.CommandType)1 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)1 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)1