How to use shutdownNotSupported method of org.jmock.lib.concurrent.DeterministicScheduler class

Best Jmock-library code snippet using org.jmock.lib.concurrent.DeterministicScheduler.shutdownNotSupported

Source:NanosecondPrecisionDeterministicScheduler.java Github

copy

Full Screen

...165 throw blockingOperationsNotSupported();166 }167 @Override168 public boolean isShutdown() {169 throw shutdownNotSupported();170 }171 @Override172 public boolean isTerminated() {173 throw shutdownNotSupported();174 }175 @Override176 public void shutdown() {177 throw shutdownNotSupported();178 }179 @Override180 public List<Runnable> shutdownNow() {181 throw shutdownNotSupported();182 }183 @Override184 public <T> Future<T> submit(Callable<T> callable) {185 return schedule(callable, 0, TimeUnit.SECONDS);186 }187 @Override188 public Future<?> submit(Runnable command) {189 return submit(command, null);190 }191 @Override192 public <T> Future<T> submit(Runnable command, T result) {193 return submit(new CallableRunnableAdapter<T>(command, result));194 }195 private static final class CallableRunnableAdapter<T> implements Callable<T> {196 private final Runnable runnable;197 private final T result;198 CallableRunnableAdapter(Runnable runnable, T result) {199 this.runnable = runnable;200 this.result = result;201 }202 @Override203 public String toString() {204 return runnable.toString();205 }206 @Override207 public T call() {208 runnable.run();209 return result;210 }211 }212 private final class ScheduledTask<T> implements ScheduledFuture<T>, Runnable {213 private final long repeatDelay;214 private final Callable<T> command;215 private boolean isCancelled = false;216 private boolean isDone = false;217 private T futureResult;218 private Exception failure = null;219 ScheduledTask(Callable<T> command) {220 this.repeatDelay = -1;221 this.command = command;222 }223 ScheduledTask(Runnable command) {224 this(-1, command);225 }226 ScheduledTask(long repeatDelay, Runnable command) {227 this.repeatDelay = repeatDelay;228 this.command = new CallableRunnableAdapter<T>(command, null);229 }230 @Override231 public String toString() {232 return command.toString() + " repeatDelay=" + repeatDelay;233 }234 public boolean repeats() {235 return repeatDelay >= 0;236 }237 @Override238 public long getDelay(TimeUnit unit) {239 return unit.convert(Duration.ofNanos(deltaQueue.delay(this)));240 }241 @Override242 public int compareTo(Delayed _object) {243 throw new UnsupportedOperationException("not supported");244 }245 @Override246 public boolean cancel(boolean _mayInterruptIfRunning) {247 isCancelled = true;248 return deltaQueue.remove(this);249 }250 @Override251 public T get() throws ExecutionException {252 if (!isDone) {253 throw blockingOperationsNotSupported();254 }255 if (failure != null) {256 throw new ExecutionException(failure);257 }258 return futureResult;259 }260 @Override261 public T get(long _timeout, TimeUnit _unit) throws InterruptedException, ExecutionException, TimeoutException {262 return get();263 }264 @Override265 public boolean isCancelled() {266 return isCancelled;267 }268 @Override269 public boolean isDone() {270 return isDone;271 }272 @Override273 public void run() {274 try {275 futureResult = command.call();276 } catch (Exception e) {277 failure = e;278 }279 isDone = true;280 }281 }282 private long toTicks(long duration, TimeUnit timeUnit) {283 return TimeUnit.NANOSECONDS.convert(duration, timeUnit);284 }285 private UnsupportedSynchronousOperationException blockingOperationsNotSupported() {286 return new UnsupportedSynchronousOperationException("cannot perform blocking wait on a task scheduled on a "287 + NanosecondPrecisionDeterministicScheduler.class.getName());288 }289 private UnsupportedOperationException shutdownNotSupported() {290 return new UnsupportedOperationException("shutdown not supported");291 }292}...

Full Screen

Full Screen

Source:DeterministicScheduler.java Github

copy

Full Screen

