Search in sources :

Example 86 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project openolat by klemens.

the class NotificationsManagerTest method testConcurrentSubscriberOperationsWithOneIdentity.

/**
 * Test creation of concurrent subscriber
 */
@Test
public void testConcurrentSubscriberOperationsWithOneIdentity() {
    final int NUM_OF_THREADS = 100;
    PublisherData pd = new PublisherData("MPSubscriber", "e.g. forumdata=keyofforum", null);
    SubscriptionContext sc = new SubscriptionContext("MPSubscriber", new Long(1238778566), UUID.randomUUID().toString().replace("-", ""));
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci-" + UUID.randomUUID().toString());
    final CountDownLatch finishCount = new CountDownLatch(NUM_OF_THREADS);
    List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
    List<MPSubscriberThread> threads = new ArrayList<MPSubscriberThread>();
    for (int i = 0; i < NUM_OF_THREADS; i++) {
        MPSubscriberThread thread = new MPSubscriberThread(sc, pd, id, exceptionHolder, statusList, finishCount);
        threads.add(thread);
    }
    for (MPSubscriberThread thread : threads) {
        thread.start();
    }
    // sleep until threads should have terminated/excepted
    try {
        finishCount.await(120, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("", e);
        Assert.fail();
    }
    for (Exception e : exceptionHolder) {
        log.error("Excpetion during concurrent subscription: ", e);
    }
    assertTrue("It throws an exception in test", exceptionHolder.isEmpty());
    assertEquals("Thread(s) did not finish", NUM_OF_THREADS, statusList.size());
    assertTrue("Subscriber does not exists", NotificationsManager.getInstance().isSubscribed(id, sc));
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PublisherData(org.olat.core.commons.services.notifications.PublisherData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 87 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project openolat by klemens.

the class NotificationsManagerTest method testAllPublishers.

@Test
public void testAllPublishers() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    List<Publisher> publishers = notificationManager.getAllPublisher();
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.contains(publisher));
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 88 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project openolat by klemens.

the class NotificationsManagerTest method testUnsubscribe_v2.

@Test
public void testUnsubscribe_v2() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("unsubs-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testUnsubscribe", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    // subscribe
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commitAndCloseSession();
    // check
    Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
    Assert.assertNotNull(subscriber);
    // unsubscribe
    notificationManager.unsubscribe(id, context);
    dbInstance.commitAndCloseSession();
    // check
    boolean subscribed = notificationManager.isSubscribed(id, context);
    Assert.assertFalse(subscribed);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 89 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project openolat by klemens.

the class NotificationsManagerTest method testGetSubscriptionInfos.

// markPublisherNews
@Test
public void testGetSubscriptionInfos() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fi1-" + UUID.randomUUID().toString());
    SubscriptionContext context = new SubscriptionContext("Course", new Long(789521), UUID.randomUUID().toString());
    PublisherData publisherData = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commitAndCloseSession();
    // get infos
    List<SubscriptionInfo> infos = notificationManager.getSubscriptionInfos(id, publisher.getType());
    Assert.assertNotNull(infos);
}
Also used : SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 90 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project openolat by klemens.

the class NotificationsManagerTest method testSubscribe.

@Test
public void testSubscribe() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("subs-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    // subscribe
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commitAndCloseSession();
    // check
    boolean subscribed = notificationManager.isSubscribed(id, context);
    Assert.assertTrue(subscribed);
    dbInstance.commitAndCloseSession();
    // double check
    Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
    Assert.assertNotNull(subscriber);
    Assert.assertEquals(publisher, subscriber.getPublisher());
    dbInstance.commitAndCloseSession();
    // triple check
    Subscriber reloadedSubscriber = notificationManager.getSubscriber(subscriber.getKey());
    Assert.assertNotNull(reloadedSubscriber);
    Assert.assertEquals(subscriber, reloadedSubscriber);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Aggregations

SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)204 PublisherData (org.olat.core.commons.services.notifications.PublisherData)84 Identity (org.olat.core.id.Identity)72 Test (org.junit.Test)66 Publisher (org.olat.core.commons.services.notifications.Publisher)58 RepositoryEntry (org.olat.repository.RepositoryEntry)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)28 BusinessGroup (org.olat.group.BusinessGroup)28 ArrayList (java.util.ArrayList)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)20 HttpResponse (org.apache.http.HttpResponse)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)18 Forum (org.olat.modules.fo.Forum)18 File (java.io.File)16 HttpGet (org.apache.http.client.methods.HttpGet)16 CollaborationTools (org.olat.collaboration.CollaborationTools)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)14 Roles (org.olat.core.id.Roles)12