use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class AgeOutHistoryUnitTestCase method testOneOffsOnly.
@Test
public void testOneOffsOnly() throws Exception {
Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
byte[] targetHash = HashUtils.hashFile(moduleDir);
targetHash = applyOneOff("oneoff1", targetHash);
targetHash = applyOneOff("oneoff2", targetHash);
controller.start();
try {
client = createClient();
assertPatched(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
assertRollbackList(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
ageoutHistory(client);
assertPatched(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
assertRollbackList(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
} finally {
controller.stop();
}
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class AgeOutHistoryUnitTestCase method testOneCP.
@Test
public void testOneCP() throws Exception {
Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
byte[] targetHash = HashUtils.hashFile(moduleDir);
targetHash = applyCP("cp1", targetHash);
controller.start();
try {
client = createClient();
assertPatched(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
assertRollbackList(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
ageoutHistory(client);
assertPatched(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
assertRollbackList(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
} finally {
controller.stop();
}
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class AgeOutHistoryUnitTestCase method applyPatch.
protected byte[] applyPatch(String patchID, byte[] targetHash, boolean cp) throws Exception {
String moduleName = "module-test";
String patchElementId = randomString();
File patchDir = mkdir(tempDir, patchID);
Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, targetHash, module);
PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
if (cp) {
patchBuilder = patchBuilder.upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), PatchingTestUtil.AS_VERSION + "_CP" + patchID).getParent().upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
} else {
patchBuilder = patchBuilder.oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
}
Patch patch = patchBuilder.build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// apply the patch and check if server is in restart-required mode
controller.start();
try {
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
if (cp) {
productConfig = new ProductConfig(PatchingTestUtil.PRODUCT, PatchingTestUtil.AS_VERSION + "_CP" + patchID, "main");
}
} finally {
controller.stop();
}
return moduleModified.getItem().getContentHash();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchBundleTestCase method createNextCumulativePatchModyfyingJbossModules.
private File createNextCumulativePatchModyfyingJbossModules(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
String layerPatchID = "layer" + patchID;
File cpPatchDir = mkdir(tempDir, patchID);
// Also see if we can update jboss-modules
final File installation = new File(AS_DISTRIBUTION);
final File patchDir = new File(cpPatchDir, patchID);
final ContentModification jbossModulesModification = PatchingTestUtil.updateModulesJar(installation, patchDir);
// Create the version module
final String versionModuleName = ProductInfo.getVersionModule();
final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
// Calculate the target hash of the currently active module
final String currentLayerPatchID = "layer" + currentPatch;
File originalVersionModulePath = new File(tempDir, currentPatch);
originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
assert patchedAsVersionHash != null;
ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).getParent().addContentModification(jbossModulesModification).build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchBundleTestCase method createCumulativePatchAddingARandomModule.
private File createCumulativePatchAddingARandomModule(String patchID, String asVersion, final String targetAsVersion, File targetDir) throws Exception {
String layerPatchID = "layer" + patchID;
File cpPatchDir = mkdir(tempDir, patchID);
final String moduleName = "org.wildfly.test." + randomString();
final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
// Create the version module
final String versionModuleName = ProductInfo.getVersionModule();
final String slot = ProductInfo.getVersionModuleSlot();
final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + slot;
final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule);
Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(moduleAdded).addContentModification(versionModuleModified).getParent().build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Aggregations