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));
}
}
}
}
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));
}
}
}
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);
}
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);
}
}
Aggregations