We were thinking about having all sorts of utilities but yet no time to
think about not implement them.About
your case this can be very simple implemented by using ServiceTracker
waitForService, so a special implementation does not make sense in my view.

HTH,
Alin

On Tue, Jul 21, 2009 at 8:44 PM, <pe...@risko.hu> wrote:

>
> Hello All,
>
>  I would like to test a SpringDM bundle from PaxExam. But I got always null
> when tried to retrieve the service reference. Finally I found that probably
> it's null because I try to grab it too early.
>
>  So I would like to know how shall I wait in the testcase for the service
> reference to be available?
>
>  I created this test method:
>
>    @Test
>    public void testSpringCalc() throws Exception {
>        System.out.println("waiting for enter a key...");
>        System.in.read();
>        boolean found = false;
>        ServiceReference[] sra =
>                bundleContext.getAllServiceReferences(null, null);
>                for(ServiceReference sr : sra) {
>                        String symName = sr.getBundle().getSymbolicName();
>                        if("org.foo.springCalc".equals(symName)) {
>
>  System.out.println("**********************");
>                                System.out.println("symname: " + symName);
>                                System.out.println("srefer: " + sr);
>
>  System.out.println("**********************");
>                                found = true;
>                        }
>                }
>                assertTrue(found);
>    }
>
>  If I comment out the "System.in.read()" line then the testcase fails, if I
> leave it and wait some time before pressing a key then it succeeds.
>
>  I guess that this is because the service reference is not available at the
> time the test method runs.
>
>  In SpringDM's AbstractConfigurableBundleCreatorTests there was a method
> "waitOnContextCreation("org.foo.springCalc");" for this.
>
>  How shall I do it in PaxExam?
>
>  Thank you, Peter
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> _______________________________________________
> general mailing list
> general@lists.ops4j.org
> http://lists.ops4j.org/mailman/listinfo/general
>



-- 
Alin Dreghiciu
Software Developer - Looking for new projects!
My profile: http://www.linkedin.com/in/alindreghiciu
My blog: http://adreghiciu.blogspot.com
http://www.ops4j.org - New Energy for OSS Communities - Open Participation
Software.
http://www.qi4j.org - New Energy for Java - Domain Driven Development.
_______________________________________________
general mailing list
general@lists.ops4j.org
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to