Search in sources :

Example 6 with RemoteEvent

use of com.oracle.bedrock.runtime.concurrent.RemoteEvent in project oracle-bedrock by coherence-community.

the class AbstractJavaApplicationTest method shouldReceiveEventFromApplication.

@Test
public void shouldReceiveEventFromApplication() throws Exception {
    EventListener listener1 = new EventListener(1);
    EventListener listener2 = new EventListener(1);
    String name = "Foo";
    RemoteEvent event = new EventingApplication.Event(19);
    try (JavaApplication application = getPlatform().launch(JavaApplication.class, ClassName.of(EventingApplication.class), IPv4Preferred.yes())) {
        application.addListener(listener1, StreamName.of(name));
        application.addListener(listener2, StreamName.of(name));
        EventingApplication.fireEvent(application, name, event);
        assertThat(listener1.await(1, TimeUnit.MINUTES), is(true));
        assertThat(listener2.await(1, TimeUnit.MINUTES), is(true));
        assertThat(listener1.getEvents().size(), is(1));
        assertThat(listener1.getEvents().get(0), is(event));
        assertThat(listener2.getEvents().size(), is(1));
        assertThat(listener2.getEvents().get(0), is(event));
    }
}
Also used : RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) StringContains.containsString(org.hamcrest.core.StringContains.containsString) EventingApplication(classloader.applications.EventingApplication) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 7 with RemoteEvent

use of com.oracle.bedrock.runtime.concurrent.RemoteEvent in project oracle-bedrock by coherence-community.

the class AbstractCoherenceCacheServerTest method shouldSendEventsFromCustomServer.

@Test
public void shouldSendEventsFromCustomServer() throws Exception {
    Platform platform = getPlatform();
    EventListener listener = new EventListener(1);
    String name = "Foo";
    RemoteEvent event = new CustomServer.Event(19);
    try (CoherenceCacheServer server = platform.launch(CoherenceCacheServer.class, ClassName.of(CustomServer.class), ClusterPort.automatic(), LocalHost.only(), Console.system())) {
        server.addListener(listener, StreamName.of(name));
        CustomServer.fireEvent(server, name, event);
        assertThat(listener.await(1, TimeUnit.MINUTES), is(true));
        assertThat(listener.getEvents().get(0), is(event));
        server.close();
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Aggregations

RemoteEvent (com.oracle.bedrock.runtime.concurrent.RemoteEvent)7 RemoteEventListener (com.oracle.bedrock.runtime.concurrent.RemoteEventListener)7 Test (org.junit.Test)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)3 Platform (com.oracle.bedrock.runtime.Platform)3 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)3 EventingApplication (classloader.applications.EventingApplication)2 StreamName (com.oracle.bedrock.runtime.concurrent.options.StreamName)2 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)2 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)2 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)2 EventingApplication (com.oracle.bedrock.runtime.remote.java.applications.EventingApplication)2 InetAddress (java.net.InetAddress)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1