Search in sources :

Example 36 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

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());
}
Also used : BGArea(org.olat.group.area.BGArea) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 37 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BGAreaManagerTest method startThreadCreateDeleteBGArea.

/**
 * thread 1 : try to create - sleep - delete sleep
 *
 * @param areaName
 * @param maxLoop
 * @param exceptionHolder
 * @param sleepAfterCreate
 * @param sleepAfterDelete
 */
private void startThreadCreateDeleteBGArea(final String areaName, final int maxLoop, final List<Exception> exceptionHolder, final int sleepAfterCreate, final int sleepAfterDelete, final CountDownLatch finishedCount) {
    new Thread(new Runnable() {

        public void run() {
            try {
                for (int i = 0; i < maxLoop; i++) {
                    try {
                        BGArea bgArea = areaManager.createAndPersistBGArea(areaName, "description:" + areaName, c1);
                        if (bgArea != null) {
                            DBFactory.getInstance().closeSession();
                            // created a new bg area
                            sleep(sleepAfterCreate);
                            areaManager.deleteBGArea(bgArea);
                        }
                    } catch (Exception e) {
                        exceptionHolder.add(e);
                    } finally {
                        try {
                            DBFactory.getInstance().closeSession();
                        } catch (Exception e) {
                        // ignore
                        }
                        ;
                    }
                    sleep(sleepAfterDelete);
                }
            } catch (Exception e) {
                exceptionHolder.add(e);
            } finally {
                finishedCount.countDown();
            }
        }
    }).start();
}
Also used : BGArea(org.olat.group.area.BGArea)

Example 38 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BGAreaManagerTest method findBusinessGroupsOfAreaKeys_andGroupKeys.

