Replaced sleeps in test with sync and CountDownLatch mechanism