final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
final List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
// Generate event for update
CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2, new Date(), 1));
cal = calManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event2 = cal.getEvent(TEST_EVENT_ID_2);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_2, event2);
assertEquals("Wrong calendar-event subject",event2.getSubject(), TEST_EVENT_SUBJECT_2);
System.out.println("testConcurrentAddRemoveEvent thread2 addEvent2 DONE");
// enable breakpoint
CodepointClient codepointClient = null;
CodepointRef codepointRef = null;
try {
codepointClient = CodepointClientFactory.createCodepointClient("vm://localhost?broker.persistent=false", CODEPOINT_SERVER_ID);
codepointRef = codepointClient.getCodepoint("org.olat.commons.coordinate.cluster.ClusterSyncer.doInSync-in-sync.org.olat.commons.calendar.ICalFileCalendarManager.addEventTo");
codepointRef.enableBreakpoint();
System.out.println();
} catch (Exception e) {
e.printStackTrace();
fail("Could not initialzed CoepointClient");
}
// thread 1
new Thread(new Runnable() {
public void run() {
try {
// 1. load calendar
CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
// 2. add Event1 => breakpoint hit
System.out.println("testConcurrentAddRemoveEvent thread1 addEvent1");
calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_1,TEST_EVENT_SUBJECT_1, new Date(), 1));
System.out.println("testConcurrentAddRemoveEvent thread1 addEvent1 DONE");
// 3. check event1 exist
cal = calManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
// 4. sleep 2sec
// 5. check event1 still exist (event2 added in meantime)
cal = calManager.getPersonalCalendar(test).getKalendar();
event1 = cal.getEvent(TEST_EVENT_ID_1);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
statusList.add(Boolean.TRUE);
System.out.println("testConcurrentAddRemoveEvent thread1 finished");
} catch (Exception ex) {
exceptionHolder.add(ex);// no exception should happen
}
}}).start();
// thread 2
new Thread(new Runnable() {
public void run() {
try {
CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
// 2. sleep 1sec
sleep(1000);
// 3. add Event2 (breakpoint of thread1 blocks)
System.out.println("testConcurrentAddRemoveEvent thread2 removeEvent2");
boolean removed = calManager.removeEventFrom(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2, new Date(), 1));
assertTrue(removed);
System.out.println("testConcurrentAddRemoveEvent thread1 removeEvent2 DONE");
// 4. check event2 exist
cal = calManager.getPersonalCalendar(test).getKalendar();
KalendarEvent updatedEvent = cal.getEvent(TEST_EVENT_ID_2);
assertNull("Still found deleted event with id=" + TEST_EVENT_ID_2, updatedEvent);
// 5. check event1 exist
cal = calManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
statusList.add(Boolean.TRUE);
System.out.println("testConcurrentAddRemoveEvent thread2 finished");
} catch (Exception ex) {