Search in sources :

Example 1 with GNSRecordMap

use of edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap in project GNS by MobilityFirst.

the class NoSQLRecordsThroughputTest method testlookupMultipleSystemAndUserFields.

private static void testlookupMultipleSystemAndUserFields(String node, String guid, String field) {
    //NoSQLRecords instance = new MongoRecords<String>(node);
    NoSQLRecords instance = new DiskMapRecords(node);
    GNSRecordMap<String> recordMap = new GNSRecordMap<String>(instance, COLLECTION_NAME);
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        System.out.println("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    NameRecord nameRecord = new NameRecord(recordMap, guid, valuesMap);
    try {
        instance.insert(COLLECTION_NAME, guid, nameRecord.toJSONObject());
    } catch (JSONException e) {
        System.out.println("Problem writing json " + e);
    } catch (FailedDBOperationException e) {
        System.out.println("Problem adding " + json.toString() + " as value of " + guid + ": " + e);
    } catch (RecordExistsException e) {
        System.out.println(guid + " record already exists in database. Try something else." + e);
    }
    // and try to read it as fast as possible
    try {
        ArrayList<ColumnField> userFields = new ArrayList<>(Arrays.asList(new ColumnField(field, ColumnFieldType.USER_JSON)));
        int frequency = 10000;
        reset();
        do {
            Map<ColumnField, Object> map = instance.lookupSomeFields(COLLECTION_NAME, guid, NameRecord.NAME, NameRecord.VALUES_MAP, userFields);
            if (incrCount() % frequency == 0) {
                System.out.println(map);
                System.out.println(DelayProfiler.getStats());
                System.out.println("op/s = " + Format.formatTime(getCount() * 1000.0 / (System.currentTimeMillis() - initTime)));
                if (getCount() > frequency * 20) {
                    System.out.println("**********************resetting************************");
                    reset();
                }
            }
        } while (true);
    } catch (FailedDBOperationException | RecordNotFoundException e) {
        System.out.println("Lookup failed: " + e);
    }
}
Also used : RecordExistsException(edu.umass.cs.gnscommon.exceptions.server.RecordExistsException) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) GNSRecordMap(edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap) RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)1 RecordExistsException (edu.umass.cs.gnscommon.exceptions.server.RecordExistsException)1 RecordNotFoundException (edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException)1 GNSRecordMap (edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap)1 NameRecord (edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord)1 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1