-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFCORE-6524] Do not duplicate managed deployment in content reposito…
…ry in tmp/vfs/temp directory
- Loading branch information
Showing
7 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
.../test/java/org/wildfly/core/test/standalone/deployment/DeploymentDuplicationTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.wildfly.core.test.standalone.deployment; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.as.controller.client.ModelControllerClient; | ||
import org.jboss.as.controller.client.Operation; | ||
import org.jboss.as.controller.operations.common.Util; | ||
import org.jboss.as.repository.ContentFilter; | ||
import org.jboss.as.repository.ContentRepositoryElement; | ||
import org.jboss.as.repository.PathUtil; | ||
import org.jboss.as.server.ServerEnvironment; | ||
import org.jboss.as.test.deployment.trivial.ServiceActivatorDeploymentUtil; | ||
import org.jboss.as.test.integration.management.ManagementOperations; | ||
import org.jboss.as.test.integration.management.util.ServerReload; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.wildfly.core.testrunner.ManagementClient; | ||
import org.wildfly.core.testrunner.WildFlyRunner; | ||
|
||
/** | ||
* Tests that there is no jar duplication on deployment to save disk space. | ||
* | ||
* @author <a href="mailto:[email protected]">Lin Gao</a> | ||
*/ | ||
@RunWith(WildFlyRunner.class) | ||
public class DeploymentDuplicationTestCase { | ||
|
||
private static final String DEPLOYMENT_NAME = DeploymentDuplicationTestCase.class.getSimpleName() + ".jar"; | ||
|
||
private final Properties props = new Properties(); | ||
|
||
@Inject | ||
private ManagementClient managementClient; | ||
|
||
@Before | ||
public void setup() { | ||
props.clear(); | ||
props.put("prop-key-A", "prop-value-A"); | ||
props.put("prop-key-B", "prop-value-B"); | ||
props.put("prop-key-C", "prop-value-C"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
props.clear(); | ||
} | ||
|
||
@Test | ||
public void test() throws Exception { | ||
ModelControllerClient mcc = managementClient.getControllerClient(); | ||
JavaArchive deployment = ServiceActivatorDeploymentUtil.createServiceActivatorDeploymentArchive(DEPLOYMENT_NAME, props); | ||
Operation deploymentOp = createDeploymentOp(deployment); | ||
try { | ||
ManagementOperations.executeOperation(mcc, deploymentOp); | ||
ServiceActivatorDeploymentUtil.validateProperties(mcc, props); | ||
|
||
Path tempPath = Paths.get(ManagementOperations.executeOperation(mcc, readTempPathOp()).asString()); | ||
List<ContentRepositoryElement> elements = PathUtil.listFiles(tempPath, null, new ContentFilter() { | ||
@Override | ||
public boolean acceptFile(Path rootPath, Path file) throws IOException { | ||
return file.endsWith("content"); | ||
} | ||
@Override | ||
public boolean acceptFile(Path rootPath, Path file, InputStream in) throws IOException { | ||
return file.endsWith("content"); | ||
} | ||
@Override | ||
public boolean acceptDirectory(Path rootPath, Path path) throws IOException { | ||
return false; | ||
} | ||
}); | ||
// Check temp directory to make sure no duplication | ||
Assert.assertTrue("There should be no content file in the tmp directory", elements.isEmpty()); | ||
} finally { | ||
ManagementOperations.executeOperation(mcc, Util.createRemoveOperation(PathAddress.pathAddress("deployment", deployment.getName()))); | ||
ServerReload.executeReloadAndWaitForCompletion(mcc); | ||
} | ||
} | ||
|
||
private Operation readTempPathOp() { | ||
final ModelNode readAttributeOperation = Util.getReadAttributeOperation(PathAddress.pathAddress("path", ServerEnvironment.SERVER_TEMP_DIR), "path"); | ||
return Operation.Factory.create(readAttributeOperation, Collections.emptyList(), true); | ||
} | ||
|
||
private Operation createDeploymentOp(JavaArchive deployment) { | ||
final List<InputStream> streams = new ArrayList<>(); | ||
streams.add(deployment.as(ZipExporter.class).exportAsInputStream()); | ||
final ModelNode addOperation = Util.createAddOperation(PathAddress.pathAddress("deployment", deployment.getName())); | ||
addOperation.get("enabled").set(true); | ||
addOperation.get("content").add().get("input-stream-index").set(0); | ||
return Operation.Factory.create(addOperation, streams, true); | ||
} | ||
|
||
} |