Newer
Older
package refit.application.rezk;
import java.util.Random;
import refit.client.REFITClientLibrary;
import refit.config.REFITConfig;
import refit.util.REFITTime;
public class REZKTestClientExists extends REZKTestClient {
private static final String[] prePaths = new String[2 * REFITConfig.NR_OF_NODES];
private String[] paths;
private boolean[] isValidPath;
private int counter = 0;
public REZKTestClientExists(REFITClientLibrary service) {
super(service);
synchronized (prePaths) {
if (prePaths[0] == null) {
for (int i = 0; i < prePaths.length; i++) {
prePaths[i] = String.format("%s%05d", "/node", i);
}
}
}
paths = new String[REFITConfig.NR_OF_NODES];
isValidPath = new boolean[paths.length];
// ensure reproducibility
Random rand = new Random(service.getNodeID());
for (int i = 0; i < paths.length; i++) {
int idx = rand.nextInt(prePaths.length);
paths[i] = prePaths[idx];
isValidPath[i] = (idx < paths.length);
}
}
@Override
protected void work() throws Exception {
// Invoke operation
long startTime = REFITTime.nanoTime.getAsLong();
boolean exists = client.exists(paths[counter], false, REFITConfig.ONLY_CONSISTENT);
long endTime = REFITTime.nanoTime.getAsLong();
service.getStatistics().event((long) ((endTime - startTime) / 1000f), service.getNodeID(), "e");
if (exists != isValidPath[counter]) throw new Exception("Node shouldn't exist");
counter = (counter + 1) % paths.length;
}
}