use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectGeoTest method test_10_GeoSpatialSelectCreateGuids.
/**
*
*/
@Test
public void test_10_GeoSpatialSelectCreateGuids() {
try {
for (int cnt = 0; cnt < 5; cnt++) {
GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "geoTest-" + RandomString.randomString(12));
// save them so we can delete them later
createdGuids.add(testEntry);
clientCommands.setLocation(testEntry, 0.0, 0.0);
}
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectAutoGroupTest method test_560_QueryLookupGroupAfterAlterations.
/**
*
*/
@Test
public void test_560_QueryLookupGroupAfterAlterations() {
try {
JSONArray result = clientCommands.selectLookupGroupQuery(groupOneGuid.getGuid());
// should only be one
Assert.assertThat(result.length(), Matchers.equalTo(1));
// look up the individual values
for (int i = 0; i < result.length(); i++) {
BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
String value = clientCommands.fieldReadArrayFirstElement(entry, groupTestFieldName);
Assert.assertEquals(TEST_HIGH_VALUE, value);
}
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception executing selectLookupGroupQuery: " + e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectAutoGroupTest method test_551_QueryRemovePreviousTestFields.
/**
*
*/
@Test
public void test_551_QueryRemovePreviousTestFields() {
// find all the guids that have our field and remove it from them
try {
String query = "~" + groupTestFieldName + " : {$exists: true}";
JSONArray result = clientCommands.selectQuery(query);
for (int i = 0; i < result.length(); i++) {
BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
GuidEntry guidEntry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
System.out.println("Removing from " + guidEntry.getEntityName());
clientCommands.fieldRemove(guidEntry, groupTestFieldName);
}
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Trying to remove previous test's fields: " + e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SubGuidDeletesTest method cleanup.
/**
* @throws Exception
*/
@After
public void cleanup() throws Exception {
// sleep doesn't seem to help
Thread.sleep(2000);
assert (clients != null && clients[0] != null);
System.out.println("About to delete " + guidEntries.length + " sub-guids: " + Arrays.asList(guidEntries));
for (GuidEntry guidEntry : guidEntries) {
try {
LOGGER.log(Level.INFO, "{0} about to delete sub-guid {1}", new Object[] { this, guidEntry });
clients[0].guidRemove(guidEntry);
LOGGER.log(Level.INFO, "{0} deleted sub-guid {1}", new Object[] { this, guidEntry });
} catch (ClientException | IOException e) {
LOGGER.log(Level.WARNING, "{0} failed to delete sub-guid {1}", new Object[] { this, guidEntry });
e.printStackTrace();
// continue with rest
}
}
System.out.println("About to delete " + accountGuidEntries.length + " account guids: " + Arrays.asList(accountGuidEntries));
for (GuidEntry accGuidEntry : accountGuidEntries) {
try {
clients[0].accountGuidRemove(accGuidEntry);
LOGGER.log(Level.FINE, "{0} deleted account guid {1}", new Object[] { this, accGuidEntry });
} catch (ClientException | IOException e) {
LOGGER.log(Level.WARNING, "{0} failed to delete account guid {1}", new Object[] { this, accGuidEntry });
e.printStackTrace();
// continue with rest
}
}
for (GNSClientCommands clientCommands : clients) {
clientCommands.close();
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SubGuidDeletesTest method setupClientsAndGuids.
private void setupClientsAndGuids() throws Exception {
clients = new GNSClientCommands[numClients];
for (int i = 0; i < numClients; i++) {
clients[i] = new GNSClientCommands();
}
String gnsInstance = GNSClientCommands.getGNSProvider();
accountGuidEntries = new GuidEntry[numAccountGuids];
for (int i = 0; i < numAccountGuids; i++) {
LOGGER.log(Level.FINE, "{0} creating account GUID {1}", new Object[] { this, ACCOUNT_GUID_PREFIX + i });
try {
accountGuidEntries[i] = clients[0].accountGuidCreate(ACCOUNT_GUID_PREFIX + i, PASSWORD);
LOGGER.log(Level.FINE, "{0} created account ", new Object[] { this, accountGuidEntries[i] });
assert (accountGuidEntries[i].getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i).getGuid()));
} catch (DuplicateNameException e) {
accountGuidEntries[i] = KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i);
LOGGER.log(Level.INFO, "{0} found that account {1} already exists", new Object[] { this, accountGuidEntries[i] });
}
// any other exception should be throw up
}
System.out.println("Created or found pre-existing " + numAccountGuids + " account GUIDs: " + Arrays.asList(accountGuidEntries));
guidEntries = new GuidEntry[numGuids];
if (accountGuidsOnly) {
System.arraycopy(accountGuidEntries, 0, guidEntries, 0, accountGuidEntries.length);
return;
}
Set<String> subGuids = new HashSet<>();
for (int i = 0, j = 0; i < numGuids; i++) {
subGuids.add(Config.getGlobalString(TC.TEST_GUID_PREFIX) + i);
if (subGuids.size() == numGuidsPerAccount || i == numGuids - 1) {
// because batch creation seems buggy
if (subGuids.size() == 1) {
String subGuid = subGuids.iterator().next();
try {
GuidEntry created = clients[0].guidCreate(accountGuidEntries[i / numGuidsPerAccount], subGuid);
assert (created.getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, subGuid).getGuid()));
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exception should be throw up
} else {
try {
// batch create
clients[0].guidBatchCreate(accountGuidEntries[i / numGuidsPerAccount], subGuids);
} catch (ClientException | IOException e) {
for (String subGuid : subGuids) {
try {
clients[0].guidCreate(accountGuidEntries[i / numGuidsPerAccount], subGuid);
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exception should be throw up
}
}
}
for (String subGuid : subGuids) {
guidEntries[j++] = KeyPairUtils.getGuidEntry(gnsInstance, subGuid);
}
LOGGER.log(Level.FINE, "{0} created sub-guid(s) {1}", new Object[] { this, subGuids });
subGuids.clear();
}
}
for (GuidEntry guidEntry : accountGuidEntries) {
assert (guidEntry != null);
}
for (GuidEntry guidEntry : guidEntries) {
assert (guidEntry != null);
}
System.out.println("Created or found " + guidEntries.length + " pre-existing sub-guids " + Arrays.asList(guidEntries));
}
Aggregations