use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method testSynchronisationUpdateBGArea.
/**
* Do in different threads ant check that no exception happens :
* 1. create BG-Area
* 5. delete
*/
@Test
public void testSynchronisationUpdateBGArea() {
// => 400 x 100ms => 40sec => finished in 50sec
final int maxLoop = 75;
final String areaName = "BGArea_2";
final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
final CountDownLatch finfishCount = new CountDownLatch(3);
BGArea bgArea = areaManager.findBGArea(areaName, c1);
assertNull(bgArea);
bgArea = areaManager.createAndPersistBGArea(areaName, "description:" + areaName, c1);
assertNotNull(bgArea);
startThreadUpdateBGArea(areaName, maxLoop, exceptionHolder, 20, finfishCount);
startThreadUpdateBGArea(areaName, maxLoop, exceptionHolder, 40, finfishCount);
startThreadUpdateBGArea(areaName, maxLoop, exceptionHolder, 15, finfishCount);
// sleep until t1 and t2 should have terminated/excepted
try {
finfishCount.await(120, TimeUnit.SECONDS);
} catch (InterruptedException e) {
exceptionHolder.add(e);
}
// if not -> they are in deadlock and the db did not detect it
for (Exception exception : exceptionHolder) {
log.error("exception: ", exception);
}
assertTrue("Exceptions #" + exceptionHolder.size(), exceptionHolder.size() == 0);
assertEquals("Not all threads has finished", 0, finfishCount.getCount());
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method countBGAreasOfBusinessGroups.
@Test
public void countBGAreasOfBusinessGroups() {
// create a resource, 3 area and 2 group
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
String areaName = UUID.randomUUID().toString();
BGArea area1 = areaManager.createAndPersistBGArea("count-1-" + areaName, "description:" + areaName, resource.getOlatResource());
BGArea area2 = areaManager.createAndPersistBGArea("count-2-" + areaName, "description:" + areaName, resource.getOlatResource());
BGArea area3 = areaManager.createAndPersistBGArea("count-3-" + areaName, "description:" + areaName, resource.getOlatResource());
// create 2 groups
BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "count-1-group", "count-group-desc", 0, -1, false, false, resource);
BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "count-2-group", "count-group-desc", 0, -1, false, false, resource);
dbInstance.commitAndCloseSession();
// add the relations
areaManager.addBGToBGArea(group1, area1);
areaManager.addBGToBGArea(group1, area2);
areaManager.addBGToBGArea(group1, area3);
areaManager.addBGToBGArea(group2, area1);
dbInstance.commitAndCloseSession();
// check with empty list
int numOfAreas1 = areaManager.countBGAreasOfBusinessGroups(Collections.<BusinessGroup>emptyList());
Assert.assertEquals(0, numOfAreas1);
// num of areas of group2 -> only area1
int numOfAreas2 = areaManager.countBGAreasOfBusinessGroups(Collections.singletonList(group2));
Assert.assertEquals(1, numOfAreas2);
// num of areas of group 1 and 2
List<BusinessGroup> groups = new ArrayList<BusinessGroup>(2);
groups.add(group1);
groups.add(group2);
int numOfAreas3 = areaManager.countBGAreasOfBusinessGroups(groups);
Assert.assertEquals(3, numOfAreas3);
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method startThreadUpdateBGArea.
private void startThreadUpdateBGArea(final String areaName, final int maxLoop, final List<Exception> exceptionHolder, final int sleepTime, final CountDownLatch finishedCount) {
// thread 2 : update,copy
new Thread(new Runnable() {
public void run() {
try {
for (int i = 0; i < maxLoop; i++) {
try {
BGArea bgArea = areaManager.findBGArea(areaName, c1);
// Detached the bg-area object with closing session
DBFactory.getInstance().closeSession();
if (bgArea != null) {
bgArea.setDescription("description:" + areaName + i);
areaManager.updateBGArea(bgArea);
}
} catch (Exception e) {
exceptionHolder.add(e);
} finally {
try {
DBFactory.getInstance().closeSession();
} catch (Exception e) {
// ignore
}
;
}
sleep(sleepTime);
}
} catch (Exception e) {
exceptionHolder.add(e);
} finally {
finishedCount.countDown();
}
}
}).start();
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method findBGArea.
@Test
public void findBGArea() {
// create a resource with areas
OLATResource resource = JunitTestHelper.createRandomResource();
String areaName = UUID.randomUUID().toString();
BGArea area1 = areaManager.createAndPersistBGArea("find-1-" + areaName, "description:" + areaName, resource);
BGArea area2 = areaManager.createAndPersistBGArea("find-2-" + areaName, "description:" + areaName, resource);
dbInstance.commitAndCloseSession();
BGArea fArea1 = areaManager.findBGArea("find-1-" + areaName, resource);
Assert.assertNotNull(fArea1);
Assert.assertEquals(area1, fArea1);
BGArea fArea2 = areaManager.findBGArea("find-2-" + areaName, resource);
Assert.assertNotNull(fArea2);
Assert.assertEquals(area2, fArea2);
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method addAndDeleteRelations.
@Test
public void addAndDeleteRelations() {
// create a resource, an area, a group
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
String areaName = UUID.randomUUID().toString();
BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource.getOlatResource());
BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource.getOlatResource());
// create 2 groups
BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource);
BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource);
BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "area-3-group", "area-group-desc", 0, -1, false, false, resource);
dbInstance.commitAndCloseSession();
// add the relations
areaManager.addBGToBGArea(group1, area1);
areaManager.addBGToBGArea(group2, area1);
areaManager.addBGToBGArea(group2, area2);
areaManager.addBGToBGArea(group3, area1);
dbInstance.commitAndCloseSession();
// check with find groups
List<BGArea> areaGroup2 = areaManager.findBGAreasOfBusinessGroup(group2);
Assert.assertNotNull(areaGroup2);
Assert.assertEquals(2, areaGroup2.size());
Assert.assertTrue(areaGroup2.contains(area1));
Assert.assertTrue(areaGroup2.contains(area2));
// remove relation to group2
areaManager.deleteBGtoAreaRelations(group2);
dbInstance.commitAndCloseSession();
// check find groups
List<BGArea> areaGroup2After = areaManager.findBGAreasOfBusinessGroup(group2);
Assert.assertNotNull(areaGroup2After);
Assert.assertEquals(0, areaGroup2After.size());
}
Aggregations