use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class GNSClientCapacityTest method cleanup.
/**
* Removes all account and sub-guids created during the test.
*
* @throws Exception
*/
@AfterClass
public static void cleanup() throws Exception {
Thread.sleep(2000);
assert (clients != null && clients[0] != null);
if (!accountGuidsOnly) {
System.out.println("About to delete " + guidEntries.length + " sub-guids: " + Arrays.asList(guidEntries));
for (GuidEntry guidEntry : guidEntries) {
try {
log.log(Level.FINE, "About to delete sub-guid {0}", new Object[] { guidEntry });
clients[0].guidRemove(guidEntry);
log.log(Level.FINE, "Deleted sub-guid {0}", new Object[] { guidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "Failed to delete sub-guid {0}", new Object[] { guidEntry });
e.printStackTrace();
// continue with rest
}
}
}
System.out.println("About to delete " + accountGuidEntries.length + " account guids: " + Arrays.asList(accountGuidEntries));
for (GuidEntry accGuidEntry : accountGuidEntries) {
try {
log.log(Level.FINE, "About to delete account guid {0}", new Object[] { accGuidEntry });
clients[0].accountGuidRemove(accGuidEntry);
log.log(Level.FINE, "Deleted account guid {0}", new Object[] { accGuidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "Failed to delete account guid {0}", new Object[] { accGuidEntry });
e.printStackTrace();
// continue with rest
}
}
for (GNSClientCommands client : clients) client.close();
executor.shutdown();
System.out.println(DelayProfiler.getStats());
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ServerConnectTest method test_010_CreateEntity.
/**
* Creates a guid.
*/
@Test
public void test_010_CreateEntity() {
String alias = "testGUID" + RandomString.randomString(12);
GuidEntry guidEntry = null;
try {
guidEntry = client.guidCreate(masterGuid, alias);
} catch (Exception e) {
failWithStackTrace("Exception while creating guid: ", e);
}
assertNotNull(guidEntry);
assertEquals(alias, guidEntry.getEntityName());
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry 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()));
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class GroupGuidLookupIndirectionTest method test_10_SetupGuids.
/**
*
*/
@Test
public void test_10_SetupGuids() {
try {
for (int cnt = 0; cnt < 5; cnt++) {
GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "guid-" + RandomString.randomString(12));
createdGuids.add(testEntry);
indirectionGroupMembers.put(testEntry.getGuid());
JSONArray array = new JSONArray(Arrays.asList(25));
clientCommands.fieldReplaceOrCreateList(testEntry, indirectionGroupTestFieldName, array);
}
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectClientTest method test_01_testQuerySelect.
/**
*
*/
@Test
public void test_01_testQuerySelect() {
String fieldName = "testQuery";
try {
for (int cnt = 0; cnt < 5; cnt++) {
GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "queryTest-" + RandomString.randomString(12));
// save them so we can delete them later
createdGuids.add(testEntry);
JSONArray array = new JSONArray(Arrays.asList(25));
clientCommands.fieldReplaceOrCreateList(testEntry, fieldName, array);
}
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
}
waitSettle(100);
try {
String query = "~" + fieldName + " : ($gt: 0)";
JSONArray result = clientCommands.selectQuery(query);
for (int i = 0; i < result.length(); i++) {
System.out.println(result.get(i).toString());
}
// best we can do should be at least 5, but possibly more objects in results
Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception executing selectNear: " + e);
}
}
Aggregations