Search in sources :

Example 71 with GuidEntry

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

Example 72 with GuidEntry

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

Example 73 with GuidEntry

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()));
}
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)

Example 74 with GuidEntry

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);
    }
}
Also used : JSONArray(org.json.JSONArray) 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 75 with GuidEntry

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

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