aspose file tools*
The moose likes Testing and the fly likes testing a client/server configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "testing a client/server configuration" Watch "testing a client/server configuration" New topic
Author

testing a client/server configuration

Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
What is the best way to test a client/server configuration?

What I wish is the tool which can help me do these steps:
1. Compile and start my server code
2. Compile and start my client code
3. After client code is finished execution stop server.
Are there any tools/frameworks which can help or I should code everything manually?


Free open source onscreen <a href="http://jslope.com/ruler.htm" target="_blank" rel="nofollow">Ruler</a>
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You should be able to do something like what you're describing with an Ant build script.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
Originally posted by Lasse Koskela:
You should be able to do something like what you're describing with an Ant build script.


Thank You. By the way, is there somewhere an example of how to start and stop a server from ant?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Sergio Baca:
Thank You. By the way, is there somewhere an example of how to start and stop a server from ant?

Depending on your particular server product, you could use the <exec/> task to call the server's regular startup scripts or you could check out whether Cargo's Ant tasks support your server.
Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
Originally posted by Lasse Koskela:

Depending on your particular server product, you could use the <exec/> task to call the server's regular startup scripts or you could check out whether Cargo's Ant tasks support your server.


But if I need to do a test for my own server and my own client with my custom protocol? How ant will know that my test was finished so it will stop my server? Is there other way to do launch it from Java except launching it as exec? (may be making custom separate memory for each application somehow?, because some singletons on server and on client are the same and can have different values it's why I think that I can't launch them both in one JVM)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Sergio Baca:
How ant will know that my test was finished so it will stop my server?

If you're running your test with Ant, then it's a non-issue because Ant runs the targets/tasks serially and not in parallel. In other words, if you've got a build script as follows...

...then the server is shut down only after the test target is finished, i.e. your tests have finished running.

Originally posted by Sergio Baca:
Is there other way to do launch it from Java except launching it as exec?

Well, if you want the server to run in a JVM different from Ant's, then you'll have to do the "exec" somehow anyway. You could use the <exec/> task in your Ant script or you could do similar Process.exec() stuff yourself in Java code (or, call Ant's Execute task in Java).
Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
Originally posted by Lasse Koskela:
[CODE]
Well, if you want the server to run in a JVM different from Ant's, then you'll have to do the "exec" somehow anyway. You could use the <exec/> task in your Ant script or you could do similar Process.exec() stuff yourself in Java code (or, call Ant's Execute task in Java).

Thank you very much for helping me.
But I whish to run in the same JVM but in different namespaces and not necessary by ant, I need my program to run and create 2 namespaces one for server and one for client. Are there any examples of how to do it?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Sergio Baca:
But I whish to run in the same JVM but in different namespaces and not necessary by ant, I need my program to run and create 2 namespaces one for server and one for client. Are there any examples of how to do it?
Um, what do you mean by a namespace?
Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
Originally posted by Lasse Koskela:
Um, what do you mean by a namespace?


I'm sorry that I wasn't very clear. I think that I can't use Ant because Ant will not know when client has finished execution. So I thought to use plain Java and 2 separate threads for starting server and client, but because on server and on client I have some singleton classes which are the same but have different values. So I thought if I'll start client and server with different class loaders they will be in different namespaces, so I'll be able to have 2 singletons with the same name. Is it possible?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Sergio Baca:
I'm sorry that I wasn't very clear. I think that I can't use Ant because Ant will not know when client has finished execution. So I thought to use plain Java and 2 separate threads for starting server and client, but because on server and on client I have some singleton classes which are the same but have different values. So I thought if I'll start client and server with different class loaders they will be in different namespaces, so I'll be able to have 2 singletons with the same name. Is it possible?


Ok. First of all, I think it should be possible to use different classloaders like you said, although that might create more problems in the long run than it's solving.

I would personally first try to find a way to replace the Singleton in your design with JustCreateOne. If that doesn't feel good, then I'd look into launching two JVMs with an Ant script without any custom classloaders using dependencies like I posted before. Only as a last resort, I'd consider doing something funky with classloaders. That's just me, of course. Your preferences might be different.
Sergio Baca
Greenhorn

Joined: Sep 30, 2001
Posts: 21
Originally posted by Lasse Koskela:

Ok. First of all, I think it should be possible to use different classloaders like you said, although that might create more problems in the long run than it's solving.

Can you please explain why it can create more problems?

I would personally first try to find a way to replace the Singleton in your design with JustCreateOne.

Thank you for an interesting link, althought I don't agree with everything there it's good to know valid alternative opinions.

If that doesn't feel good, then I'd look into launching two JVMs with an Ant script without any custom classloaders using dependencies like I posted before.
Only as a last resort, I'd consider doing something funky with classloaders. That's just me, of course. Your preferences might be different.

At least classloaders sound interesting :-)
[ January 03, 2006: Message edited by: Sergio Baca ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Regarding ClassLoaders causing problems, it's a matter of debugging or "figuring out what the heck is happening here" becoming more difficult when you're not sure which ClassLoader has loaded a given class and which classes that particular ClassLoader sees, plus, since you've got a custom ClassLoader, it's probably doing something more than just "sandboxing" parts of the system from seeing each other.

Yes, it would probably be interesting. Still, I wouldn't like to hear a developer going "this pacemaker stuff is interesting!" while writing software for the pacemaker the surgeon is just about to stitch next to my heart...
 
 
subject: testing a client/server configuration