mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Added a regression test that asserts that eventbus and shared data are not null at factory init.
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
|
||||
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
*/
|
||||
|
||||
package io.vertx.core;
|
||||
|
||||
import io.vertx.core.spi.VerticleFactory;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class AccessEventBusFromInitVerticleFactory implements VerticleFactory {
|
||||
|
||||
@Override
|
||||
public void init(Vertx vertx) {
|
||||
// should not be null
|
||||
if (vertx.eventBus() == null) {
|
||||
throw new IllegalStateException("eventBus was null, while it shouldn't");
|
||||
}
|
||||
if (vertx.sharedData() == null) {
|
||||
throw new IllegalStateException("sharedData was null, while it shouldn't");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prefix() {
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createVerticle(String verticleName, ClassLoader classLoader, Promise<Callable<Verticle>> promise) {
|
||||
promise.complete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.vertx.core;
|
||||
|
||||
import io.vertx.core.spi.VerticleFactory;
|
||||
import io.vertx.test.core.VertxTestBase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AccessEventBusFromInitVerticleFactoryTest extends VertxTestBase {
|
||||
|
||||
@Test
|
||||
public void testLoadFactoryThatCheckEventBusAndSharedDataForNull() {
|
||||
assertEquals(2, vertx.verticleFactories().size());
|
||||
boolean found = false;
|
||||
for (VerticleFactory fact : vertx.verticleFactories()) {
|
||||
if (fact instanceof AccessEventBusFromInitVerticleFactory) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,13 @@ public class ClasspathVerticleFactoryTest extends VertxTestBase {
|
||||
|
||||
@Test
|
||||
public void testLoadedFromClasspath() {
|
||||
assertEquals(1, vertx.verticleFactories().size());
|
||||
VerticleFactory fact = vertx.verticleFactories().iterator().next();
|
||||
assertTrue(fact instanceof ClasspathVerticleFactory);
|
||||
assertEquals(2, vertx.verticleFactories().size());
|
||||
boolean found = false;
|
||||
for (VerticleFactory fact : vertx.verticleFactories()) {
|
||||
if (fact instanceof ClasspathVerticleFactory) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,10 @@ public class VerticleFactoryTest extends VertxTestBase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Unregister the factory that's loaded from the classpath
|
||||
VerticleFactory factory = vertx.verticleFactories().iterator().next();
|
||||
vertx.unregisterVerticleFactory(factory);
|
||||
// Unregister the factories that are loaded from the classpath
|
||||
for (VerticleFactory factory : vertx.verticleFactories()) {
|
||||
vertx.unregisterVerticleFactory(factory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
io.vertx.core.ClasspathVerticleFactory
|
||||
io.vertx.core.AccessEventBusFromInitVerticleFactory
|
||||
|
||||
Reference in New Issue
Block a user