Search in sources :

Example 1 with GenericEventListener

use of org.olat.core.util.event.GenericEventListener in project OpenOLAT by OpenOLAT.

the class JMSTest method testSendReceive.

@Test
public void testSendReceive() {
    // enable test only if we have the cluster configuration enabled.
    // this test requires that an JMS Provider is running
    // (see file serviceconfig/org/olat/core/_spring/coreextconfig.xml)
    EventBus bus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("jms");
        // send and wait some time until a message should arrive at the latest.
        final OLATResourceable ores = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
        final CountDownLatch doneSignal = new CountDownLatch(1);
        bus.registerFor(new GenericEventListener() {

            @Override
            public void event(Event event) {
                log.audit("Event received: " + event);
                doneSignal.countDown();
            }
        }, id, ores);
        MultiUserEvent mue = new MultiUserEvent("amuecommand");
        bus.fireEventToListenersOf(mue, ores);
        try {
            boolean interrupt = doneSignal.await(5, TimeUnit.SECONDS);
            assertTrue("Test takes too long (more than 5s)", interrupt);
        } catch (InterruptedException e) {
            fail("" + e.getMessage());
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Event(org.olat.core.gui.control.Event) EventBus(org.olat.core.util.event.EventBus) GenericEventListener(org.olat.core.util.event.GenericEventListener) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Test(org.junit.Test)

Example 2 with GenericEventListener

use of org.olat.core.util.event.GenericEventListener in project openolat by klemens.

the class JMSTest method testSendReceive.

@Test
public void testSendReceive() {
    // enable test only if we have the cluster configuration enabled.
    // this test requires that an JMS Provider is running
    // (see file serviceconfig/org/olat/core/_spring/coreextconfig.xml)
    EventBus bus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("jms");
        // send and wait some time until a message should arrive at the latest.
        final OLATResourceable ores = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
        final CountDownLatch doneSignal = new CountDownLatch(1);
        bus.registerFor(new GenericEventListener() {

            @Override
            public void event(Event event) {
                log.audit("Event received: " + event);
                doneSignal.countDown();
            }
        }, id, ores);
        MultiUserEvent mue = new MultiUserEvent("amuecommand");
        bus.fireEventToListenersOf(mue, ores);
        try {
            boolean interrupt = doneSignal.await(5, TimeUnit.SECONDS);
            assertTrue("Test takes too long (more than 5s)", interrupt);
        } catch (InterruptedException e) {
            fail("" + e.getMessage());
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Event(org.olat.core.gui.control.Event) EventBus(org.olat.core.util.event.EventBus) GenericEventListener(org.olat.core.util.event.GenericEventListener) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 Event (org.olat.core.gui.control.Event)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 EventBus (org.olat.core.util.event.EventBus)2 GenericEventListener (org.olat.core.util.event.GenericEventListener)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2