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:
Paulo Lopes
2019-11-26 10:48:40 +01:00
parent 75f880801a
commit 86f5cfd0d1
5 changed files with 78 additions and 6 deletions

View File

@@ -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() {
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -1 +1,2 @@
io.vertx.core.ClasspathVerticleFactory
io.vertx.core.AccessEventBusFromInitVerticleFactory