private void delay() { if (maxDelayMs != 0) { sleepMillis(minDelayMs + random.nextInt(maxDelayMs)); } }
private void delay() { if (maxDelayMs > 0) { sleepMillis(minDelayMs + random.nextInt(maxDelayMs)); } }
public static void sleepUntilMs(long deadlineMs) { long now = System.currentTimeMillis(); long duration = deadlineMs - now; if (duration > 0) { sleepMillis(duration); } }
@Override public Object process(Map.Entry<Integer, Long> entry) { sleepMillis(delayMs); long newValue = entry.getValue() + increment; entry.setValue(newValue); return null; } }
@Override @SuppressWarnings("unchecked") public void delete(Object object) { if (deleteDelayMs > 0) { sleepMillis(deleteDelayMs); } K key = (K) object; V value = writtenKeys.remove(key); if (value != null) { deletedEntries.put(key, value); } deleteCount.incrementAndGet(); }
@Override public Map<K, K> loadAll(Iterable<? extends K> keys) { if (loadAllDelayMs > 0) { sleepMillis(loadAllDelayMs); } Map<K, K> map = new HashMap<K, K>(); for (K key : keys) { load(key); map.put(key, key); } return map; }
@Override public void afterCompletion() { // wait, so that our entry listener implementation can catch the last incoming events from other members / clients sleepMillis(SLEEP_CATCH_EVENTS_MILLIS); listeners.add(listener); } }
@Override public K load(final K key) { checkNotNull(key, "load null key!"); if (loadDelayMs > 0) { sleepMillis(loadDelayMs); } loaded.put(key, key); loadCount.incrementAndGet(); return key; }
@Override public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> entries) { if (writeAllDelayMs > 0) { sleepMillis(writeAllDelayMs); } for (Cache.Entry<? extends K, ? extends V> entry : entries) { write(entry); } }
@Override public void deleteAll(Collection<?> entries) { if (deleteAllDelayMs > 0) { sleepMillis(deleteAllDelayMs); } for (Iterator<?> keys = entries.iterator(); keys.hasNext(); ) { delete(keys.next()); keys.remove(); } }
@AfterRun public void afterRun() throws Exception { sleepMillis((maxTryTimeMillis + maxLeaseTimeMillis) * 2); }
public void shutdown() { messageQueue.add(POISON_PILL); SimulatorMessage message = messageQueue.peek(); while (message != null) { if (!POISON_PILL.equals(message)) { int queueSize = messageQueue.size(); LOGGER.debug(format("%d messages pending on messageQueue, first message: %s", queueSize, message)); } sleepMillis(WAIT_FOR_EMPTY_QUEUE_MILLIS); message = messageQueue.peek(); } joinThread(messageQueueThread); } }
@Override public void write(Cache.Entry<? extends K, ? extends V> entry) { if (writeDelayMs > 0) { sleepMillis(writeDelayMs); } writtenKeys.put(entry.getKey(), entry.getValue()); writeCount.incrementAndGet(); }
private void waitForWorkerShutdown(int expectedWorkerCount) { int timeoutSeconds = simulatorProperties.getWaitForWorkerShutdownTimeoutSeconds(); long started = System.nanoTime(); LOGGER.info(format("Waiting up to %d seconds for shutdown of %d Workers...", timeoutSeconds, expectedWorkerCount)); long expirationTimeMillis = System.currentTimeMillis() + SECONDS.toMillis(timeoutSeconds); while (componentRegistry.workerCount() > 0 && System.currentTimeMillis() < expirationTimeMillis) { sleepMillis(FINISHED_WORKERS_SLEEP_MILLIS); } List<WorkerData> remainingWorkers = componentRegistry.getWorkers(); if (remainingWorkers.isEmpty()) { LOGGER.info(format("Finished shutdown of all Workers (%d seconds)", getElapsedSeconds(started))); } else { LOGGER.warn(format("Aborted waiting for shutdown of all Workers (%d still running)...", remainingWorkers.size())); LOGGER.warn(format("Unfinished workers: %s", toString(remainingWorkers))); } }
@AfterRun public void afterRun(ThreadState state) { // sleep to give time for the last EntryProcessor tasks to complete sleepMillis(maxProcessorDelayMs * 2); resultsPerWorker.add(state.localIncrementsAtKey); }
@AfterRun public void afterRun(ThreadState state) { // sleep to give time for the last EntryProcessor tasks to complete sleepMillis(maxProcessorDelayMs * 2); resultsPerWorker.add(state.result); }
@Override public Object process(MutableEntry<Integer, Long> entry, Object... arguments) { if (delayMs > 0) { sleepMillis(delayMs); } long newValue = entry.getValue() + increment; entry.setValue(newValue); return null; } }
@Run public void run() { while (!testContext.isStopped()) { probe.recordValue(LATENCY_NANOS); sleepMillis(1); } } }
@Override public void run() { PingOperation operation = new PingOperation(); while (running) { try { invokeOnAllWorkers(operation); sleepMillis(pingIntervalMillis); } catch (SimulatorProtocolException e) { if (e.getCause() instanceof InterruptedException) { break; } } } } }
@Override public void run() { while (running) { try { for (WorkerProcess workerProcess : workerProcessManager.getWorkerProcesses()) { detectFailures(workerProcess); if (workerProcess.isFinished()) { workerProcessManager.remove(workerProcess); } } } catch (Exception e) { LOGGER.fatal("Failed to scan for failures", e); } sleepMillis(checkIntervalMillis); } }