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

Expose all flavors (core, axle, rx) of Vert.x EventBus #1553

Merged
merged 1 commit into from
Mar 18, 2019
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 @@ -37,8 +37,8 @@ public class VertxProducer {

private volatile VertxConfiguration conf;
private volatile Vertx vertx;
private io.vertx.axle.core.Vertx axle;
private io.vertx.reactivex.core.Vertx rx;
private volatile io.vertx.axle.core.Vertx axle;
private volatile io.vertx.reactivex.core.Vertx rx;

private void createCompanions(Vertx instance) {
this.vertx = instance == null ? Vertx.vertx() : instance;
Expand Down Expand Up @@ -246,6 +246,24 @@ public synchronized EventBus eventbus() {
return this.vertx.eventBus();
}

@Singleton
@Produces
public synchronized io.vertx.axle.core.eventbus.EventBus axleEventbus() {
if (vertx == null) {
initialize();
}
return this.axle.eventBus();
}

@Singleton
@Produces
public synchronized io.vertx.reactivex.core.eventbus.EventBus rxRventbus() {
if (vertx == null) {
initialize();
}
return this.rx.eventBus();
}

void configure(VertxConfiguration config) {
this.conf = config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,56 @@
import java.util.Optional;
import java.util.OptionalInt;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class VertxProducerTest {

private VertxProducer producer;

@Before
public void setUp() throws Exception {
producer = new VertxProducer();
}

@After
public void tearDown() throws Exception {
producer.destroy();
}

@Test
public void shouldNotFailWithoutConfig() {
VertxProducer producer = new VertxProducer();
producer.configure(null);
verifyProducer();
}

private void verifyProducer() {
assertThat(producer.vertx(), is(notNullValue()));
assertFalse(producer.vertx().isClustered());
assertThat(producer.eventbus(), is(notNullValue()));

producer.destroy();
assertThat(producer.axle(), is(notNullValue()));
assertFalse(producer.axle().isClustered());
assertThat(producer.axleEventbus(), is(notNullValue()));

assertThat(producer.rx(), is(notNullValue()));
assertFalse(producer.rx().isClustered());
assertThat(producer.rxRventbus(), is(notNullValue()));
}

@Test
public void shouldNotFailWithDefaultConfig() {
VertxProducer producer = new VertxProducer();
VertxConfiguration configuration = createDefaultConfiguration();
configuration.workerPoolSize = 10;
configuration.warningExceptionTime = Duration.ofSeconds(1);
configuration.internalBlockingPoolSize = 5;
producer.configure(configuration);

assertThat(producer.vertx(), is(notNullValue()));
assertFalse(producer.vertx().isClustered());
assertThat(producer.eventbus(), is(notNullValue()));

producer.destroy();
verifyProducer();
}

@Test
public void shouldEnableClustering() {
VertxProducer producer = new VertxProducer();
VertxConfiguration configuration = createDefaultConfiguration();
ClusterConfiguration cc = configuration.cluster;
cc.clustered = true;
Expand All @@ -63,8 +78,6 @@ public void shouldEnableClustering() {
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("No ClusterManagerFactory"));
}

producer.destroy();
}

private VertxConfiguration createDefaultConfiguration() {
Expand Down