private static final long WRITE_SIZE_VALUE = 13;
private static final long READ_SIZE_VALUE = 17;
public void testSync() throws Exception{
Thread[] threads = new Thread[THREAD_COUNT];
final DFSClientMetrics metrics = new DFSClientMetrics(true);
for(int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < OPERATIONS_PER_THREAD; i++) {
metrics.incLsCalls();
metrics.incNumCreateDirOps();
metrics.incNumCreateFileOps();
metrics.incPreadOps();
metrics.incPreadSize(PREAD_SIZE_VALUE);
metrics.incPreadTime(PREAD_TIME_VALUE);
metrics.incReadOps();
metrics.incReadsFromLocalFile();
metrics.incReadSize(READ_SIZE_VALUE);
metrics.incReadTime(READ_TIME_VALUE);
metrics.incSyncTime(SYNC_TIME_VALUE);
metrics.incWriteOps();
metrics.incWriteSize(WRITE_SIZE_VALUE);
}
}
});
}
for(int i = 0; i < threads.length; i++) {
threads[i].start();
}
for(int i = 0; i < threads.length; i++) {
threads[i].join();
}
// This is dependent to DFSClientMetrics private API; used to obtain value
// of lsCalls.
Method privateStringMethod = DFSClientMetrics.class
.getDeclaredMethod("getAndResetLsCalls");
privateStringMethod.setAccessible(true);
long returnValue = (Long) privateStringMethod.invoke(metrics);
assertEquals(THREAD_COUNT * OPERATIONS_PER_THREAD, returnValue);
metrics.doUpdates(null);
assertEquals(THREAD_COUNT * OPERATIONS_PER_THREAD,
metrics.numCreateDirOps.getPreviousIntervalValue());
assertEquals(THREAD_COUNT * OPERATIONS_PER_THREAD,
metrics.numCreateFileOps.getPreviousIntervalValue());