OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
Marcin Mroczkowski wrote:Ok now i know what i got to do. Thanks again, i hope my next post will be on new thread and inform about exam pass
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
Marcin Mroczkowski wrote:One of the major requirments for Data.class is implementation of lock method, which will block any other attempts to lock the same record again, so i think this one should be tested hard.
Roel De Nijs wrote:
Marcin Mroczkowski wrote:One of the major requirments for Data.class is implementation of lock method, which will block any other attempts to lock the same record again, so i think this one should be tested hard.
Do I understand correctly if I state you want to create a test case which verifies that if a record is locked by a threadA it can't be locked by any other thread?
Roel De Nijs wrote:If that's the case I would try something like this test case: create a list with e.g. 10 threads. All these threads do the same thing: lock record 1, do some assertions and finally unlock record 1. If your lock-method works as expected 1 of these threads should own the lock (it's state should be RUNNABLE), all other threads should be in BLOCKED state. That's easily to verify through Thread's getState()-method. When unlock of record 1 is called by the thread that has locked record 1, all other threads will compete again to lock record 1. And then you verify the assumptions again. This process will repeat itself until all records have locked and unlocked record 1
OCJP 6, OCMJD 6
Marcin Mroczkowski wrote:Yes that's exacly what i want to test. This problem can be very tricky because any of normal tests will not detect it (including Roberto's test case, unit tests, business interface tests, user-side apllication tests), it's MUST requirement, and if threre is even slight chance for two threads to get same lock, the project can be failed on the spot.
Marcin Mroczkowski wrote:Now this test do what it should do
Roel De Nijs wrote:It can be tricky to test some multi-threaded issues. Because of my simple design, implementation and straightforward business logic I did not needed such a test. I could easily determine by using a bit of logic thinking that it's impossible for 2 threads to get same lock. With a more complex situation I would have created a similar test.
Roel De Nijs wrote:If you are satisfied with your test (and it's not closely tied with your Data class and assumptions you made), you could maybe (just like Roberto and me) share your test with the community (and add a link to ScjdFaq), so others could run this test to verify their lock-method is spot-on.
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
OCJP 6, OCMJD 6
Did you just should on me? You should read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|