GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to test Network mode? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to test Network mode?" Watch "How to test Network mode?" New topic
Author

How to test Network mode?

Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Everybody:
I am ok with local mode. It is working fine. How to test network mode in a single windowME machine? I mean how do I create multiple clients and concurrent access. I have designed a GUI that should work for both network and local mode. I am lost here. Do I have to write separate program to test network mode? I am not sure. How do I know lock unlock methods are propely working? Any response in this regard highly appriciated.
Thank you -Bal
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Just start the server and two sessions of the client on the same machine. If you're using RMI or sockets just use the local machines url ort. RMI on the same machine doesn't even need a url. You don't need to have a network. It really is quite simple.
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello:
I am using RMI. "two sessions of the client" means two GUI runnning at the same time right! I will test and let you know how it goes.
Thanks for response. -Bal
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello There:
I opened two clients. Process booking for each clients in my sigle machine.

Internal process goes so fast I can not see waiting state. I want to see client A locks the record, if client B attemts same record got to wait right! So, client B is waiting. Client A unlocks client B recieves the lock.
How to pass at least 10 clients attempting to modify same record, so I will know who got lock and who is waiting? I want to access the book method at same time for 10 clients. How can I do this?
Thanks in advance for any response. -Bal
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Bal
You can just disable the unlock method, from where you call it - recompile and try again.
/Ren�


Regards, Rene Larsen
Dropbox Invite
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Bal
You can also implement a delay - Thread.sleep(...) - in the begining of your unlock method.
/Ren�
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Ren�:
Thank you for responses. I tried both test as you indicated.
Disabling unlock method
I opened two clients. I mean two GUI. I processed for flight booking. Following was the result. By the way, after I clicked button on second GUI. GUI changed into gray color and lost tables, buttons and lables. But good news you know what! I saw "Waiting to be locked Record #: 20" message on DOS window.

Delaying Process
I wrote following code at the begining of unlock method.

I am glad to let you know that I see "Waiting to be locked Record #: 7" message. But it is my surprise that why I did not see "I am delaying process for TEN seconds" message which is at the begining of unlock method. This time I opened five GUI (clients) and wanted to test. I tried to change same record. I think I should have seen four message "Waiting to be locked Record #", right!
Why I had only 3. I do not know.
I am using RMI. There is no gurantee that each client get separate thread. Does this small test show there will not be any deadlock? How can I be sure that there will not be any problem in lock and unlock method? I mean, will they run smoothly without any glitch? Is there any other way to be sure?
Your views in this regards highly appriciated. Thanks -Bal
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Bal
If you want to see "I am delaying process for TEN seconds" then you should change your code to:

The way I did my testing was to disable the unlock method, try to book some seats from a number of clients, shutdown or just disconnect one client at a time, starting with the first, from RMI server.
On the server I have used the interface to clean up (to unlock the client).
/Ren�
[ January 27, 2002: Message edited by: Rene Larsen ]
[ January 27, 2002: Message edited by: Rene Larsen ]
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Ren�:
It was my bad I thought I had "I am delaying process for TEN seconds" message in try block but it was not. I see why I did not see it. Could you please explain me more about Unreferenced how does it work? and how did you use it?
Thanks in advance. -Bal
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Bal
I implemented my RMI server using the Abstract Factory Pattern - see Applying the Factory Pattern to RMI.
Doing so I get one unik proxy object assigned to one client.
The Unreferenced interface is implemented in the proxy object, and it receive notification when there are no more clients that reference that remote object.
The interface has only one method public void unreferenced(). This method is called by the RMI runtime sometime after the runtime determines that the reference list, the list of clients referencing the remote object, becomes empty.
In the method unreferenced() I have a loop running through a local ArrayList of records not unlocked.
Hope this helps
/Ren�
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Ren�:
Hope this helps
Of course, it does. Thanks for your responses. I think I should not worry too much about lock unlock. I believe they are straighthened out. I see message Locked record # and Unlocked record # while program is running. In addtion to this, I liked your idea delaying the process. It gives a picture what is going on.
I got a question for you. I did not change any synchronized modifier from the Data class. It is almost same in the RemoteData class too. I just added synchronized block inside lock and unlock methos using Hashset object. I am curious, did you change any synchronized modifier in supplied class. Do you think it is'nt gonna hurt? OR may be do I have to delete any synchronized?
Thanks^10. -Bal
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Bal
I did not remove/change any method signatur.
Inside lock and unlock methods, I only used a synchronized block on the ArrayList that holds the locks.
/Ren�
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
What a match! Thank you again. Have a great day! -Bal
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to test Network mode?