@Test
public void findBusinessGroupsOfAreaKeys_andGroupKeys() {
    // create a resource, 3 area and 2 group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("find-group-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("find-group-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "find-group-1-area", "find-group-in-area-1-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "find-group-2-area", "find-group-in-area-2-desc", 0, -1, false, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "find-group-2-area", "find-group-in-area-3-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group1, area2);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area2);
    dbInstance.commitAndCloseSession();
    // check find area 2 -> all 3 groups
    List<Long> area2Key = Collections.singletonList(area2.getKey());
    List<BusinessGroup> groupsArea2 = areaManager.findBusinessGroupsOfAreaKeys(area2Key);
    Assert.assertNotNull(groupsArea2);
    Assert.assertEquals(3, groupsArea2.size());
    Assert.assertTrue(groupsArea2.contains(group1));
    Assert.assertTrue(groupsArea2.contains(group2));
    Assert.assertTrue(groupsArea2.contains(group3));
    List<Long> groupKeysArea2 = areaManager.findBusinessGroupKeysOfAreaKeys(area2Key);
    Assert.assertNotNull(groupKeysArea2);
    Assert.assertEquals(3, groupKeysArea2.size());
    Assert.assertTrue(groupKeysArea2.contains(group1.getKey()));
    Assert.assertTrue(groupKeysArea2.contains(group2.getKey()));
    Assert.assertTrue(groupKeysArea2.contains(group3.getKey()));
    // check find area 1 -> only group 1
    List<Long> area1Key = Collections.singletonList(area1.getKey());
    List<BusinessGroup> groupsArea1 = areaManager.findBusinessGroupsOfAreaKeys(area1Key);
    Assert.assertNotNull(groupsArea1);
    Assert.assertEquals(1, groupsArea1.size());
    Assert.assertTrue(groupsArea1.contains(group1));
    List<Long> groupKeysArea1 = areaManager.findBusinessGroupKeysOfAreaKeys(area1Key);
    Assert.assertNotNull(groupKeysArea1);
    Assert.assertEquals(1, groupKeysArea1.size());
    Assert.assertTrue(groupKeysArea1.contains(group1.getKey()));
    // check find area 1 and 2 -> all 3 groups
    List<Long> areaKeys = new ArrayList<>(2);
    areaKeys.add(area1.getKey());
    areaKeys.add(area2.getKey());
    List<BusinessGroup> groupsAreas = areaManager.findBusinessGroupsOfAreaKeys(areaKeys);
    Assert.assertNotNull(groupsAreas);
    Assert.assertEquals(3, groupsAreas.size());
    Assert.assertTrue(groupsAreas.contains(group1));
    Assert.assertTrue(groupsAreas.contains(group2));
    Assert.assertTrue(groupsAreas.contains(group3));
    List<Long> groupKeysAreas = areaManager.findBusinessGroupKeysOfAreaKeys(areaKeys);
    Assert.assertNotNull(groupKeysAreas);
    Assert.assertEquals(3, groupKeysAreas.size());
    Assert.assertTrue(groupKeysAreas.contains(group1.getKey()));
    Assert.assertTrue(groupKeysAreas.contains(group2.getKey()));
    Assert.assertTrue(groupKeysAreas.contains(group3.getKey()));
    // check with empty list
    List<BusinessGroup> emptyGroups = areaManager.findBusinessGroupsOfAreaKeys(Collections.<Long>emptyList());
    Assert.assertNotNull(emptyGroups);
    Assert.assertEquals(0, emptyGroups.size());
    List<Long> emptyGroupKeys = areaManager.findBusinessGroupKeysOfAreaKeys(Collections.<Long>emptyList());
    Assert.assertNotNull(emptyGroupKeys);
    Assert.assertEquals(0, emptyGroupKeys.size());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 39 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BGAreaManagerTest method testSynchronisationCreateBGArea.

/**
 * Do in different threads ant check that no exception happens :
 * 1. create BG-Area
 * 5. delete
 */
@Test
public void testSynchronisationCreateBGArea() {
    // => 400 x 100ms => 40sec => finished in 50sec
    final int maxLoop = 75;
    final String areaName = "BGArea_1";
    final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    final CountDownLatch finfishCount = new CountDownLatch(3);
    BGArea bgArea = areaManager.findBGArea(areaName, c1);
    assertNull(bgArea);
    startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 100, 20, finfishCount);
    startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 30, 40, finfishCount);
    startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 15, 20, finfishCount);
    // sleep until t1 and t2 should have terminated/excepted
    try {
        finfishCount.await(120, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("", 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());
}
Also used : BGArea(org.olat.group.area.BGArea) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 40 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BGAreaManagerTest method addAndFindByGroups.

@Test
public void addAndFindByGroups() {
    // 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());
    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);
    BusinessGroup group4 = businessGroupService.createBusinessGroup(null, "area-4-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relation
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area1);
    areaManager.addBGToBGArea(group3, area2);
    areaManager.addBGToBGArea(group4, area2);
    dbInstance.commitAndCloseSession();
    // check find group 1
    List<BGArea> areasGroup1 = areaManager.findBGAreasOfBusinessGroups(Collections.singletonList(group1));
    Assert.assertNotNull(areasGroup1);
    Assert.assertEquals(1, areasGroup1.size());
    Assert.assertTrue(areasGroup1.contains(area1));
    // check find group 2 and 4 -> only area 2
    List<BusinessGroup> groups2_4 = new ArrayList<BusinessGroup>();
    groups2_4.add(group2);
    groups2_4.add(group4);
    List<BGArea> areasGroup2_4 = areaManager.findBGAreasOfBusinessGroups(groups2_4);
    Assert.assertNotNull(areasGroup2_4);
    Assert.assertEquals(1, areasGroup2_4.size());
    Assert.assertTrue(areasGroup2_4.contains(area2));
    // check find all groups
    List<BusinessGroup> allGroups = new ArrayList<BusinessGroup>();
    allGroups.add(group1);
    allGroups.add(group2);
    allGroups.add(group3);
    allGroups.add(group4);
    List<BGArea> areasAllGroups = areaManager.findBGAreasOfBusinessGroups(allGroups);
    Assert.assertNotNull(areasAllGroups);
    Assert.assertEquals(2, areasAllGroups.size());
    Assert.assertTrue(areasAllGroups.contains(area1));
    Assert.assertTrue(areasAllGroups.contains(area2));
    // check empty list
    List<BGArea> areasEmpty = areaManager.findBGAreasOfBusinessGroups(Collections.<BusinessGroup>emptyList());
    Assert.assertNotNull(areasEmpty);
    Assert.assertEquals(0, areasEmpty.size());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

BGArea (org.olat.group.area.BGArea)124 BusinessGroup (org.olat.group.BusinessGroup)70 Test (org.junit.Test)68 RepositoryEntry (org.olat.repository.RepositoryEntry)52 ArrayList (java.util.ArrayList)22 Identity (org.olat.core.id.Identity)22 BGAreaReference (org.olat.group.model.BGAreaReference)18 AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)16 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)16 HashSet (java.util.HashSet)14 AssessmentMode (org.olat.course.assessment.AssessmentMode)12 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)12 OLATResource (org.olat.resource.OLATResource)12 AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 CollaborationTools (org.olat.collaboration.CollaborationTools)6 BusinessGroupShort (org.olat.group.BusinessGroupShort)6 File (java.io.File)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4