Skip to content

Commit

Permalink
Update to m7 api
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Apr 21, 2017
1 parent 36b0cf8 commit ebd4b3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ public void close()
this.close(5, TimeUnit.SECONDS);
}

public void subscribe(Consumer<InboundSseEvent> onEvent) {
@Override
public void register(Consumer<InboundSseEvent> onEvent) {
if (onEvent == null) {
throw new IllegalArgumentException();
}
onEventConsumers.add(onEvent);
}

public void subscribe(Consumer<InboundSseEvent> onEvent,
@Override
public void register(Consumer<InboundSseEvent> onEvent,
Consumer<Throwable> onError) {
if (onEvent == null) {
throw new IllegalArgumentException();
Expand All @@ -181,7 +183,8 @@ public void subscribe(Consumer<InboundSseEvent> onEvent,
onErrorConsumers.add(onError);
}

public void subscribe(Consumer<InboundSseEvent> onEvent,
@Override
public void register(Consumer<InboundSseEvent> onEvent,
Consumer<Throwable> onError,
Runnable onComplete) {
if (onEvent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testAddMessage() throws Exception

SseEventSource eventSource = SseEventSource.target(target).build();
Assert.assertEquals(SseEventSourceImpl.class, eventSource.getClass());
eventSource.subscribe(event -> {
eventSource.register(event -> {
results.add(event.toString());
latch.countDown();
});
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testSseEvent() throws Exception

SseEventSource eventSource = SseEventSource.target(target).build();
Assert.assertEquals(SseEventSourceImpl.class, eventSource.getClass());
eventSource.subscribe(event -> {
eventSource.register(event -> {
results.add(event.readData());
latch.countDown();
});
Expand All @@ -112,23 +112,23 @@ public void testBroadcast() throws Exception

SseEventSource eventSource = SseEventSource.target(target).build();
Assert.assertEquals(SseEventSourceImpl.class, eventSource.getClass());
eventSource.subscribe(event -> {
eventSource.register(event -> {
latch.countDown();
});
eventSource.open();
eventSource.subscribe(insse -> {Assert.assertTrue("", textMessage.equals(insse.readData()));});
eventSource.register(insse -> {Assert.assertTrue("", textMessage.equals(insse.readData()));});

Client client2 = new ResteasyClientBuilder().build();
WebTarget target2 = client2.target(generateURL("/service/sse/subscribe"));

SseEventSource eventSource2 = SseEventSource.target(target2).build();
eventSource2.subscribe(event -> {
eventSource2.register(event -> {
latch.countDown();
});
eventSource2.open();

//Test for eventSource subscriber
eventSource2.subscribe(insse -> {Assert.assertTrue("", textMessage.equals(insse.readData()));});
eventSource2.register(insse -> {Assert.assertTrue("", textMessage.equals(insse.readData()));});
//To give some time to subscribe, otherwise the broadcast will execute before subscribe
Thread.sleep(3000);
client.target(generateURL("/service/server-sent-events/broadcast")).request().post(Entity.entity(textMessage, MediaType.SERVER_SENT_EVENTS));
Expand Down

0 comments on commit ebd4b3a

Please sign in to comment.