Search in sources :

Example 76 with GuidEntry

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

Example 77 with GuidEntry

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);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 78 with GuidEntry

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);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 79 with GuidEntry

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();
    }
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) After(org.junit.After)

Example 80 with GuidEntry

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));
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) DuplicateNameException(edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) HashSet(java.util.HashSet)

Aggregations

GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)134 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)87 IOException (java.io.IOException)85 Test (org.junit.Test)69 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 RandomString (edu.umass.cs.gnscommon.utils.RandomString)54 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)46 JSONException (org.json.JSONException)45 JSONArray (org.json.JSONArray)36 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)28 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)15 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)14 StringTokenizer (java.util.StringTokenizer)13 JSONObject (org.json.JSONObject)12 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)11 FileNotFoundException (java.io.FileNotFoundException)11 HashSet (java.util.HashSet)10 FileInputStream (java.io.FileInputStream)8 Repeat (edu.umass.cs.utils.Repeat)7