use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class UserCourseInformationsManagerTest method updateInitialLaunchDates_concurrent.
/**
* This test is to analyze a red screen
*/
@Test
public void updateInitialLaunchDates_concurrent() {
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-concurrent-6-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user, "course-concurrent-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession();
final int numThreads = 20;
CountDownLatch latch = new CountDownLatch(numThreads);
UpdateThread[] threads = new UpdateThread[numThreads];
for (int i = 0; i < threads.length; i++) {
OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
threads[i] = new UpdateThread(user, courseResource, userCourseInformationsManager, latch, dbInstance);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
try {
latch.await(120, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Assert.fail("Takes too long (more than 120sec)");
}
int countErrors = 0;
for (int i = 0; i < threads.length; i++) {
countErrors += threads[i].getErrors();
}
Assert.assertEquals(0, countErrors);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class UserCourseInformationsManagerTest method getInitialLaunchDates.
@Test
public void getInitialLaunchDates() {
Identity user1 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-3-" + UUID.randomUUID().toString());
Identity user2 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-4-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user1, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession();
OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
userCourseInformationsManager.updateUserCourseInformations(courseResource, user1);
userCourseInformationsManager.updateUserCourseInformations(courseResource, user2);
dbInstance.commitAndCloseSession();
List<Identity> users = new ArrayList<Identity>();
users.add(user1);
users.add(user2);
Map<Long, Date> launchDates = userCourseInformationsManager.getInitialLaunchDates(courseResource, users);
Assert.assertNotNull(launchDates);
Assert.assertEquals(2, launchDates.size());
Assert.assertTrue(launchDates.containsKey(user1.getKey()));
Assert.assertNotNull(launchDates.get(user1.getKey()));
Assert.assertTrue(launchDates.containsKey(user2.getKey()));
Assert.assertNotNull(launchDates.get(user2.getKey()));
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class UserCourseInformationsManagerTest method getInitialParticiantLaunchDate_businessGroup.
@Test
public void getInitialParticiantLaunchDate_businessGroup() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("init-launch-1-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("init-launch-2-");
ICourse course = CoursesWebService.createEmptyCourse(id1, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession();
OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
userCourseInformationsManager.updateUserCourseInformations(courseResource, id1);
userCourseInformationsManager.updateUserCourseInformations(courseResource, id2);
dbInstance.commit();
// add user to a group
BusinessGroup group = businessGroupService.createBusinessGroup(null, "initial launch", "tg", null, null, false, false, courseEntry);
businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
Date launchDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, group);
Assert.assertNotNull(launchDate);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class UserCourseInformationsManagerTest method getInitialLaunchDate_repositoryEntry.
@Test
public void getInitialLaunchDate_repositoryEntry() {
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-2-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession();
OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
userCourseInformationsManager.updateUserCourseInformations(courseResource, user);
dbInstance.commitAndCloseSession();
Date launchDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, user);
Assert.assertNotNull(launchDate);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class UserCourseInformationsManagerTest method createUpdateCourseInfos_updateToo_implementationDetails.
/**
* Check the low level update statement, it's the critical part of the
* method which update the user course informations.
*/
@Test
public void createUpdateCourseInfos_updateToo_implementationDetails() {
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-1-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession();
OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
userCourseInformationsManager.updateUserCourseInformations(courseResource, user);
dbInstance.commitAndCloseSession();
int updated1 = ((UserCourseInformationsManagerImpl) userCourseInformationsManager).lowLevelUpdate(courseResource, user);
dbInstance.commitAndCloseSession();
Assert.assertEquals(1, updated1);
int updated2 = ((UserCourseInformationsManagerImpl) userCourseInformationsManager).lowLevelUpdate(courseResource, user);
dbInstance.commitAndCloseSession();
Assert.assertEquals(1, updated2);
UserCourseInformations infos = userCourseInformationsManager.getUserCourseInformations(courseResource, user);
Assert.assertNotNull(infos);
Assert.assertNotNull(infos.getIdentity());
Assert.assertEquals(3, infos.getVisit());
}
Aggregations