/** * Returns the current "cache time" in milliseconds since the epoch. * The "cache time" takes into account skew among the local clocks * on the various machines involved in the cache. */ public long cacheTimeMillis() { long result; final long offset = getCacheTimeOffset(); final long st = getStopTime(); if (st != 0) { result = st + offset; if (result < 0 || result > MAX_CACHE_TIME_MILLIS) { throw new IllegalStateException("Expected cacheTimeMillis " + result + " to be >= 0 and <= " + MAX_CACHE_TIME_MILLIS + " stopTime=" + st + " offset=" + offset); } } else { long ct = System.currentTimeMillis(); result = ct + offset; if (result < 0 || result > MAX_CACHE_TIME_MILLIS) { throw new IllegalStateException("Expected cacheTimeMillis " + result + " to be >= 0 and <= " + MAX_CACHE_TIME_MILLIS + " curTime=" + ct + " offset=" + offset); } } return result; }
@Override public Object call() throws Exception { InternalDistributedSystem system = getSystem(); DistributionManager dm = (DistributionManager) system.getDistributionManager(); long timeOffset = dm.getCacheTimeOffset(); return timeOffset; } });
@Override public Object call() throws Exception { InternalDistributedSystem system = getSystem(); DistributionManager dm = (DistributionManager) system.getDistributionManager(); long timeOffset = dm.getCacheTimeOffset(); return timeOffset; } });
@Override public Object call() throws Exception { InternalDistributedSystem system = getSystem(); DistributionManager dm = (DistributionManager) system.getDistributionManager(); long timeOffset = dm.getCacheTimeOffset(); return timeOffset; } });
@Override public Object call() throws CacheException { InternalDistributedSystem system = getSystem(); DistributionManager dm = (DistributionManager) system.getDistributionManager(); DMTestHook testHook = dm.getTestHook(); assertNotNull(testHook); while(testHook.getInformation("TimerTaskCancelled") == null) { pause(100); } boolean isCancelled = (Boolean) testHook.getInformation("TimerTaskCancelled"); List<Long> cacheTimes = (List) testHook.getInformation("CacheTime"); List<Long> awaitedTimes = (List) testHook.getInformation("AwaitedTime"); assertTrue(isCancelled); assertEquals(cacheTimes.size(), awaitedTimes.size()); for (int i=0; i<cacheTimes.size()-1; i++) { //Last one wont satisfy condition. assertTrue((cacheTimes.get(i) - awaitedTimes.get(i)) >= 0); } dm.setDMTestHook(null); return dm.getCacheTimeOffset(); } });
@Override public Object call() throws CacheException { InternalDistributedSystem system = getSystem(); // Just to make sure the cache time is started and accepts dm timer task. Cache cache = CacheFactory.create(system); DistributionManager dm = (DistributionManager) system.getDistributionManager(); dm.setDMTestHook(new DistManagerTestHook()); return dm.getCacheTimeOffset(); } });
@Override public void run2() throws CacheException { InternalDistributedSystem system = (InternalDistributedSystem) InternalDistributedSystem .getAnyInstance(); final DistributionManager dm = (DistributionManager) system.getDistributionManager(); // Set lower time offset long currOffset = dm.getCacheTimeOffset(); final long newOffset = currOffset - 10 /* ms */; dm.setCacheTimeOffset(null, newOffset, false); // Let GemfireTimeSync protocol kick in after VIEW_CHANGE waitForCriterion(new WaitCriterion() { @Override public boolean done() { return dm.getCacheTimeOffset() == newOffset; } @Override public String description() { return "Waiting for locator cache time to slowdown"; } }, 30, 2, true); } });
@Override public Object call() throws Exception { InternalDistributedSystem system = getSystem(); JChannel jchannel = MembershipManagerHelper.getJChannel(system); final UnitTestHook gftsTestHook = new UnitTestHook(); Protocol prot = jchannel.getProtocolStack().findProtocol("GemFireTimeSync"); GemFireTimeSync gts = (GemFireTimeSync)prot; gts.setTestHook(gftsTestHook); //Let the syncMessages reach to all VMs for new offsets. waitForCriterion(new WaitCriterion() { @Override public boolean done() { return gftsTestHook.getBarrier() == GemFireTimeSync.OFFSET_RESPONSE; } @Override public String description() { return "Waiting for this node to get time offsets from co-ordinator"; } }, 500, 50, false); DistributionManager dm = (DistributionManager) system.getDistributionManager(); long timeOffset = dm.getCacheTimeOffset(); gts.setTestHook(null); return timeOffset; } });
long timeOffset = dm.getCacheTimeOffset(); gts.setTestHook(null);