Author Login
Post Reply
I would like a suggestion/feedback for getting around the issue of getting an
UnsupportedSynchronousOperationException when using DeterministicScheduler.
Is there a workaround? Or a suggestion of how I can proceed?
Also, I am kind of confused about what the following means: "The scheduler does
not implement the synchronous methods of the SchedulerExecutorService interface.
If a test attempts to do a blocking wait for a scheduled task to complete". Can
someone help me understand this.
I am trying to do some T-D-D using JMock in creating tests/class that support
asynchronous code. My design uses the Producer-Consumer pattern and my story
requirements are that my processes in my consumer class run on their own
"worker" thread.
What I am really trying to do is use DeterministicScheduler, simply for it's
implementation of ExecutorService, which will can return to me a Future<T> that
my class can process and can do something with upon a
DeterministicScheduler.submit(Callable<T>).
I have been relying heavily on the CookBook pages
(http://www.jmock.org/threading-scheduler.html,
http://www.jmock.org/threads.html).
So, I have been using DeterministicScheduler as an ExecutorService in my test
class:
public someTestClass {
private DeterministicScheduler _executorService = new
DeterministicScheduler();
private OperationConsumer _operationConsumer = new OperationConsumer();
private BlockingQueue<PackageResourceOperation> _mockOperationsQueue;
....
}
And in my testMethod, I am doing soemthing like:
Expectations expectations = new Expectations() {
{
oneOf(_mockOperationsQueue).take();
will(returnValue(mockResourceOperation));
inSequence(readSequence);
oneOf(_mockConsumerReadResourceTask).call();
will(returnValue(mockResourceCollection));
inSequence(readSequence);
}};
_mockContext.checking(expectations);
_operationConsumer.start(_executorService, _mockOperationsQueue);
My implementation Code for OperationConsumer does something like:
void doSomeCoolOperations() {
//note: params in ConsumerReadResourceTask are really populated by member
content in resourceOperation
resourceOperation = _operationsQueue.take();
if (_consumerReadResourcesTask == null)
_consumerReadResourcesTask = new ConsumerReadResourceTask(
null, false, null, null, false);
Future<Collection<Resource>> future =
_worker.submit(_consumerReadResourcesTask);
}
Everything was working smooth & dandy...Until, I added in the following code to
doSomeCoolOperations():
try {
Collection<Resource> resources = future.get();
} catch (InterruptedException e) {
logger.warn("This Read Task was interupted " + e);
} catch (ExecutionException e) {
throw new ResourceServiceException(e);
}
At that point my test started returning the
UnsupportedSynchronousOperationException:
org.jmock.lib.concurrent.UnsupportedSynchronousOperationException: cannot
perform blocking wait on a task scheduled on a
org.jmock.lib.concurrent.DeterministicScheduler
at
org.jmock.lib.concurrent.DeterministicScheduler.blockingOperationsNotSupported(D
eterministicScheduler.java:265)
at
org.jmock.lib.concurrent.DeterministicScheduler.access$100(DeterministicSchedule
r.java:28)
at
org.jmock.lib.concurrent.DeterministicScheduler$ScheduledTask.get(DeterministicS
cheduler.java:227)
at
com.rockwellautomation.resources.server.packaging.OperationConsumer.readAndRetur
nResources(OperationConsumer.java:86)
at
com.rockwellautomation.resources.server.packaging.OperationConsumer.chooseAndDoO
peration(OperationConsumer.java:72)
at
com.rockwellautomation.resources.server.packaging.OperationConsumer.start(Operat
ionConsumer.java:54)
at
com.rockwellautomation.resources.server.packaging.OperationConsumerTest.itShould
PollTheQueueAndExecuteReadResourceRequest(OperationConsumerTest.java:146)
This I assume is where I am trying to do a blocking wait for my task to
complete.
Any suggestions?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email