Hi Steve,

Thank you very much for your informative reply.  I am following your suggestion 
and studying testharness to see how I can use it for what I am trying to do.


As for the ant tasks, my problem with <sf-run> is that although the description 
suggests that the task waits for the application to terminate, in reality it 
only waits for deployment/start, and then shuts down the daemon. Therefore, if 
the application lifecycle extends beyond sfStart (as in the 'counter' example, 
for instance), then <sf-run> terminates it prematurely.

<sf-functionaltest> offers more flexibility, in that you can insert sleep or 
some kind of waitFor, in order to ensure that the application runs to 
completion before teardown. However, except for some special cases (such as the 
webapps that you mentioned), there doesn't seem to be a straightforward way to 
do that. If you just put <sf-deploy> between the <test> tags, the result will 
be as in <sf-run>: the task may end before the application terminates on its 
own.

Before I received your reply, I worked around this problem by writing a custom 
Ant task that loops <sf-ping> until it throws, indicating that the application 
has terminated. Placing this task in the <test> block after <sf-deploy> delays 
teardown until application termination. This is a rather cumbersome solution 
though.

By the way, you might be interested to know that currently the sf-tasks jar is 
not added to distribution packages. I had to build SmartFrog from source in 
order to get it.


Finally, I have a different but related question. I would like to use a 
SmartFrog script to run several OS executable programs, one after another. I 
could use ExecuteProgram as the base component for each program, but how would 
I chain them? Sequence does something like this, except that it does not wait 
for sub-components to terminate and launches the next component as soon as the 
current component returns from sfStart. I am thinking of either extending (or 
more likely, rewriting) ExecuteProgram (RunShellImpl), or extending/rewriting 
Sequence or Compound. Perhaps there is a better way to do this?


Thank you for your help,
Dmitry


