Skip to content

Commit

Permalink
[WFCORE-6383] throwing boot errors if super.boot fails
Browse files Browse the repository at this point in the history
  • Loading branch information
istudens committed Sep 27, 2023
1 parent 36ebe35 commit 29dee92
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ protected BootErrorCollector getBootErrorCollector() {
return bootErrorCollector;
}

protected final ModelNode getBootErrors() {
return bootErrorCollector.getErrors();
}

protected OperationStepHandler createExtraValidationStepHandler() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void addFailureDescription(final ModelNode operation, final ModelNode failureDes
}
}

private ModelNode getErrors() {
ModelNode getErrors() {
synchronized (errors) {
return errors.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/
package org.jboss.as.core.model.test.deployment;

import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.fail;

import org.hamcrest.MatcherAssert;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.core.model.test.AbstractCoreModelTest;
import org.jboss.as.core.model.test.KernelServices;
import org.jboss.as.core.model.test.TestModelType;
Expand Down Expand Up @@ -37,34 +37,15 @@ public void testDeployments() throws Exception {

@Test
public void testIncorrectDeployments() throws Exception {
try { createKernelServicesBuilder(TestModelType.STANDALONE)
.setXmlResource("standalone_duplicate.xml")
.createContentRepositoryContent("12345678901234567890")
.build();
} catch (XMLStreamException ex) {
String expectedMessage = ControllerLogger.ROOT_LOGGER.duplicateNamedElement("abc.war", new Location() {
public int getLineNumber() {
return 287;
}

public int getColumnNumber() {
return 1;
}

public int getCharacterOffset() {
return 1;
}

public String getPublicId() {
return "";
}

public String getSystemId() {
return "";
}
}).getMessage();
expectedMessage = expectedMessage.substring(expectedMessage.indexOf("WFLYCTL0073:"));
MatcherAssert.assertThat(ex.getMessage(), containsString(expectedMessage));
try {
createKernelServicesBuilder(TestModelType.STANDALONE)
.setXmlResource("standalone_duplicate.xml")
.createContentRepositoryContent("12345678901234567890")
.build();
fail("Expected boot failed");
} catch (OperationFailedException ex) {
final String failureDescription = ex.getFailureDescription().asString();
MatcherAssert.assertThat(failureDescription, allOf(containsString("WFLYSRV0205:"), containsString("abc.war")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
*/
package org.jboss.as.core.model.test.servergroup;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROFILE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_GROUP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;

import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import static org.junit.Assert.fail;

import org.hamcrest.MatcherAssert;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.core.model.test.AbstractCoreModelTest;
import org.jboss.as.core.model.test.KernelServices;
Expand Down Expand Up @@ -54,30 +53,10 @@ public void testServerGroupXmlWithWrongDeployments() throws Exception {
.createContentRepositoryContent("12345678901234567890")
.createContentRepositoryContent("09876543210987654321")
.build();
} catch (XMLStreamException ex) {
String expectedMessage = ControllerLogger.ROOT_LOGGER.duplicateNamedElement("foo.war", new Location() {
public int getLineNumber() {
return 1634;
}

public int getColumnNumber() {
return 1;
}

public int getCharacterOffset() {
return 1;
}

public String getPublicId() {
return "";
}

public String getSystemId() {
return "";
}
}).getMessage();
expectedMessage = expectedMessage.substring(expectedMessage.indexOf("WFLYCTL0073:"));
MatcherAssert.assertThat(ex.getMessage(), containsString(expectedMessage));
fail("Expected boot failed");
} catch (OperationFailedException ex) {
final String failureDescription = ex.getFailureDescription().asString();
MatcherAssert.assertThat(failureDescription, allOf(containsString("WFLYDC0063:"), containsString("foo.war")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public abstract class ModelTestModelControllerService extends AbstractController
private volatile ManagementResourceRegistration rootRegistration;
private volatile Throwable error;
private volatile boolean bootSuccess;
private static final OperationFailedException unknownBootFailure = new OperationFailedException("Unknown failure while executing boot operations");
private static final String BOOT_ERROR_MESSAGE = "Failure while executing boot operations";

/**
* This is the constructor to use for 23.0.x core model tests.
Expand Down Expand Up @@ -297,7 +297,7 @@ protected boolean boot(List<ModelNode> bootOperations, boolean rollbackOnRuntime
}

if (!bootSuccess) {
error = unknownBootFailure;
error = new BootOperationFailedException(BOOT_ERROR_MESSAGE, super.getBootErrors());
}
return bootSuccess;
} catch (Exception e) {
Expand Down Expand Up @@ -347,10 +347,10 @@ public void start(StartContext context) throws StartException {

public void waitForSetup() throws Exception {
latch.await();
// Don't throw exception if a reason for the boot failure is not provided
if (error != null && !error.equals(unknownBootFailure)) {
if (error instanceof Exception)
if (error != null) {
if (error instanceof Exception) {
throw (Exception) error;
}
throw new RuntimeException(error);
}
}
Expand Down Expand Up @@ -451,7 +451,13 @@ public void registerCapabilities(ManagementResourceRegistration resourceRegistra
}
}

//These are here to overload the constuctor used for the different legacy controllers
private static class BootOperationFailedException extends OperationFailedException {
public BootOperationFailedException(final String msg, final ModelNode description) {
super(msg, description);
}
}

//These are here to overload the constructor used for the different legacy controllers


@SuppressWarnings("InstantiationOfUtilityClass")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.jboss.as.remoting;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.jboss.as.controller.capability.RuntimeCapability.buildDynamicCapabilityName;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
Expand Down Expand Up @@ -32,6 +34,8 @@
import java.util.concurrent.Executors;
import java.util.function.Consumer;

import org.hamcrest.MatcherAssert;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
import org.jboss.as.controller.extension.ExtensionRegistry;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
Expand All @@ -44,7 +48,6 @@
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceNotFoundException;
import org.jboss.msc.service.ServiceTarget;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -175,22 +178,14 @@ public void testSubsystemWithConnectorPropertyChange() throws Exception {

@Test
public void testSubsystemWithBadConnectorProperty() throws Exception {
KernelServices services = createKernelServicesBuilder(createRuntimeAdditionalInitialization(true))
.setSubsystemXmlResource("remoting-with-bad-connector-property.xml")
.build();

try {
services.getContainer().getRequiredService(RemotingServices.SUBSYSTEM_ENDPOINT);
fail("Expected no " + RemotingServices.SUBSYSTEM_ENDPOINT);
} catch (ServiceNotFoundException expected) {
// ok
}

try {
services.getContainer().getRequiredService(RemotingServices.serverServiceName("test-connector"));
fail("Expected no " + RemotingServices.serverServiceName("test-connector"));
} catch (ServiceNotFoundException expected) {
// ok
KernelServices services = createKernelServicesBuilder(createRuntimeAdditionalInitialization(true))
.setSubsystemXmlResource("remoting-with-bad-connector-property.xml")
.build();
fail("Expected boot failed");
} catch (OperationFailedException ex) {
final String failureDescription = ex.getFailureDescription().asString();
MatcherAssert.assertThat(failureDescription, allOf(containsString("WFLYRMT0028:"), containsString("WORKER_ACCEPT_THREAD_BAD")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
*/
package org.jboss.as.remoting;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.jboss.as.controller.capability.RuntimeCapability.buildDynamicCapabilityName;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.remoting.Capabilities.IO_WORKER_CAPABILITY_NAME;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.EnumSet;
Expand All @@ -17,6 +20,7 @@
import java.util.concurrent.Executors;
import java.util.function.Consumer;

import org.hamcrest.MatcherAssert;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
Expand Down Expand Up @@ -96,11 +100,15 @@ public void testRuntime() throws Exception {

@Test
public void testHttpConnectorValidationStepFail() throws Exception {
KernelServices services = createKernelServicesBuilder(createAdditionalInitialization())
.setSubsystemXml(getSubsystemXml("remoting-with-duplicate-http-connector.xml"))
.build();

Assert.assertFalse(services.isSuccessfulBoot());
try {
KernelServices services = createKernelServicesBuilder(createAdditionalInitialization())
.setSubsystemXml(getSubsystemXml("remoting-with-duplicate-http-connector.xml"))
.build();
fail("Expected boot failed");
} catch (OperationFailedException ex) {
final String failureDescription = ex.getFailureDescription().asString();
MatcherAssert.assertThat(failureDescription, allOf(containsString("WFLYCTL0445:"), containsString("http")));
}
}

@Test
Expand Down

0 comments on commit 29dee92

Please sign in to comment.