Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before scheduling task on ReactorDispatcher - verify that its not closed #331

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ public void invoke(final int delay, final DispatchHandler timerCallback) throws
}

private void throwIfSchedulerError() {
// throw when the scheduler on which Reactor is running is already closed
final RejectedExecutionException rejectedException = this.reactor.attachments()
.get(RejectedExecutionException.class, RejectedExecutionException.class);
if (rejectedException != null) {
throw new RejectedExecutionException(rejectedException.getMessage(), rejectedException);
}

// throw when the pipe is in closed state - in which case,
// signalling the new event-dispatch will fail
if (!this.ioSignal.source().isOpen() || !this.ioSignal.sink().isOpen()) {
throw new RejectedExecutionException("ReactorDispatcher instance is closed.");
}
}

private void signalWorkQueue() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,21 @@ public void SupplyClosedExecutorServiceThenReceiverCloseOperation() throws Excep

temp.closeSync();
}

@Test(expected = RejectedExecutionException.class)
public void testEventHubClientSendAfterClose() throws Exception {
final ConnectionStringBuilder connectionString = TestContext.getConnectionString();
final EventHubClient eventHubClient = EventHubClient.createSync(connectionString.toString(), TestContext.EXECUTOR_SERVICE);
eventHubClient.closeSync();
eventHubClient.sendSync(EventData.create("test message".getBytes()));
}

@Test(expected = IllegalStateException.class)
public void testEventHubClientSendCloseAfterSomeSends() throws Exception {
final ConnectionStringBuilder connectionString = TestContext.getConnectionString();
final EventHubClient eventHubClient = EventHubClient.createSync(connectionString.toString(), TestContext.EXECUTOR_SERVICE);
eventHubClient.sendSync(EventData.create("test message".getBytes()));
eventHubClient.closeSync();
eventHubClient.sendSync(EventData.create("test message".getBytes()));
}
}