use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class CapacityTestForThruputClient method setup.
/**
* @throws Exception
*/
public static void setup() throws Exception {
numClients = 10;
if (System.getProperty("numClients") != null) {
numClients = Integer.parseInt(System.getProperty("numClients"));
}
someField = "someField";
if (System.getProperty("field") != null) {
someField = System.getProperty("field");
}
withMalicious = false;
if (System.getProperty("withMalicious") != null) {
withMalicious = Boolean.parseBoolean(System.getProperty("withMalicious"));
}
withSignature = false;
if (System.getProperty("withSigniture") != null) {
withSignature = Boolean.parseBoolean(System.getProperty("withSigniture"));
}
isRead = true;
if (System.getProperty("isRead") != null) {
isRead = Boolean.parseBoolean(System.getProperty("isRead"));
}
if (System.getProperty("numThread") != null) {
NUM_THREAD = Integer.parseInt(System.getProperty("numThread"));
}
String keyFile = "guid";
if (System.getProperty("keyFile") != null) {
keyFile = System.getProperty("keyFile");
}
ObjectInputStream input = new ObjectInputStream(new FileInputStream(new File(keyFile)));
entry = new GuidEntry(input);
input.close();
assert (entry != null);
String malKeyFile = "mal_guid";
if (System.getProperty("malKeyFile") != null) {
malKeyFile = System.getProperty("malKeyFile");
}
if (new File(malKeyFile).exists()) {
input = new ObjectInputStream(new FileInputStream(new File(malKeyFile)));
malEntry = new GuidEntry(input);
}
fraction = 0.0;
if (System.getProperty("fraction") != null) {
fraction = Double.parseDouble(System.getProperty("fraction"));
}
ratio = 0.0;
if (System.getProperty("ratio") != null) {
ratio = Double.parseDouble(System.getProperty("ratio"));
}
executor = Executors.newFixedThreadPool(NUM_THREAD);
clients = new GNSClientCommands[numClients];
for (int i = 0; i < numClients; i++) {
clients[i] = new GNSClientCommands();
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class GNSClientCapacityTest method setupClientsAndGuids.
private static void setupClientsAndGuids() throws Exception {
clients = new GNSClient[numClients];
executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(50 * numClients);
for (int i = 0; i < numClients; i++) clients[i] = new GNSClientCommands();
@SuppressWarnings("deprecation") String gnsInstance = GNSClient.getGNSProvider();
accountGuidEntries = new GuidEntry[numAccountGuids];
int numPreExisting = 0;
for (int i = 0; i < numAccountGuids; i++) {
log.log(Level.FINE, "Creating account GUID {0}", new Object[] { accountGUIDPrefix + i });
try {
accountGuidEntries[i] = GuidUtils.lookupOrCreateAccountGuid(clients[0], accountGUIDPrefix + i, PASSWORD);
log.log(Level.FINE, "Created account {0}", new Object[] { accountGuidEntries[i] });
assert (accountGuidEntries[i].getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, accountGUIDPrefix + i).getGuid()));
} catch (DuplicateNameException e) {
numPreExisting++;
accountGuidEntries[i] = KeyPairUtils.getGuidEntry(gnsInstance, accountGUIDPrefix + i);
log.log(Level.INFO, "Found that account {0} already exists", new Object[] { accountGuidEntries[i] });
}
// any other exceptions should be thrown up
}
accessor = GuidUtils.lookupOrCreateAccountGuid(clients[0], accountGUIDPrefix + "_accessor", PASSWORD);
System.out.println("Created (" + (numAccountGuids - numPreExisting) + ") or found pre-existing (" + numPreExisting + ") a total of " + numAccountGuids + " account GUIDs: " + Arrays.asList(accountGuidEntries));
if (accountGuidsOnly) {
for (int i = 0; i < accountGuidEntries.length; i++) guidEntries[i] = accountGuidEntries[i];
return;
}
guidEntries = new GuidEntry[numGuids];
Set<String> subGuids = new HashSet<String>();
for (int i = 0, j = 0; i < numGuids; i++) {
subGuids.add(accountGUIDPrefix + 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 = GuidUtils.lookupOrCreateGuid(clients[0], accountGuidEntries[i / numGuidsPerAccount], subGuid);
assert (created.getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, subGuid).getGuid()));
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exceptions should be thrown up
} else
try {
// batch create
clients[0].execute(GNSCommand.batchCreateGUIDs(accountGuidEntries[i / numGuidsPerAccount], subGuids));
} catch (Exception e) {
for (String subGuid : subGuids) {
try {
clients[0].execute(GNSCommand.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);
}
log.log(Level.FINE, "Created sub-guid(s) {0}", new Object[] { 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));
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ThroughputAsynchMultiClientTest method createSubGuidsAndWriteValue.
/**
* Creates the guids where do all the data access.
* If the user specifies an updateAlias we make one
* guid using that alias and use that for all clients. Otherwise we
* make a bunch of random guids.
* @param useExistingGuids
*/
public void createSubGuidsAndWriteValue(boolean useExistingGuids) {
try {
// to do all the operations from
if (updateAlias != null) {
// if it was specified find or create the guid for updateAlias
subGuids[0] = GuidUtils.lookupOrCreateGuid(clients[0], masterGuid, updateAlias, true).getGuid();
}
JSONArray existingGuids = null;
GuidEntry[] createdGuids = new GuidEntry[numberOfGuids];
// a bunch of aliases that are subalises to the masterGuid
if (updateAlias == null) {
if (!useExistingGuids) {
// Create the the guids set up below.
for (int i = 0; i < numberOfGuids; i++) {
createdGuids[i] = clients[i].guidCreate(masterGuid, "subGuid" + RandomString.randomString(6));
System.out.println("Created: " + createdGuids[i].getEntityName());
}
}
try {
JSONObject command = createCommand(CommandType.LookupRandomGuids, GNSProtocol.GUID.toString(), masterGuid.getGuid(), GNSProtocol.GUIDCNT.toString(), numberOfGuids);
String result = clients[0].execute(new CommandPacket((long) (Math.random() * Long.MAX_VALUE), command)).getResultString();
if (!result.startsWith(GNSProtocol.BAD_RESPONSE.toString())) {
existingGuids = new JSONArray(result);
} else {
System.out.println("Problem reading random guids " + result);
System.exit(-1);
}
} catch (JSONException | IOException | ClientException e) {
System.out.println("Problem reading random guids " + e);
System.exit(-1);
}
}
// Ensure that we have enough guids
if (existingGuids.length() == 0) {
System.out.println("No guids found in account guid " + masterGuid.getEntityName() + "; exiting.");
System.exit(-1);
}
if (existingGuids.length() < numberOfGuids) {
System.out.println(existingGuids.length() + " guids found in account guid " + masterGuid.getEntityName() + " which is not enough" + "; exiting.");
System.exit(-1);
}
System.out.println("Using " + numberOfGuids + " guids");
for (int i = 0; i < numberOfGuids; i++) {
if (updateAlias != null) {
// if it was specified copy the single one
subGuids[i] = subGuids[0];
} else {
// otherwise use the ones we discovered or created above
subGuids[i] = existingGuids.getString(i);
//subGuids[i] = clients[i].guidCreate(masterGuid, "subGuid" + Utils.randomString(6)).getGuid();
//System.out.println("Using: " + subGuids[i]);
}
}
} catch (Exception e) {
System.out.println("Exception creating the subguid: " + e);
e.printStackTrace();
System.exit(1);
}
if (doingReads) {
try {
// if the user specified one guid we just need to update that one
if (updateAlias != null) {
clients[0].fieldUpdate(subGuids[0], updateField, updateValue, masterGuid);
} else {
// otherwise write the value into all guids
System.out.println("Initializing fields.");
for (int i = 0; i < numberOfGuids; i++) {
clients[i].fieldUpdate(subGuids[i], updateField, updateValue, masterGuid);
System.out.print(".");
}
}
} catch (Exception e) {
System.out.println("Exception writing the initial value: " + e);
e.printStackTrace();
System.exit(1);
}
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class TestActiveCodeRemoteQueryClient method setupClientsAndGuids.
/**
* @throws IOException
* @throws ClientException
*/
@BeforeClass
public static void setupClientsAndGuids() throws IOException, ClientException {
client = new GNSClient();
entries = new GuidEntry[2];
// initialize two GUID
for (int i = 0; i < numGuid; i++) {
try {
entries[i] = GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT_GUID_PREFIX + i, PASSWORD);
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(new File("guid" + i)));
entries[i].writeObject(output);
output.flush();
output.close();
} catch (Exception e) {
// the GUID has already been created, try to fetch it from a file
try {
ObjectInputStream input = new ObjectInputStream(new FileInputStream(new File("guid" + i)));
entries[i] = new GuidEntry(input);
input.close();
} catch (IOException | EncryptionException ie) {
ie.printStackTrace();
}
}
}
// set the target guid to the second one and put it into the code
targetGuid = entries[numGuid - 1].getGuid();
noop_code = new String(Files.readAllBytes(Paths.get("scripts/activeCode/noop.js")));
String codeFile = System.getProperty("activeReadCode");
if (codeFile == null)
codeFile = "scripts/activeCode/remoteReadQuery.js";
String code = new String(Files.readAllBytes(Paths.get(codeFile)));
read_code = code.replace("//substitute this line with the targetGuid", "var targetGuid=\"" + targetGuid + "\";");
System.out.println("The read code is:\n" + read_code);
codeFile = System.getProperty("activeWriteCode");
if (codeFile == null)
codeFile = "scripts/activeCode/remoteWriteQuery.js";
code = new String(Files.readAllBytes(Paths.get(codeFile)));
write_code = code.replace("//substitute this line with the targetGuid", "var targetGuid=\"" + targetGuid + "\";");
System.out.println("The write code is:\n" + write_code);
// initialize the fields for each guid
client.execute(GNSCommand.fieldUpdate(entries[0], someField, someValue));
client.execute(GNSCommand.fieldUpdate(entries[1], depthField, depthResult));
System.out.println(">>>>>>>>>> Testing >>>>>>>>>>");
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class GNSClientCapacityTest method test_01_SingleWrite.
/**
* Verifies a single write is successful.
* @throws IOException
*/
@Test
public void test_01_SingleWrite() throws IOException {
GuidEntry guid = guidEntries[0];
String codeFile = System.getProperty("activeCode");
int activeValue = 0;
String activeDepth = System.getProperty("activeDepth");
if (activeDepth != null)
activeValue = Integer.parseInt(activeDepth);
if (codeFile == null)
codeFile = "scripts/activeCode/noop.js";
String code = new String(Files.readAllBytes(Paths.get(codeFile)));
try {
clients[0].fieldUpdate(guid, someField, someValue);
clients[0].fieldUpdate(guid, activeField, activeValue);
// prepare for active code
if (isRead) {
clients[0].activeCodeClear(guid.getGuid(), ActiveCode.READ_ACTION, guid);
clients[0].activeCodeSet(guid.getGuid(), ActiveCode.READ_ACTION, code, guid);
} else {
clients[0].activeCodeClear(guid.getGuid(), ActiveCode.WRITE_ACTION, guid);
clients[0].activeCodeSet(guid.getGuid(), ActiveCode.WRITE_ACTION, code, guid);
}
// verify written value
Assert.assertEquals(clients[0].fieldRead(guid, someField), (someValue));
Assert.assertEquals(clients[numClients > 1 ? 1 : 0].fieldRead(guid, someField), (someValue));
} catch (IOException | ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations