Hi Hadrian,

I made a mock implementation of the Java serial API specifically for
unit testing: https://github.com/frontlinesms/mock-serial

Do you have any practical advice for developing components, or
resources I should be reading?

Thanks,

Alex


On 26 January 2012 21:22, Hadrian Zbarcea <hzbar...@gmail.com> wrote:
> Alex, smslib is distributed under ALv2, which is great. I didn't check yet
> if it's OSGi ready, we're looking for that too. All our components are now
> OSGi ready. If smslib isn't we'll try to work with them to make it OSGi
> ready or find another solution.
>
> The question I have for you is how to you envision the unit testing for this
> component? Is there a way to have a mock service provider? We obviously
> cannot afford using a real service for the unit tests.
>
> Cheers,
> Hadrian
>
>
> On 01/26/2012 09:21 AM, Alex Anderson wrote:
>>
>> I'm working on a Camel component for SMSLib (http://www.smslib.org).
>> This is a Java library for communicating with mobile phones and modems
>> via a serial connection to send and receive SMS messages using the
>> Hayes (AT) command set.
>>
>> I have a working prototype - you can see the source at
>> https://github.com/frontlinesms/camel-smslib
>>
>> I have some general worries regards best-practice for designing the
>> Endpoint, Consumer and Producer for this component.  I've not come
>> across comprehensive documentation for implementing Endpoints etc.,
>> and it's hard to know which other components would have a similar
>> model to mine and therefore would be worth delving into the source of.
>>
>>
>> Notes on serial devices
>> -----------------------
>> * before starting to send or receive messages through a device it must
>> be initialised
>> * initialisation can fail
>>
>>
>> Endpoint
>> --------
>> Each Endpoint will refer to a serial port, with corresponding URIs, e.g.:
>> * Windows: smslib:COM1
>> * Linux: smslib:/dev/tty01
>>
>> When Endpoints are initially created, settings for the port (e.g. baud
>> rate) are passed to it.  Later we may want to create endpoints for the
>> same port with different settings, but only if the original endpoint
>> is no longer in use.
>>
>>
>> Consumer
>> --------
>> There should be a maximum of 1 consumer per endpoint.  The serial port
>> must be polled to check for incoming SMS.  Rather than storing the SMS
>> within the Smslib service, I would like to pass them immediately
>> upstream to the Consumer's Processor.
>>
>>
>> Producer
>> --------
>> For my usage, I would like a single Producer per endpoint.  This is
>> primarily because when there are no active producers or consumers for
>> an endpoint, the serial connection can be closed to allow its use by
>> other programs.  It may be reasonable for other uses to have multiple
>> Producers for the same endpoint.
>>
>>
>> Current status
>> --------------
>> The endpoint has a Thread (implemented in a class SmslibService) which
>> controls the receiving from the serial connection - every 30 seconds
>> the thread wakes and checks the modem for new incoming messages.  This
>> SmslibService keeps a reference to a Producer and a Consumer, and
>> should shut down the serial connection when both Consumer and Producer
>> are stopped.
>>
>> Trying to create more than one Producer or Consumer for an Endpoint
>> will cause an Exception to be thrown.
>>
>> This causes problems when the settings used to create an endpoint
>> initially are bad - there will be an Exception thrown in
>> SmslibProducer.doStart()
>>
>>
>> My Questions
>> ------------
>> * are there any good resources for writing Endpoints that I should be
>> reading?
>> * does anyone know of any similarly-modelled components whose source
>> might provide guidance?
>> * are there any patterns or base classes that I should obviously be
>> using for my Component, Endpoint, Consumer or Producer
>> implementations?
>> * is there anyone else interested in this component who could cast an
>> eye over the code?
>
>
> --
> Hadrian Zbarcea
> Principal Software Architect
> Talend, Inc
> http://coders.talend.com/
> http://camelbot.blogspot.com/

Reply via email to