Search in sources :

Example 1 with RemoteEvent

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

the class RemoteJavaApplicationLauncherTest method shouldReceiveEventFromApplication.

@Test
public void shouldReceiveEventFromApplication() throws Exception {
    Platform platform = getRemotePlatform();
    EventListener listener1 = new EventListener(1);
    EventListener listener2 = new EventListener(1);
    String name = "Foo";
    RemoteEvent event = new EventingApplication.Event(19);
    try (JavaApplication application = platform.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);
        Assert.assertThat(listener1.await(1, TimeUnit.MINUTES), is(true));
        Assert.assertThat(listener2.await(1, TimeUnit.MINUTES), is(true));
        Assert.assertThat(listener1.getEvents().size(), is(1));
        Assert.assertThat(listener1.getEvents().get(0), is(event));
        Assert.assertThat(listener2.getEvents().size(), is(1));
        Assert.assertThat(listener2.getEvents().get(0), is(event));
    }
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) EventingApplication(com.oracle.bedrock.runtime.remote.java.applications.EventingApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 2 with RemoteEvent

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

the class RemoteJavaApplicationLauncherTest method shouldSendEventsToApplication.

@Test
public void shouldSendEventsToApplication() throws Exception {
    Platform platform = getRemotePlatform();
    EventListener listener = new EventListener(1);
    RemoteEvent event = new EventingApplication.Event(19);
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(EventingApplication.class), IPv4Preferred.yes())) {
        application.addListener(listener, StreamName.of("Back"));
        EventingApplication.listen(application, "Out", "Back");
        application.raise(event, StreamName.of("Out"));
        Assert.assertThat(listener.await(1, TimeUnit.MINUTES), is(true));
        Assert.assertThat(listener.getEvents().size(), is(1));
        Assert.assertThat(listener.getEvents().get(0), is(event));
        application.close();
    }
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) EventingApplication(com.oracle.bedrock.runtime.remote.java.applications.EventingApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 3 with RemoteEvent

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

the class AbstractJavaApplicationTest method shouldSendEventsToApplication.

@Test
public void shouldSendEventsToApplication() throws Exception {
    EventListener listener = new EventListener(1);
    RemoteEvent event = new EventingApplication.Event(19);
    try (JavaApplication application = getPlatform().launch(JavaApplication.class, ClassName.of(EventingApplication.class), IPv4Preferred.yes())) {
        application.addListener(listener, StreamName.of("Back"));
        EventingApplication.listen(application, "Out", "Back");
        application.raise(event, StreamName.of("Out"));
        Assert.assertThat(listener.await(1, TimeUnit.MINUTES), is(true));
        Assert.assertThat(listener.getEvents().size(), is(1));
        Assert.assertThat(listener.getEvents().get(0), is(event));
        application.close();
    }
}
Also used : RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) EventingApplication(classloader.applications.EventingApplication) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 4 with RemoteEvent

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

the class SocketBasedRemoteChannelTest method shouldReceiveEventsInOrder.

@Test
public void shouldReceiveEventsInOrder() throws Exception {
    int count = 100;
    final CountDownLatch latch = new CountDownLatch(count);
    final List<Integer> list = new ArrayList<>();
    RemoteEventListener listener = new RemoteEventListener() {

        @Override
        public void onEvent(RemoteEvent event) {
            list.add(((Event) event).getId());
            latch.countDown();
        }
    };
    try (SocketBasedRemoteChannelServer server = new SocketBasedRemoteChannelServer("Test")) {
        StreamName streamName = StreamName.of("Foo");
        InetAddress address = server.open();
        server.addListener(listener, streamName);
        try (SocketBasedRemoteChannelClient client = new SocketBasedRemoteChannelClient(address, server.getPort())) {
            client.open();
            for (int i = 0; i < count; i++) {
                client.raise(new Event(i), streamName);
            }
            assertThat(latch.await(1, TimeUnit.MINUTES), is(true));
            assertThat(list.size(), is(count));
            for (int i = 0; i < count; i++) {
                assertThat(list.get(i), is(i));
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamName(com.oracle.bedrock.runtime.concurrent.options.StreamName) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) ArrayList(java.util.ArrayList) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) CountDownLatch(java.util.concurrent.CountDownLatch) InetAddress(java.net.InetAddress) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) Test(org.junit.Test)

Example 5 with RemoteEvent

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

the class SocketBasedRemoteChannelTest method shouldRaiseAndProcessEvents.

@Test
public void shouldRaiseAndProcessEvents() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    RemoteEventListener listener = new RemoteEventListener() {

        @Override
        public void onEvent(RemoteEvent event) {
            latch.countDown();
        }
    };
    try (SocketBasedRemoteChannelServer server = new SocketBasedRemoteChannelServer("Test")) {
        StreamName streamName = StreamName.of("Foo");
        InetAddress address = server.open();
        server.addListener(listener, streamName);
        try (SocketBasedRemoteChannelClient client = new SocketBasedRemoteChannelClient(address, server.getPort())) {
            client.open();
            client.raise(new Event(1), streamName);
            assertThat(latch.await(1, TimeUnit.MINUTES), is(true));
        }
    }
}
Also used : StreamName(com.oracle.bedrock.runtime.concurrent.options.StreamName) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) RemoteEvent(com.oracle.bedrock.runtime.concurrent.RemoteEvent) CountDownLatch(java.util.concurrent.CountDownLatch) InetAddress(java.net.InetAddress) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) 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