...122 {123 throw blockingOperationsNotSupported();124 }125 public boolean isShutdown() {126 throw shutdownNotSupported();127 }128 public boolean isTerminated() {129 throw shutdownNotSupported();130 }131 public void shutdown() {132 throw shutdownNotSupported();133 }134 public List<Runnable> shutdownNow() {135 throw shutdownNotSupported();136 }137 138 public <T> Future<T> submit(Callable<T> callable) {139 return schedule(callable, 0, TimeUnit.SECONDS);140 }141 142 public Future<?> submit(Runnable command) {143 return submit(command, null);144 }145 146 public <T> Future<T> submit(Runnable command, T result) {147 return submit(new CallableRunnableAdapter<T>(command, result));148 }149 150 private final class CallableRunnableAdapter<T> implements Callable<T> {151 private final Runnable runnable;152 private final T result;153 154 public CallableRunnableAdapter(Runnable runnable, T result) {155 this.runnable = runnable;156 this.result = result;157 }158 159 @Override160 public String toString() {161 return runnable.toString();162 }163 public T call() throws Exception {164 runnable.run();165 return result;166 }167 }168 169 private final class ScheduledTask<T> implements ScheduledFuture<T>, Runnable {170 public final long repeatDelay;171 public final Callable<T> command;172 private boolean isCancelled = false;173 private boolean isDone = false;174 private T futureResult;175 private Exception failure = null;176 177 public ScheduledTask(Callable<T> command) {178 this.repeatDelay = -1;179 this.command = command;180 }181 182 public ScheduledTask(Runnable command) {183 this(-1, command);184 }185 186 public ScheduledTask(long repeatDelay, Runnable command) {187 this.repeatDelay = repeatDelay;188 this.command = new CallableRunnableAdapter<T>(command, null); 189 }190 191 @Override192 public String toString() {193 return command.toString() + " repeatDelay=" + repeatDelay;194 }195 196 public boolean repeats() {197 return repeatDelay >= 0;198 }199 public long getDelay(TimeUnit unit) {200 throw new UnsupportedOperationException("not supported");201 }202 public int compareTo(Delayed o) {203 throw new UnsupportedOperationException("not supported");204 }205 public boolean cancel(boolean mayInterruptIfRunning) {206 isCancelled = true;207 return deltaQueue.remove(this);208 }209 public T get() throws InterruptedException, ExecutionException {210 if (!isDone) {211 throw blockingOperationsNotSupported();212 }213 214 if (failure != null) {215 throw new ExecutionException(failure);216 }217 218 return futureResult;219 }220 public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {221 return get();222 }223 224 public boolean isCancelled() {225 return isCancelled;226 }227 228 public boolean isDone() {229 return isDone;230 }231 public void run() {232 try {233 futureResult = command.call();234 }235 catch (Exception e) {236 failure = e;237 }238 isDone = true;239 }240 }241 private long toTicks(long duration, TimeUnit timeUnit) {242 return TimeUnit.MILLISECONDS.convert(duration, timeUnit);243 }244 245 private UnsupportedSynchronousOperationException blockingOperationsNotSupported() {246 return new UnsupportedSynchronousOperationException("cannot perform blocking wait on a task scheduled on a " + DeterministicScheduler.class.getName());247 }248 249 private UnsupportedOperationException shutdownNotSupported() {250 return new UnsupportedOperationException("shutdown not supported");251 }252}...

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.lib.concurrent.DeterministicScheduler;3import org.jmock.lib.concurrent.Synchroniser;4import org.jmock.lib.legacy.ClassImposteriser;5import org.jmock.Expectations;6import org.jmock.integration.junit4.JUnitRuleMockery;7import org.junit.Rule;8import org.junit.Test;9public class TestClass {10 public JUnitRuleMockery context = new JUnitRuleMockery() {11 {12 setThreadingPolicy(new Synchroniser());13 setImposteriser(ClassImposteriser.INSTANCE);14 }15 };16 public void testMethod() throws Exception {17 final DeterministicScheduler deterministicScheduler = new DeterministicScheduler();18 context.checking(new Expectations() {19 {20 oneOf(deterministicScheduler).shutdownNotSupported();21 }22 });23 deterministicScheduler.shutdownNotSupported();24 }25}261) org.jmock.lib.concurrent.DeterministicScheduler.shutdownNotSupported()27at org.jmock.lib.concurrent.DeterministicScheduler.shutdownNotSupported(DeterministicScheduler.java:157)28at TestClass.testMethod(TestClass.java:23)29at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)30at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)31at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)32at java.lang.reflect.Method.invoke(Method.java:498)33at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)34at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)35at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)36at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)37at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)38at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)39at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)40at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)41at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)42at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.acceptance;2import junit.framework.TestCase;3import org.jmock.Expectations;4import org.jmock.Mockery;5import org.jmock.lib.concurrent.DeterministicScheduler;6import org.jmock.test.unit.lib.concurrent.Synchroniser;7import org.jmock.test.unit.lib.concurrent.SynchroniserTest;8public class DeterministicSchedulerAcceptanceTests extends TestCase {9 private Mockery context = new Mockery();10 private Synchroniser synchroniser = context.mock(Synchroniser.class);11 private DeterministicScheduler scheduler = new DeterministicScheduler();12 public void testShutdownNotSupported() {13 context.checking(new Expectations() {{14 oneOf(synchroniser).doSomething();15 }});16 scheduler.schedule(synchroniser, "doSomething");17 try {18 scheduler.shutdown();19 fail("should not support shutdown");20 }21 catch (UnsupportedOperationException ex) {22 }23 }24}

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.lib.concurrent;2import junit.framework.TestCase;3import org.jmock.MockObjectTestCase;4import org.jmock.lib.concurrent.DeterministicScheduler;5import org.jmock.lib.concurrent.Synchroniser;6public class DeterministicSchedulerTest extends MockObjectTestCase {7 private DeterministicScheduler scheduler = new DeterministicScheduler();8 public void testShutdownNotSupported() {9 try {10 scheduler.shutdown();11 } catch (UnsupportedOperationException e) {12 return;13 }14 fail("Expected UnsupportedOperationException");15 }16}17javac -cp .;jmock.jar;hamcrest.jar 1.java18java -cp .;jmock.jar;hamcrest.jar org.junit.runner.JUnitCore org.jmock.test.unit.lib.concurrent.DeterministicSchedulerTest19java.lang.UnsupportedOperationException: shutdown() not supported20 at org.jmock.lib.concurrent.DeterministicScheduler.shutdown(DeterministicScheduler.java:83)21 at org.jmock.test.unit.lib.concurrent.DeterministicSchedulerTest.testShutdownNotSupported(DeterministicSchedulerTest.java:15)

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1import org.jmock.lib.concurrent.DeterministicScheduler;2public class 1 {3 public static void main(String[] args) {4 DeterministicScheduler scheduler = new DeterministicScheduler();5 scheduler.shutdownNotSupported();6 }7}8 at org.jmock.lib.concurrent.DeterministicScheduler.shutdownNotSupported(DeterministicScheduler.java:135)9 at 1.main(1.java:8)10import org.jmock.lib.concurrent.DeterministicScheduler;11public class 2 {12 public static void main(String[] args) {13 DeterministicScheduler scheduler = new DeterministicScheduler();14 scheduler.shutdownNow();15 }16}17 at org.jmock.lib.concurrent.DeterministicScheduler.shutdownNow(DeterministicScheduler.java:140)18 at 2.main(2.java:8)19import org.jmock.lib.concurrent.DeterministicScheduler;20public class 3 {21 public static void main(String[] args) {22 DeterministicScheduler scheduler = new DeterministicScheduler();23 scheduler.schedule(new Runnable() {24 public void run() {25 System.out.println("Hello World");26 }27 }, 10);28 }29}30import org.jmock.lib.concurrent.DeterministicScheduler;31public class 4 {32 public static void main(String[] args) {33 DeterministicScheduler scheduler = new DeterministicScheduler();34 scheduler.scheduleAtFixedRate(new Runnable() {35 public void run() {36 System.out.println("Hello World");37 }38 }, 10, 10);39 }40}41import org.jmock.lib.concurrent.DeterministicScheduler;42public class 5 {43 public static void main(String[] args) {44 DeterministicScheduler scheduler = new DeterministicScheduler();45 scheduler.scheduleWithFixedDelay(new Runnable() {46 public void run() {

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.lib.concurrent.DeterministicScheduler;3import org.jmock.lib.concurrent.Synchroniser;4import org.jmock.lib.concurrent.DeterministicExecutor;5import org.jmock.lib.concurrent.DeterministicScheduler;6import java.util.concurrent.TimeUnit;7public class 1 {8 public static void main(String[] args) {9 Mockery context = new Mockery();10 DeterministicScheduler scheduler = new DeterministicScheduler();11 context.setThreadingPolicy(new Synchroniser());12 context.checking(new Expectations() {{13 oneOf (mock).shutdownNotSupported();14 will (scheduler.shutdownNotSupported());15 }});16 mock.shutdownNotSupported();17 scheduler.tick(1, TimeUnit.SECONDS);18 }19}20 at org.jmock.lib.concurrent.DeterministicExecutor.tick(DeterministicExecutor.java:93)21 at org.jmock.lib.concurrent.DeterministicScheduler.tick(DeterministicScheduler.java:44)22 at 1.main(1.java:22)23DeterministicScheduler.tick(long,TimeUnit) Method24import org.jmock.Mockery;25import org.jmock.lib.concurrent.DeterministicScheduler;26import org.jmock.lib.concurrent.Synchroniser;27import org.jmock.lib.concurrent.DeterministicExecutor;28import org.jmock.lib.concurrent.DeterministicScheduler;29import java.util.concurrent.TimeUnit;30public class 1 {31 public static void main(String[] args) {32 Mockery context = new Mockery();33 DeterministicScheduler scheduler = new DeterministicScheduler();34 context.setThreadingPolicy(new Synchroniser());35 context.checking(new Expectations() {{36 oneOf (mock).shutdownNotSupported();37 will (scheduler.shutdownNotSupported());38 }});39 mock.shutdownNotSupported();40 scheduler.tick(1, TimeUnit.SECONDS);41 }42}43 at org.jmock.lib.concurrent.DeterministicExecutor.tick(DeterministicExecutor.java:

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.lib.concurrent;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Stub;5import org.jmock.core.constraint.IsAnything;6import org.jmock.core.constraint.IsEqual;7import org.jmock.core.constraint.IsInstanceOf;8import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;9import org.jmock.core.matcher.InvokeOnceMatcher;10import org.jmock.core.stub.ReturnStub;11import org.jmock.lib.concurrent.DeterministicScheduler;12import org.jmock.lib.concurrent.Synchroniser;13import org.jmock.test.unit.lib.concurrent.DeterministicSchedulerTest.TestRunnable;14import java.util.concurrent.Callable;15import java.util.concurrent.ExecutorService;16import java.util.concurrent.Executors;17import java.util.concurrent.Future;18import java.util.concurrent.TimeUnit;19public class ShutdownNotSupportedTestCase extends MockObjectTestCase {20 public void testShutdownNotSupported() throws Exception {21 DeterministicScheduler scheduler = new DeterministicScheduler();22 scheduler.shutdownNotSupported();23 try {24 scheduler.shutdown();25 fail("Expected UnsupportedOperationException");26 } catch (UnsupportedOperationException e) {27 }28 }29}30package org.jmock.lib.concurrent;31import junit.framework.TestCase;32import java.util.concurrent.ExecutorService;33import java.util.concurrent.Executors;34import java.util.concurrent.Future;35import java.util.concurrent.TimeUnit;36public class DeterministicSchedulerTest extends TestCase {37 public static class TestRunnable implements Runnable {38 private boolean hasRun = false;39 public void run() {40 hasRun = true;41 }42 public boolean hasRun() {43 return hasRun;44 }45 }46 public void testRunsScheduledRunnables() throws Exception {47 DeterministicScheduler scheduler = new DeterministicScheduler();48 TestRunnable r1 = new TestRunnable();49 TestRunnable r2 = new TestRunnable();50 scheduler.schedule(r1, 0, TimeUnit.MILLISECONDS);51 scheduler.schedule(r2, 0, TimeUnit.MILLISECONDS);52 assertFalse("r1 should not have run yet", r1.hasRun());53 assertFalse("r2 should not have run yet", r2.hasRun());54 scheduler.tick(0, TimeUnit.MILLISECONDS);55 assertTrue("r1 should have run", r1.hasRun());56 assertTrue("r2 should have run", r2.hasRun());57 }58 public void testSchedulesRunnablesToRunAfterDelay() throws Exception {59 DeterministicScheduler scheduler = new DeterministicScheduler();

Full Screen

Full Screen

shutdownNotSupported

Using AI Code Generation

copy

Full Screen

1import org.jmock.MockObjectTestCase;2import org.jmock.lib.concurrent.DeterministicScheduler;3public class Test1 extends MockObjectTestCase {4 public void test() {5 DeterministicScheduler scheduler = new DeterministicScheduler();6 scheduler.schedule(new Runnable() {7 public void run() {8 System.out.println("Hello World");9 }10 }, 0);11 scheduler.shutdownNotSupported();12 }13}14 at org.jmock.lib.concurrent.DeterministicScheduler.shutdownNotSupported(DeterministicScheduler.java:94)15 at Test1.test(Test1.java:14)16 at Test1.main(Test1.java:9)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful