Skip to content
Snippets Groups Projects
Commit 0a3e1f94 authored by srosse's avatar srosse
Browse files

OO-830: update the basiclti-util library

parent 8c319e7f
No related branches found
No related tags found
No related merge requests found
...@@ -1708,7 +1708,7 @@ ...@@ -1708,7 +1708,7 @@
<dependency> <dependency>
<groupId>org.sakaiproject.basiclti</groupId> <groupId>org.sakaiproject.basiclti</groupId>
<artifactId>basiclti-util</artifactId> <artifactId>basiclti-util</artifactId>
<version>2.2-SNAPSHOT</version> <version>2.10.SP1</version>
</dependency> </dependency>
<!-- J2EE dependencies but provided --> <!-- J2EE dependencies but provided -->
<dependency> <dependency>
......
...@@ -19,18 +19,16 @@ ...@@ -19,18 +19,16 @@
*/ */
package org.olat.course.assessment.manager; package org.olat.course.assessment.manager;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.course.ICourse; import org.olat.course.ICourse;
import org.olat.course.assessment.UserCourseInformations; import org.olat.course.assessment.UserCourseInformations;
import org.olat.restapi.repository.course.CoursesWebService; import org.olat.restapi.repository.course.CoursesWebService;
...@@ -45,9 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -45,9 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired;
* *
*/ */
public class UserCourseInformationsManagerTest extends OlatTestCase { public class UserCourseInformationsManagerTest extends OlatTestCase {
private static final OLog log = Tracing.createLoggerFor(UserCourseInformationsManagerTest.class);
@Autowired @Autowired
private DB dbInstance; private DB dbInstance;
@Autowired @Autowired
...@@ -55,7 +51,7 @@ public class UserCourseInformationsManagerTest extends OlatTestCase { ...@@ -55,7 +51,7 @@ public class UserCourseInformationsManagerTest extends OlatTestCase {
@Test @Test
public void createUpdateCourseInfos() { public void createUpdateCourseInfos() {
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-2-" + UUID.randomUUID().toString()); Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-1-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null); ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
...@@ -76,78 +72,39 @@ public class UserCourseInformationsManagerTest extends OlatTestCase { ...@@ -76,78 +72,39 @@ public class UserCourseInformationsManagerTest extends OlatTestCase {
} }
@Test @Test
public void updateSetLaunchDates_concurrent() { public void getInitialLaunchDate() {
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-1-" + UUID.randomUUID().toString()); Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-2-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null); ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
int numOfThreads = 25;
final CountDownLatch doneSignal = new CountDownLatch(numOfThreads);
SetLaunchDatesThread[] threads = new SetLaunchDatesThread[numOfThreads];
for(int i=numOfThreads; i-->0; ) {
threads[i] = new SetLaunchDatesThread(user, course.getResourceableId(), doneSignal);
}
for(int i=numOfThreads; i-->0; ) { userCourseInformationsManager.updateUserCourseInformations(course.getResourceableId(), user);
threads[i].start(); dbInstance.commitAndCloseSession();
}
try {
boolean interrupt = doneSignal.await(240, TimeUnit.SECONDS);
Assert.assertTrue("Test takes too long (more than 10s)", interrupt);
} catch (InterruptedException e) {
Assert.fail("" + e.getMessage());
}
int countError = 0; Date launchDate = userCourseInformationsManager.getInitialLaunchDate(course.getResourceableId(), user);
for(int i=numOfThreads; i-->0; ) { Assert.assertNotNull(launchDate);
countError += threads[i].getErrorCount();
}
Assert.assertEquals(0, countError);
UserCourseInformations infos = userCourseInformationsManager.getUserCourseInformations(course.getResourceableId(), user);
Assert.assertEquals(1250, infos.getVisit());
} }
@Test
private class SetLaunchDatesThread extends Thread { public void getInitialLaunchDates() {
Identity user1 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-3-" + UUID.randomUUID().toString());
private AtomicInteger errorCounter = new AtomicInteger(); Identity user2 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-4-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(user1, "course-launch-dates", "course long name", null);
private final Identity user; dbInstance.commitAndCloseSession();
private final Long courseResourceableId;
private final CountDownLatch doneSignal;
public SetLaunchDatesThread(Identity user, Long courseResourceableId, CountDownLatch doneSignal) { userCourseInformationsManager.updateUserCourseInformations(course.getResourceableId(), user1);
this.user = user; userCourseInformationsManager.updateUserCourseInformations(course.getResourceableId(), user2);
this.doneSignal = doneSignal; dbInstance.commitAndCloseSession();
this.courseResourceableId = courseResourceableId;
}
public int getErrorCount() { List<Identity> users = new ArrayList<Identity>();
return errorCounter.get(); users.add(user1);
} users.add(user2);
@Override Map<Long,Date> launchDates = userCourseInformationsManager.getInitialLaunchDates(course.getResourceableId(), users);
public void run() { Assert.assertNotNull(launchDates);
try { Assert.assertEquals(2, launchDates.size());
Thread.sleep(10); Assert.assertTrue(launchDates.containsKey(user1.getKey()));
} catch (InterruptedException e) { Assert.assertNotNull(launchDates.get(user1.getKey()));
log.error("", e); Assert.assertTrue(launchDates.containsKey(user2.getKey()));
} Assert.assertNotNull(launchDates.get(user2.getKey()));
UserCourseInformationsManager infoManager = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
try {
for(int i=0; i<50; i++) {
infoManager.updateUserCourseInformations(courseResourceableId, user);
}
} catch (Exception e) {
errorCounter.incrementAndGet();
log.error("", e);
} finally {
doneSignal.countDown();
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment