• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URLyBird 1.2.3 Locking test

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've come up with some spag code for a junit test for a multi user locking test....anybody got any comments? (I know it's awfull code but it is 02:13 here and I'm fresh out of Dr Pepper)



getExample() is a little helper method to generate some test data.

This should return Xx (repeated however many times) eg: XxXxXxXx

Dunno - I'm tired but comments would be warmly welcomed.

Cheers
Dan
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel

I don't know what you want to test?

Your test is thread safe because you have synchronize block inside of the run method, the synchronize ensure you that only one thread will operate (be in) the block. With other words your workflow looks like this :
thread 1 -> lock-operate-release ,after this
thread 2 -> lock-operate-release, after this
....
thread 3 -> lock-operate-release.

What you need is something where the lock and release are access in the same time by more than one thread.

Regards M
P.S. keep a Dr Pepper for me also
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this one:
https://coderanch.com/t/189353/java-developer-SCJD/certification/JUnit-Test-Cases
[ September 06, 2007: Message edited by: Chris Be ]
reply
    Bookmark Topic Watch Topic
  • New Topic