Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to test locking/unlocking  RSS feed

Bill Rowell
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!

    Ronald Wouters
    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

    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!