This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to test locking/unlocking  RSS feed

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on URLyBird 1.3.1 using NetBeans and I'm trying to test whether locking/unlocking is working. I'm comfortable that the code is doing what I think I want it to do. However, I don't really know whether it will work in practice.

I have followed these steps:
  • --- Start up network server
  • --- Place a break point in the method implementing lock(recNo) just at the lockedRecords.notifyAll(); statement, that is, just after placing the entry (key is instance of RoomFileAccess file that implements all of the methods in the Data class and its value is the record number being locked)for the locked record into the container (a WeakHashMap).
  • --- Start network client 1 in the debug mode in NetBeans
  • --- Start network client 2 in the debug mode in Netbeans
  • --- Book a room with network client 1 so thread stops at breakpoint
  • --- Try to book the same room with network client 2

  • I'm expecting that network client 2 will stop in the block in the lock method shown below:

    while (isLockedRoomRecord(recNo)) {
    try {
    } catch (InterruptedException e) {

    However, cbased on the stack trace I don't think it gets that far.

    Below is the partial stack trace of what the network client 2 hits:

    java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: Read timed out
    at sun.rmi.transport.tcp.TCPChannel.createConnection(
    at sun.rmi.transport.tcp.TCPChannel.newConnection(
    at sun.rmi.server.UnicastRef.invoke(
    at suncertify.remote.RoomDatabaseImpl_Stub.isBooked(Unknown Source)
    at suncertify.gui.GuiController.bookRoom(
    at suncertify.gui.ClientWindow$BookRoom.actionPerformed(

    I'm not sure what the results mean or even if I'm trying to test the lock/unlock functionality correctly.

    Any suggestions about how to test end-to-end locking/unlocking that you have would be helpful!

    Ranch Hand
    Posts: 190
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I used MTJUnit, a multithreaded JUnit extension to test the threadsafety of my solution (URLyBird 1.3.3). I also put in extensive logging (finer and finest level) in combination with a custom log formatter that shows also the thread name and a more detailed timestamp than with the regular formatters, see example log output below.

    I found this approach allowed me to more fully test (hundreds of simultaneous "users") than any "multi-debug" session could possibly do

    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!