Synchronous publishing on memory channel - is it possible

45 views
Skip to first unread message

Abraham Menacherry

unread,
Aug 8, 2011, 2:42:23 AM8/8/11
to jetlang-dev
I am using jetlang for testing out some webservices we have. Some of
the webservice clients I am testing, expect synchronous replies.

Mostly this is my workflow
1) Spring Webservice endpoint gets the message from client.
2) Message is published to memory channel
3) The integration test case with the appropriate filter and
subscription to memory channel gets this message... rest of test case
continues.

The publishing is async and it is fine for most cases but few require
them to be synchronos, is there a way to achieve synchronous
publish(on the same thread as the webservice end point?)

Thanks,
Abraham.

Mike Roberts

unread,
Aug 8, 2011, 8:24:58 AM8/8/11
to jetla...@googlegroups.com
Hi Abraham,

Sounds like what you need is FiberStub - http://code.google.com/p/jetlang/source/browse/trunk/src/main/java/org/jetlang/fibers/FiberStub.java - I use this extensively for my integration / functional testing. With FiberStub you call executeAllPending / executeAllScheduled to trigger events in the queue. A little trick is you may need to call these several times if a particular behavior involves more than one Jetlang event.

Mike

> --
> You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
> To post to this group, send email to jetla...@googlegroups.com.
> To unsubscribe from this group, send email to jetlang-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jetlang-dev?hl=en.
>

Abraham Menacherry

unread,
Aug 8, 2011, 10:32:28 AM8/8/11
to jetlang-dev
Mike,

This is what I was looking for, thank you.

I also stumbed upon this implementation SynchronousDisposingExecutor,
which can be used in place of fiber while subscribing to a channel to
get synchronous execution.

Thanks,
Abraham.

On Aug 8, 5:24 pm, Mike Roberts <mikerobe...@me.com> wrote:
> Hi Abraham,
>
> Sounds like what you need is FiberStub -http://code.google.com/p/jetlang/source/browse/trunk/src/main/java/or...- I use this extensively for my integration / functional testing. With FiberStub you call executeAllPending / executeAllScheduled to trigger events in the queue. A little trick is you may need to call these several times if a particular behavior involves more than one Jetlang event.
>
> Mike
>
> On Aug 8, 2011, at 2:42 AM, Abraham Menacherry wrote:
>
>
>
> > I am using jetlang for testing out some webservices we have. Some of
> > the webservice clients I am testing, expect synchronous replies.
>
> > Mostly this is my workflow
> > 1) Spring Webservice endpoint gets the message from client.
> > 2) Message is published to memory channel
> > 3) The integration test case with the appropriate filter and
> > subscription to memory channel gets this message... rest of test case
> > continues.
>
> > The publishing is async and it is fine for most cases but few require
> > them to be synchronos, is there a way to achieve synchronous
> > publish(on the same thread as the webservice end point?)
>
> > Thanks,
> > Abraham.
>
> > --
> > You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
> > To post to this group, send email to jetla...@googlegroups.com.
> > To unsubscribe from this group, send email to jetlang-dev...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/jetlang-dev?hl=en.- Hide quoted text -
>
> - Show quoted text -

Abraham Menacherry

unread,
Aug 8, 2011, 10:46:16 AM8/8/11
to jetlang-dev
I ran a test with FiberStub, and for the synchronous case it does not
suit me so well. I need the callback to be run on the incoming
webservice request thread, while the fiber is in my main test case
thread and hence when I call the executeAllPending method it becomes
"async".

But still, a good to know feature for async cases.

On Aug 8, 7:32 pm, Abraham Menacherry <abrahammenache...@gmail.com>
wrote:
> Mike,
>
> This is what I was looking for, thank you.
>
> I also stumbed upon this implementation SynchronousDisposingExecutor,
> which can be used in place of fiber while subscribing to a channel to
> get synchronous execution.
>
> Thanks,
> Abraham.
>
> On Aug 8, 5:24 pm, Mike Roberts <mikerobe...@me.com> wrote:
>
>
>
> > Hi Abraham,
>
> > Sounds like what you need is FiberStub -http://code.google.com/p/jetlang/source/browse/trunk/src/main/java/or...I use this extensively for my integration / functional testing. With FiberStub you call executeAllPending / executeAllScheduled to trigger events in the queue. A little trick is you may need to call these several times if a particular behavior involves more than one Jetlang event.
>
> > Mike
>
> > On Aug 8, 2011, at 2:42 AM, Abraham Menacherry wrote:
>
> > > I am using jetlang for testing out some webservices we have. Some of
> > > the webservice clients I am testing, expect synchronous replies.
>
> > > Mostly this is my workflow
> > > 1) Spring Webservice endpoint gets the message from client.
> > > 2) Message is published to memory channel
> > > 3) The integration test case with the appropriate filter and
> > > subscription to memory channel gets this message... rest of test case
> > > continues.
>
> > > The publishing is async and it is fine for most cases but few require
> > > them to be synchronos, is there a way to achieve synchronous
> > > publish(on the same thread as the webservice end point?)
>
> > > Thanks,
> > > Abraham.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
> > > To post to this group, send email to jetla...@googlegroups.com.
> > > To unsubscribe from this group, send email to jetlang-dev...@googlegroups.com.
> > > For more options, visit this group athttp://groups.google.com/group/jetlang-dev?hl=en.-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

Mike Rettig

unread,
Aug 8, 2011, 7:25:22 PM8/8/11
to jetla...@googlegroups.com
The easiest solution is to create a channel and pass a blocking queue
across the channel. The FiberStub is intended to be used for
synchronous test cases that are single threaded and need to be
deterministic.

http://code.google.com/p/jetlang/source/browse/trunk/src/test/java/org/jetlang/examples/BasicExamples.java


@Test
public void requestReplyWithBlockingQueue() throws InterruptedException {
Fiber fiber = new ThreadFiber();
fiber.start();
BlockingQueue<String> replyQueue = new ArrayBlockingQueue<String>(1);
MemoryChannel<BlockingQueue<String>> channel = new
MemoryChannel<BlockingQueue<String>>();
Callback<BlockingQueue<String>> replyCb = new
Callback<BlockingQueue<String>>() {
public void onMessage(BlockingQueue<String> message) {
try {
message.put("hello");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
};
channel.subscribe(fiber, replyCb);
channel.publish(replyQueue);

Assert.assertEquals("hello", replyQueue.poll(10, TimeUnit.SECONDS));
fiber.dispose();

Reply all
Reply to author
Forward
0 new messages