use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ByteificationComparisonFail method test_18_CommandPacket_128B.
/**
*
* @param byteificationComparison
* @throws UnsupportedEncodingException
* @throws JSONException
* @throws ClientException
* @throws RequestParseException
*/
// FIXME: THIS TEST IS FAILING at new CommandPacket(bytes)
@Test
public void test_18_CommandPacket_128B(ByteificationComparisonFail byteificationComparison) throws UnsupportedEncodingException, JSONException, ClientException, RequestParseException {
CommandPacket packet = GNSCommand.fieldRead(new String(Util.getRandomAlphanumericBytes(64)), new String(Util.getRandomAlphanumericBytes(64)), null);
//CommandPacket packet = new CommandPacket(CommandUtils.createCommand(CommandType.ReadArrayOneUnsigned, "", GNSProtocol.GUID.toString(), new String(Util.getRandomAlphanumericBytes(64)), GNSProtocol.FIELD.toString(),new String(Util.getRandomAlphanumericBytes(64))));
long startTime = System.nanoTime();
for (int i = 0; i < TEST_RUNS; i++) {
byte[] bytes = packet.toBytes();
new CommandPacket(bytes);
}
long endTime = System.nanoTime();
double avg = (endTime - startTime) / (TEST_RUNS);
System.out.println("Average byteification time CommandPacket 128B was " + avg + " nanoseconds.");
byte[] bytes = packet.toBytes();
CommandPacket outputPacket = new CommandPacket(bytes);
//assert(packet.toJSONObject().toString().equals(outputPacket.toJSONObject().toString()));
assert (Arrays.equals(bytes, outputPacket.toBytes()));
//System.out.println(packet.toJSONObject().toString());
//System.out.println(outputPacket.toJSONObject().toString());
}
use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ByteificationComparisonFail method test_19_CommandPacket_1024B.
/**
*
* @param byteificationComparison
* @throws UnsupportedEncodingException
* @throws JSONException
* @throws ClientException
* @throws RequestParseException
*/
// FIXME: THIS TEST IS FAILING at new CommandPacket(bytes)
@Test
public void test_19_CommandPacket_1024B(ByteificationComparisonFail byteificationComparison) throws UnsupportedEncodingException, JSONException, ClientException, 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))));
long startTime = System.nanoTime();
for (int i = 0; i < TEST_RUNS; i++) {
byte[] bytes = packet.toBytes();
new CommandPacket(bytes);
}
long endTime = System.nanoTime();
double avg = (endTime - startTime) / (TEST_RUNS);
System.out.println("Average byteification time CommandPacket 1024B was " + avg + " nanoseconds.");
byte[] bytes = packet.toBytes();
CommandPacket outputPacket = new CommandPacket(bytes);
assert (Arrays.equals(bytes, outputPacket.toBytes()));
//assert(packet.toJSONObject().toString().equals(outputPacket.toJSONObject().toString()));
}
use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ThroughputAsynchMultiClientTest method createUpdateCommandPacket.
private static CommandPacket createUpdateCommandPacket(GNSClient client, String targetGuid, JSONObject json, GuidEntry writer) throws Exception {
JSONObject command;
command = createAndSignCommand(CommandType.ReplaceUserJSON, writer, GNSProtocol.GUID.toString(), targetGuid, json.toString(), GNSProtocol.WRITER.toString(), writer.getGuid());
return new CommandPacket(-1, command);
}
use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class ThroughputAsynchMultiClientTest method createSubGuidsAndWriteValue.
/**
* Creates the guids where do all the data access.
* If the user specifies an updateAlias we make one
* guid using that alias and use that for all clients. Otherwise we
* make a bunch of random guids.
* @param useExistingGuids
*/
public void createSubGuidsAndWriteValue(boolean useExistingGuids) {
try {
// to do all the operations from
if (updateAlias != null) {
// if it was specified find or create the guid for updateAlias
subGuids[0] = GuidUtils.lookupOrCreateGuid(clients[0], masterGuid, updateAlias, true).getGuid();
}
JSONArray existingGuids = null;
GuidEntry[] createdGuids = new GuidEntry[numberOfGuids];
// a bunch of aliases that are subalises to the masterGuid
if (updateAlias == null) {
if (!useExistingGuids) {
// Create the the guids set up below.
for (int i = 0; i < numberOfGuids; i++) {
createdGuids[i] = clients[i].guidCreate(masterGuid, "subGuid" + RandomString.randomString(6));
System.out.println("Created: " + createdGuids[i].getEntityName());
}
}
try {
JSONObject command = createCommand(CommandType.LookupRandomGuids, GNSProtocol.GUID.toString(), masterGuid.getGuid(), GNSProtocol.GUIDCNT.toString(), numberOfGuids);
String result = clients[0].execute(new CommandPacket((long) (Math.random() * Long.MAX_VALUE), command)).getResultString();
if (!result.startsWith(GNSProtocol.BAD_RESPONSE.toString())) {
existingGuids = new JSONArray(result);
} else {
System.out.println("Problem reading random guids " + result);
System.exit(-1);
}
} catch (JSONException | IOException | ClientException e) {
System.out.println("Problem reading random guids " + e);
System.exit(-1);
}
}
// Ensure that we have enough guids
if (existingGuids.length() == 0) {
System.out.println("No guids found in account guid " + masterGuid.getEntityName() + "; exiting.");
System.exit(-1);
}
if (existingGuids.length() < numberOfGuids) {
System.out.println(existingGuids.length() + " guids found in account guid " + masterGuid.getEntityName() + " which is not enough" + "; exiting.");
System.exit(-1);
}
System.out.println("Using " + numberOfGuids + " guids");
for (int i = 0; i < numberOfGuids; i++) {
if (updateAlias != null) {
// if it was specified copy the single one
subGuids[i] = subGuids[0];
} else {
// otherwise use the ones we discovered or created above
subGuids[i] = existingGuids.getString(i);
//subGuids[i] = clients[i].guidCreate(masterGuid, "subGuid" + Utils.randomString(6)).getGuid();
//System.out.println("Using: " + subGuids[i]);
}
}
} catch (Exception e) {
System.out.println("Exception creating the subguid: " + e);
e.printStackTrace();
System.exit(1);
}
if (doingReads) {
try {
// if the user specified one guid we just need to update that one
if (updateAlias != null) {
clients[0].fieldUpdate(subGuids[0], updateField, updateValue, masterGuid);
} else {
// otherwise write the value into all guids
System.out.println("Initializing fields.");
for (int i = 0; i < numberOfGuids; i++) {
clients[i].fieldUpdate(subGuids[i], updateField, updateValue, masterGuid);
System.out.print(".");
}
}
} catch (Exception e) {
System.out.println("Exception writing the initial value: " + e);
e.printStackTrace();
System.exit(1);
}
}
}
use of edu.umass.cs.gnscommon.packets.CommandPacket in project GNS by MobilityFirst.
the class LNSPacketDemultiplexer method handleCommandPacket.
/**
* Handles a command packet that has come in from a client.
*
* @param json
* @param header
* @throws JSONException
* @throws IOException
*/
public void handleCommandPacket(JSONObject json, NIOHeader header) throws JSONException, IOException {
CommandPacket packet = new CommandPacket(json);
LNSRequestInfo requestInfo = new LNSRequestInfo(packet.getRequestID(), packet, header.sndr);
GNSConfig.getLogger().log(Level.INFO, "{0} inserting outgoing request {1} with header {2}", new Object[] { this, json, header });
handler.addRequestInfo(packet.getRequestID(), requestInfo, header);
packet = removeSenderInfo(json);
if (requestInfo.getCommandType().isCreateDelete() || requestInfo.getCommandType().isSelect()) {
// if (GNSCommandProtocol.CREATE_DELETE_COMMANDS.contains(requestInfo.getCommandName())
// || requestInfo.getCommandName().equals(GNSCommandProtocol.SELECT)) {
this.asyncLNSClient.sendRequestAnycast(packet, callback);
} else {
this.asyncLNSClient.sendRequest(packet, callback, redirector);
}
}
Aggregations