public void InsertDelayedTask() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); double t1 = 0; double t2 = 0; DateTime tim1 = DateTime.Now; e.Schedule(new RunnableAction(delegate { t1 = (DateTime.Now - tim1).TotalMilliseconds; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(20); DateTime tim2 = DateTime.Now; e.Schedule(new RunnableAction(delegate { t2 = (DateTime.Now - tim2).TotalMilliseconds; }), 50, TimeUnit.MILLISECONDS); Thread.Sleep(150); Assert.IsTrue(t2 >= 50, "Elapsed: " + t2); Assert.IsTrue(t2 < 50 + delayDif, "Elapsed: " + t2); Assert.IsTrue(t1 >= 100, "Elapsed: " + t1); Assert.IsTrue(t1 < 100 + delayDif, "Elapsed: " + t1); e.ShutdownNow(); }
/// <summary> /// Run a set of threads making changes to the deprecations /// concurrently with another set of threads calling get() /// and set() on Configuration objects. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestConcurrentDeprecateAndManipulate() { int NumThreadIds = 10; int NumKeysPerThread = 1000; ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2 * NumThreadIds , new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat("testConcurrentDeprecateAndManipulate modification thread %d" ).Build()); CountDownLatch latch = new CountDownLatch(1); AtomicInteger highestModificationThreadId = new AtomicInteger(1); IList <Future <Void> > futures = new List <Future <Void> >(); for (int i = 0; i < NumThreadIds; i++) { futures.AddItem(executor.Schedule(new _Callable_363(latch, highestModificationThreadId , NumKeysPerThread), 0, TimeUnit.Seconds)); } AtomicInteger highestAccessThreadId = new AtomicInteger(1); for (int i_1 = 0; i_1 < NumThreadIds; i_1++) { futures.AddItem(executor.Schedule(new _Callable_382(latch, highestAccessThreadId, NumKeysPerThread), 0, TimeUnit.Seconds)); } latch.CountDown(); // allow all threads to proceed foreach (Future <Void> future in futures) { Uninterruptibles.GetUninterruptibly(future); } }
public void InsertDelayedTask () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); double t1 = 0; double t2 = 0; DateTime tim1 = DateTime.Now; e.Schedule (new RunnableAction (delegate { t1 = (DateTime.Now - tim1).TotalMilliseconds; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (20); DateTime tim2 = DateTime.Now; e.Schedule (new RunnableAction (delegate { t2 = (DateTime.Now - tim2).TotalMilliseconds; }),50, TimeUnit.MILLISECONDS); Thread.Sleep (150); Assert.IsTrue (t2 >= 50, "Elapsed: " + t2); Assert.IsTrue (t2 < 50 + delayDif, "Elapsed: " + t2); Assert.IsTrue (t1 >= 100, "Elapsed: " + t1); Assert.IsTrue (t1 < 100 + delayDif, "Elapsed: " + t1); e.ShutdownNow (); }
public void ShutdownNoContinueExisting() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); e.SetExecuteExistingDelayedTasksAfterShutdownPolicy(false); bool run = false; e.Schedule(new RunnableAction(delegate { run = true; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(50); e.Shutdown(); Assert.IsTrue(e.IsShutdown()); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); Thread.Sleep(100); Assert.IsFalse(run); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); }
public void ShutdownNow() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); bool run = false; e.Schedule(new RunnableAction(delegate { run = true; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(50); var pending = e.ShutdownNow(); Assert.AreEqual(0, pending.Count); Assert.IsTrue(e.IsShutdown()); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); Thread.Sleep(100); Assert.IsFalse(run); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); }
internal virtual void UncacheBlock(string bpid, long blockId) { lock (this) { ExtendedBlockId key = new ExtendedBlockId(blockId, bpid); FsDatasetCache.Value prevValue = mappableBlockMap[key]; bool deferred = false; if (!dataset.datanode.GetShortCircuitRegistry().ProcessBlockMunlockRequest(key)) { deferred = true; } if (prevValue == null) { Log.Debug("Block with id {}, pool {} does not need to be uncached, " + "because it is not currently in the mappableBlockMap." , blockId, bpid); numBlocksFailedToUncache.IncrementAndGet(); return; } switch (prevValue.state) { case FsDatasetCache.State.Caching: { Log.Debug("Cancelling caching for block with id {}, pool {}.", blockId, bpid); mappableBlockMap[key] = new FsDatasetCache.Value(prevValue.mappableBlock, FsDatasetCache.State .CachingCancelled); break; } case FsDatasetCache.State.Cached: { mappableBlockMap[key] = new FsDatasetCache.Value(prevValue.mappableBlock, FsDatasetCache.State .Uncaching); if (deferred) { Log.Debug("{} is anchored, and can't be uncached now. Scheduling it " + "for uncaching in {} " , key, DurationFormatUtils.FormatDurationHMS(revocationPollingMs)); deferredUncachingExecutor.Schedule(new FsDatasetCache.UncachingTask(this, key, revocationMs ), revocationPollingMs, TimeUnit.Milliseconds); } else { Log.Debug("{} has been scheduled for immediate uncaching.", key); uncachingExecutor.Execute(new FsDatasetCache.UncachingTask(this, key, 0)); } break; } default: { Log.Debug("Block with id {}, pool {} does not need to be uncached, " + "because it is in state {}." , blockId, bpid, prevValue.state); numBlocksFailedToUncache.IncrementAndGet(); break; } } } }
public void DelayedTask () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); DateTime tim = DateTime.Now; var future = e.Schedule (new RunnableAction (delegate { Console.WriteLine ("t1"); }),50, TimeUnit.MILLISECONDS); future.Get (); double elapsed = (DateTime.Now - tim).TotalMilliseconds; Assert.IsTrue (elapsed >= 50, "Elapsed: " + elapsed); Assert.IsTrue (elapsed < 60 + delayDif, "Elapsed: " + elapsed); e.ShutdownNow (); }
public void DelayedTask() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); DateTime tim = DateTime.Now; var future = e.Schedule(new RunnableAction(delegate { Console.WriteLine("t1"); }), 50, TimeUnit.MILLISECONDS); future.Get(); double elapsed = (DateTime.Now - tim).TotalMilliseconds; Assert.IsTrue(elapsed >= 50, "Elapsed: " + elapsed); Assert.IsTrue(elapsed < 60 + delayDif, "Elapsed: " + elapsed); e.ShutdownNow(); }
public void Shutdown() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); bool run = false; e.Schedule (new RunnableAction (delegate { run = true; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (50); e.Shutdown (); Assert.IsTrue (e.IsShutdown ()); Assert.IsFalse (e.IsTerminated (), "Terminated"); Assert.IsTrue (e.IsTerminating (), "Terminating"); Thread.Sleep (100); Assert.IsTrue (run, "Not run"); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); }
public void ShutdownNoContinueExisting () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); e.SetExecuteExistingDelayedTasksAfterShutdownPolicy (false); bool run = false; e.Schedule (new RunnableAction (delegate { run = true; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (50); e.Shutdown (); Assert.IsTrue (e.IsShutdown ()); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); Thread.Sleep (100); Assert.IsFalse (run); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); }