use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AdminTestSuite method setupBeforeClass.
/**
*
* @throws IOException
*/
@BeforeClass
public static void setupBeforeClass() throws IOException {
System.out.println("Starting client");
clientCommands = new GNSClientCommands();
// Make all the reads be coordinated
clientCommands.setForceCoordinatedReads(true);
// arun: connectivity check embedded in GNSClient constructor
boolean connected = clientCommands instanceof GNSClient;
if (connected) {
System.out.println("Client created and connected to server.");
}
//
int tries = 5;
boolean accountCreated = false;
do {
try {
System.out.println("Creating account guid: " + (tries - 1) + " attempt remaining.");
masterGuid = GuidUtils.getGUIDKeys(globalAccountName);
accountCreated = true;
} catch (Exception e) {
Utils.failWithStackTrace("Failure getting master guid");
ThreadUtils.sleep((5 - tries) * 5000);
}
} while (!accountCreated && --tries > 0);
if (accountCreated == false) {
Utils.failWithStackTrace("Failure setting up account guid; aborting all tests.");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class CapacityTestForLatencyClient method setup.
/**
* @throws Exception
*/
public static void setup() throws Exception {
numClients = 10;
if (System.getProperty("numClients") != null) {
numClients = Integer.parseInt(System.getProperty("numClients"));
}
System.out.println("There are " + numClients + " clients.");
someField = "someField";
if (System.getProperty("field") != null) {
someField = System.getProperty("field");
}
withSignature = false;
if (System.getProperty("withSigniture") != null) {
withSignature = Boolean.parseBoolean(System.getProperty("withSigniture"));
}
RATE = 10;
if (System.getProperty("rate") != null) {
RATE = Integer.parseInt(System.getProperty("rate"));
}
TOTAL = RATE * DURATION / 1000;
EXTRA_WAIT_TIME = 0;
if (System.getProperty("extraTime") != null) {
EXTRA_WAIT_TIME = 1000 * Integer.parseInt(System.getProperty("extraTime"));
}
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"));
}
if (System.getProperty("sequential") != null) {
sequential = Boolean.parseBoolean(System.getProperty("sequential"));
}
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);
assert (entry != null);
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.GNSClientCommands 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.GNSClientCommands 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.GNSClientCommands in project GNS by MobilityFirst.
the class TestActiveACL method setupClientsAndGuids.
/**
* @throws Exception
*/
@BeforeClass
public static void setupClientsAndGuids() throws Exception {
client = new GNSClientCommands();
entries = new GuidEntry[numGuid];
// initialize three GUID
for (int i = 0; i < numGuid; i++) {
try {
entries[i] = GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT_GUID_PREFIX + i, PASSWORD);
} catch (Exception e) {
}
}
System.out.println("Create 3 GUIDs:GUID_0, GUID_1 and GUID_2");
// initialize the fields for each guid
client.fieldUpdate(entries[0], someField, someValue);
client.aclAdd(AclAccessType.READ_WHITELIST, entries[0], someField, entries[2].getGuid());
System.out.println("Update value of field '" + someField + "' for GUID_0 to " + someValue + ", and add GUID_2 into " + someField + "'s ACL.");
}
Aggregations