/** * Puts the current thread to sleep for the desired number of ms, suppressing any exceptions. * * @param sleeptime number of ms to sleep */ public static void sleepThread(long sleeptime) { sleepThread(sleeptime, null); }
@Override public void run() { TestingUtil.sleepThread(period); } }
@Override public Object get(Object key) { Object result = super.get(key); TestingUtil.sleepThread(0); return result; } };
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(val); TestingUtil.sleepThread(delay); }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { val = (String) in.readObject(); TestingUtil.sleepThread(delay); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { TestingUtil.sleepThread(2000); in.defaultReadObject(); }
public static void sleepRandom(int maxTime) { sleepThread(random.nextInt(maxTime)); }
@Override public void run() { while (running) { try { currentValue++; if (tm != null) tm.begin(); cache.put(key, "v" + currentValue); if (tm != null) tm.commit(); TestingUtil.sleepThread(r.nextInt(10) * 10); } catch (Exception e) { // do nothing? } } } }
@Override public void call() { for (int i = 0; i < 1000; i++) { cm.getCache(generateRandomString(20)); } System.out.println("Took: " + TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start)); TestingUtil.sleepThread(2000); } });
public static void blockUntilViewsReceived(long timeout, boolean barfIfTooManyMembers, CacheContainer... cacheContainers) { long failTime = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < failTime) { if (areCacheViewsComplete(barfIfTooManyMembers, cacheContainers)) { return; } sleepThread(100); } viewsTimedOut(cacheContainers); }
@CacheEntriesEvicted @SuppressWarnings("unused") public void entryEvicted(Event e) { log.info("Cache entries evicted, now check in different thread"); after.countDown(); // Force a bit of delay in the listener so that lack of visibility // of changes in container can be appreciated more easily TestingUtil.sleepThread(1000); } }
@CacheEntriesEvicted @SuppressWarnings("unused") public void entryEvicted(Event e) { log.info("Cache entry evicted, now check in different thread"); after.countDown(); // Force a bit of delay in the listener so that lack of visibility // of changes in container can be appreciated more easily TestingUtil.sleepThread(1000); }
/** * Blocks until the cache has reached a specified state. * * @param cache cache to watch * @param cacheStatus status to wait for * @param timeout timeout to wait for */ public static void blockUntilCacheStatusAchieved(Cache cache, ComponentStatus cacheStatus, long timeout) { AdvancedCache spi = cache.getAdvancedCache(); long killTime = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < killTime) { if (spi.getStatus() == cacheStatus) return; sleepThread(50); } throw new RuntimeException("Timed out waiting for condition"); }
public void blockUntilCacheStoreContains(Object key, Object expectedValue, long timeout) { long killTime = timeService.wallClockTime() + timeout; while (timeService.wallClockTime() < killTime) { MarshalledEntry entry = deserialize(key, store.get(key), true, false); if (entry != null && entry.getValue().equals(expectedValue)) return; TestingUtil.sleepThread(50); } throw new RuntimeException(String.format( "Timed out waiting (%d ms) for cache store to contain key=%s with value=%s", timeout, key, expectedValue)); }
public static void blockUntilViewReceived(Cache cache, int groupSize, long timeout, boolean barfIfTooManyMembersInView) { long failTime = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < failTime) { sleepThread(100); EmbeddedCacheManager cacheManager = cache.getCacheManager(); if (isCacheViewComplete(cacheManager.getMembers(), cacheManager.getAddress(), groupSize, barfIfTooManyMembersInView)) { return; } } throw new RuntimeException(String.format( "Timed out before cache had %d members. View is %s", groupSize, cache.getCacheManager().getMembers())); }
protected void assertOnAllCaches(Object key, String value) { for (Cache<K, V> c : caches) { Object realVal = c.get(key); if (value == null) { assert realVal == null : "Expecting [" + key + "] to equal [" + value + "] on cache [" + addressOf(c) + "] but was [" + realVal + "]. Owners are " + Arrays.toString(getOwners(key)); } else { assert value.equals(realVal) : "Expecting [" + key + "] to equal [" + value + "] on cache [" + addressOf(c) + "] but was [" + realVal + "]"; } } // Allow some time for all ClusteredGetCommands to finish executing TestingUtil.sleepThread(100); }
@Override public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable { // First execute the operation itself Object ret = super.visitPutKeyValueCommand(ctx, command); assertKeySet = (cache.keySet().size() == 1); // After entry has been committed to the container log.info("Cache entry created, now check in different thread"); latch.countDown(); // Force a bit of delay in the listener TestingUtil.sleepThread(3000); return ret; }
@Override public void call() { // simulate slow back end store store.lock.lock(); try { cache.put("k1", "v1"); cache.put("k2", "v2"); // force eviction of "k1" TestingUtil.sleepThread(100); // wait until the only AsyncProcessor thread is blocked cache.put("k3", "v3"); cache.put("k4", "v4"); // force eviction of "k3" assert "v3".equals(cache.get("k3")) : "cache must return k3 == v3 (was: " + cache.get("k3") + ")"; } finally { store.lock.unlock(); } } });
@Override public void write(MarshalledEntry entry) { assertRunning(); record("write"); if (configuration.slow()) { TestingUtil.sleepThread(SLOW_STORE_WAIT); } if (entry!= null) { if (trace) log.tracef("Store %s in dummy map store@%s", entry, Util.hexIdHashCode(store)); store.put(entry.getKey(), serialize(entry)); } }
@Override public void call() { cache.put("k1", "v1"); cache.put("k2", "v2"); TestingUtil.sleepThread(200); assertFalse("expiry doesn't work even after expiration", 2 == cache.getAdvancedCache().getDataContainer().size()); } });