> -----Original Message-----
> From: Steve Loughran [mailto:[email protected]]
> Sent: Monday, September 20, 2010 3:20 PM
> To: Dmitry Epstein; Peter Gagarinov
> Cc: [email protected]; [email protected]
> Subject: re: [Smartfrog-users] Running applications using Ant tasks
> 
> 
> Hi.
> 
> sorry to only just get back to you, -my mail from this list goes to a
> machine that I only check @work, and I've been working from home the
> last few days.
> 
> The best way to programatically run an SF application from within JUnit
> 3.8.x is to use our testharness classes (in the sf-testharness JAR)
> 
> http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/testha
> rness/src/org/smartfrog/test/DeployingTestBase.java?revision=8404&view=
> markup
> 
> There's also a subclass, PortCheckingTestBase, which can be made to
> check for ports being open before/after test runs. This is handy for
> blocking until things are up and running.
> 
> http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/testha
> rness/src/org/smartfrog/test/PortCheckingTestBase.java?revision=8404&vi
> ew=markup
> 
> The code in DeployingTestBase and it's parent, SmartFrogTestBase,
> should
> show you how to create an SF application in Java code, which is
> generally fairly straightforward: you load up a configuration, then
> deploy it to the target machine, and look for errors or an RMI-
> remotable
> interface.
> http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/testha
> rness/src/org/smartfrog/test/SmartFrogTestBase.java?revision=8404&view=
> markup
> 
> In the DeployingTestBase we try and do something a bit cleverer in that
> it will deploy components which implement the TestBlock interface,
> these
>   -provide more lifecycle events
>   -let you know if their child started/finished/failed, etc.
> 
> With components that implement this interface (TestBlockImpl and the
> more sophisticated TestCompound/TestCompoundImpl), we can just use
> JUnit
> as a launcher for the tests, get the traces back when they fail and
> generally push most of the test work -starting something, running
> tests-
> into the app. For the problem we often have -functional testing of a
> SmartFrog component- this is good, though the limitations of Ant's XML
> to HTML Junit process do show (there's no way to get text descriptions
> of tests into the HTML, or show which tests were skipped).
> 
> For the the other problem we often have -deploying some webapp and then
> testing against it, it's simpler to
>   -use <sf-functionaltest> to start SF in one process, junit in the
> other
>   -have your Junit tests block until the webapp port is live, or even
> better, until some status servlet is returning 200 on every query.
> 
> 
> If you are having problems with <sf-run>, I'll file that as a bugrep
> and
> take a look at it; think of some way to see what's going on in one of
> our tests which use Ant's testing framework to run ant tasks from under
> JUnit.
> 
> The <sf-functional> test behaviour you saw was "works as planned"; the
> test runner task blocked until the condition was met, then the junit
> tests would be run (everything in the <test> clause), then the shutdown
> process initiated. If you don't have anything in the <test> sequence,
> the daemon and it's application will be killed as soon as the empty Ant
> sequence finishes. If you inserted some work in there (even a <sleep>
> task), things would be different.
> 
> Finally, you should know that I've been working on cutting a new SF
> release this month, first with an internal alpha release that seems to
> be working OK. then with a new planned release which has some more
> changes. The main work is creating some new CentOS 5.5 + Java 6 JVMs,
> one for cutting releases, another for testing RPM installation.
> 
> http://jira.smartfrog.org/jira/browse/SFOS-1513
> 
> 
> Hope this helps,
> 
> -steve
> 
> --------
> 
> 
> Date: Thu, 16 Sep 2010 20:54:07 +0400
> From: <[email protected]>
> Subject: [Smartfrog-users] Running applications using Ant tasks
> To: <[email protected]>
> Cc: [email protected]
> Message-ID:
>       <[email protected].
> com>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hello,
> 
> I am trying to implement execution of a SmartFrog application within a
> JUnit test. Successful termination of the application is a necessary
> condition for the test success.
> 
> The <sf-run> Ant task sounds like what I need. The description says:
> "Run an application by deploying it locally; only return from ant after
> it has finished." In practice, I found that the application is forcibly
> terminated immediately after it is started. For example, the following
> SmartFrog  example is supposed to execute 4 counter steps before
> terminating:
> 
>                                  <sf-run classpathref="run.classpath">
>                                                  <application name="
> Counter " descriptor="org/smartfrog/examples/counter/example.sf"/>
>                                  </sf-run>
> 
> Here is what actually happens:
> 
>     [sf-run]
>     [sf-run] SmartFrog 3.17.014 (2009-07-27 16:11:39 BST)
>     [sf-run] (C) Copyright 1998-2009 Hewlett-Packard Development
> Company, LP
>     [sf-run]
>     [sf-run] 2010/09/16 20:38:28:937 MSD [WARN ][main] SFCORE_LOG -
> SmartFrog security is NOT active
>     [sf-run] 2010/09/16 20:38:30:343 MSD [INFO ][main] HOST
> test289.alliedtesting.com:sfRunProcess:Counter - Starting with msg-step
>     [sf-run]  - Successfully deployed: 'HOST
> test289.alliedtesting.com:sfRunProcess:Counter',
> [/org/smartfrog/examples/counter/example.sf]
>     [sf-run]
>     [sf-run] COUNTER: step 1
> 
> As you can see, the task doesn't wait for the application to  terminate
> on its own. I tried playing with various attributes, but the result was
> always the same, as far as premature termination is concerned.
> 
> 
> Another Ant task that I have tried to use is <sf-functionaltest>. Here
> is the same example as above using a simple implementation of this
> task:
> 
>                                  <sf-functionaltest shutdowntime="10"
> testtimeout="600">
>                                                  <application>
> 
> <sf-startdaemon classpathref="run.classpath"/>
>                                                  </application>
>                                                  <probe>
> 
> <socket
> port="${smartfrog.daemon.port}" server="localhost"/>
>                                                  </probe>
>                                                  <teardown>
> 
> <sf-stopdaemon failonerror="false"/>
>                                                  </teardown>
>                                                  <test>
> 
> <sf-deploy classpathref="run.classpath">
> 
>           <application
> 
>                           name="Counter"
> 
> 
> descriptor="/org/smartfrog/examples/counter/example.sf"
> 
>           />
> 
> </sf-deploy>
>                                                  </test>
>                                  </sf-functionaltest>
> 
> And here is what happens:
> 
> [sf-startdaemon]
> [sf-startdaemon] SmartFrog 3.17.014 (2009-07-27 16:11:39 BST)
> [sf-startdaemon] (C) Copyright 1998-2009 Hewlett-Packard Development
> Company, LP
> 
> [sf-startdaemon]
> [sf-startdaemon] 2010/09/16 20:44:39:554 MSD [WARN ][main] SFCORE_LOG -
> SmartFrog security is NOT active
> [sf-startdaemon] SmartFrog ready... [rootProcess:3800] Thu Sep 16
> 20:44:41 MSD 2010
> [sf-deploy]
> [sf-deploy] SmartFrog 3.17.014 (2009-07-27 16:11:39 BST)
> [sf-deploy] (C) Copyright 1998-2009 Hewlett-Packard Development
> Company, LP
> [sf-deploy]
> [sf-deploy] 2010/09/16 20:44:42:460 MSD [WARN ][main] SFCORE_LOG -
> SmartFrog security is NOT active
> [sf-startdaemon] 2010/09/16 20:44:44:288 MSD [INFO ][RMI TCP
> Connection(3)-192.168.134.33] HOST
> test289.alliedtesting.com:rootProcess:Counter - Starting with msg-step
> [sf-deploy]  - Successfully deployed: 'HOST
> test289.alliedtesting.com:rootProcess:Counter',
> [/org/smartfrog/examples/counter/example.sf],  host:localhost
> [sf-deploy]
> [sf-startdaemon] COUNTER: step 1
> [sf-startdaemon] COUNTER: step 2
> [sf-stopdaemon]
> [sf-stopdaemon] SmartFrog 3.17.014 (2009-07-27 16:11:39 BST)
> [sf-stopdaemon] (C) Copyright 1998-2009 Hewlett-Packard Development
> Company, LP
> [sf-stopdaemon]
> [sf-stopdaemon] 2010/09/16 20:44:45:601 MSD [WARN ][main] SFCORE_LOG -
> SmartFrog security is NOT active
> [sf-startdaemon] COUNTER: step 3
> [sf-startdaemon] 2010/09/16 20:44:46:882 MSD [INFO ][RMI TCP
> Connection(5)-192.168.134.33] HOST
> test289.alliedtesting.com:rootProcess:Counter -  Terminating for
> reason:
> Termination Record: HOST test289.alliedtesting.com:rootProcess,
> type:normal,  description: External Management Action
> [sf-startdaemon] 2010/09/16 20:44:46:882 MSD [ERROR][Counter] HOST
> test289.alliedtesting.com:rootProcess:Counter -
> <java.lang.InterruptedException: sleep interrupted>
> [sf-startdaemon]
> [sf-startdaemon] SmartFrog [rootProcess] dead  Thu Sep 16 20:44:46 MSD
> 2010
> [sf-stopdaemon] SmartFrog daemon terminated
> [sf-stopdaemon]  - Successfully terminated: 'null',  host:localhost
> [sf-stopdaemon]
> 
> In this case, too, the application was terminated prematurely.
> 
> 
> Am I doing something wrong?
> 
> Is there a better way to do what I want (i.e. programmatically
> executing
> a SmartFrog application, preferably using an Ant or Java interface, and
> getting back the termination status)?
> 
> Thank you,
> Dmitry

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Smartfrog-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/smartfrog-users

Reply via email to