*/
public void testGroupUser(final int NB, final boolean withBarrier) {
logger.log(BasicLevel.INFO, "testGroupUser" + NB +
(withBarrier ? "WithBarrier" : ""));
final Waiter waiter = new Waiter(0, withBarrier);
final Group group = new Group("TestThinLock.testGroupUser.group1");
final User[] users = new User[NB];
for(int i=0; i<NB; i++) {
users[i] = new User("TestThinLock.testGroupUser.user" + i);
group.getUsers().add(users[i]);
}
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
pm.makePersistent(group);
pm.currentTransaction().commit();
pm.close();
Thread[] ths = new Thread[NB];
for(int i=0; i<NB; i++) {
ths[i] = new Thread(new TestGroupUser(waiter, group, users[i],
new User("TestThinLock.testGroupUser.user" + (NB + i)),
pmf));
}
for(int i=0; i<NB; i++) {
ths[i].start();
}
Collection threads = Arrays.asList(ths);
List res = waiter.nextAction(threads, 1000);
assertTrue("Thread blocked on first point: " + res, res.isEmpty());
res = waiter.nextAction(threads, 1000);
if (!res.isEmpty()) {
for(int i=0; i<ths.length; i++) {
if (ths[i].isAlive()) {
ths[i].interrupt();
}
}
}
assertTrue("Thread blocked on second point: " + res, res.isEmpty());
res = waiter.nextAction(threads, 1000);
for(int i=0; i<ths.length; i++) {
if (ths[i].isAlive()) {
try {
ths[i].join(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
pm = pmf.getPersistenceManager();
int size = group.getUsers().size();
pm.currentTransaction().begin();
pm.deletePersistentAll(group.getUsers());
pm.deletePersistent(group);
pm.currentTransaction().commit();
pm.close();
assertEquals("Bad number of users", NB, size);
}