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