Search in sources :

Example 1 with RemoteEventListener

use of com.oracle.bedrock.runtime.concurrent.RemoteEventListener 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 2 with RemoteEventListener

use of com.oracle.bedrock.runtime.concurrent.RemoteEventListener 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)

Example 3 with RemoteEventListener

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

the class RemoteEvents method add.

/**
 * Internally adds a {@link RemoteEventListener} to this {@link RemoteEvents} option
 *
 * @param listener       the {@link RemoteEventListener} to add
 * @param optionsByType  the {@link OptionsByType} for the {@link RemoteEventListener}
 */
private void add(RemoteEventListener listener, OptionsByType optionsByType) {
    StreamName streamName = optionsByType.get(StreamName.class);
    HashMap<RemoteEventListener, OptionsByType> streamEventListeners = eventListeners.computeIfAbsent(streamName, name -> new HashMap<>());
    streamEventListeners.put(listener, optionsByType);
}
Also used : StreamName(com.oracle.bedrock.runtime.concurrent.options.StreamName) OptionsByType(com.oracle.bedrock.OptionsByType) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener)

Example 4 with RemoteEventListener

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

the class SimpleJUnitTestRunTest method fireEvent.

public void fireEvent(JUnitTestListener.Event event, JUnitTestListener... listeners) throws Exception {
    Platform platform = mock(Platform.class);
    JavaApplicationProcess process = mock(JavaApplicationProcess.class);
    OptionsByType optionsByType = OptionsByType.empty();
    for (JUnitTestListener listener : listeners) {
        optionsByType.add(Decoration.of(listener));
    }
    try (SimpleJUnitTestRun application = new SimpleJUnitTestRun(platform, process, optionsByType)) {
        ArgumentCaptor<RemoteEventListener> captorListener = ArgumentCaptor.forClass(RemoteEventListener.class);
        ArgumentCaptor<Option> captorOptions = ArgumentCaptor.forClass(Option.class);
        verify(process).addListener(captorListener.capture(), captorOptions.capture());
        RemoteEventListener eventListener = captorListener.getValue();
        List<Option> listenerOpts = captorOptions.getAllValues();
        assertThat(eventListener, is(notNullValue()));
        assertThat(listenerOpts, containsInAnyOrder(JUnitTestRunner.STREAM_NAME));
        eventListener.onEvent(event);
    }
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) JUnitTestListener(com.oracle.bedrock.testsupport.junit.JUnitTestListener) SimpleJUnitTestListener(com.oracle.bedrock.testsupport.junit.SimpleJUnitTestListener) JavaApplicationProcess(com.oracle.bedrock.runtime.java.JavaApplicationProcess) Option(com.oracle.bedrock.Option) SimpleJUnitTestRun(com.oracle.bedrock.testsupport.junit.SimpleJUnitTestRun) OptionsByType(com.oracle.bedrock.OptionsByType) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener)

Aggregations

RemoteEventListener (com.oracle.bedrock.runtime.concurrent.RemoteEventListener)4 StreamName (com.oracle.bedrock.runtime.concurrent.options.StreamName)3 OptionsByType (com.oracle.bedrock.OptionsByType)2 RemoteEvent (com.oracle.bedrock.runtime.concurrent.RemoteEvent)2 InetAddress (java.net.InetAddress)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 Option (com.oracle.bedrock.Option)1 Platform (com.oracle.bedrock.runtime.Platform)1 JavaApplicationProcess (com.oracle.bedrock.runtime.java.JavaApplicationProcess)1 JUnitTestListener (com.oracle.bedrock.testsupport.junit.JUnitTestListener)1 SimpleJUnitTestListener (com.oracle.bedrock.testsupport.junit.SimpleJUnitTestListener)1 SimpleJUnitTestRun (com.oracle.bedrock.testsupport.junit.SimpleJUnitTestRun)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1