use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchOpInputStreamIndexAsFSPathUnitTestCase method testMain.
@Test
public void testMain() throws Exception {
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
String patchElementId = randomString();
File patchDir = mkdir(tempDir, patchID);
// create a module to be updated w/o a conflict
File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
String moduleName = "module-test";
Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", "new resource in the module".getBytes())).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, HashUtils.hashFile(moduleDir), module);
// create a file for the conflict
String fileName = "file-test.txt";
File miscFile = touch(new File(PatchingTestUtil.AS_DISTRIBUTION, "bin"), fileName);
dump(miscFile, "original script to run standalone AS7");
byte[] originalFileHash = HashUtils.hashFile(miscFile);
// patch the file
ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", miscFile, "bin", fileName);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileModified).upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
controller.start();
// apply the patch using the cli
CommandContext ctx = CLITestUtil.getCommandContext();
try {
ctx.connectController();
ctx.handle("/core-service=patching:patch(input-stream-index=" + escapePath(zippedPatch.getAbsolutePath()) + ")");
} catch (Exception e) {
ctx.terminateSession();
throw e;
} finally {
controller.stop();
}
// first patch applied
assertPatchElements(baseModuleDir, new String[] { patchElementId }, false);
byte[] patch1FileHash = HashUtils.hashFile(miscFile);
assertNotEqual(originalFileHash, patch1FileHash);
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class CPRollingbackOneOffTestCase method testOneOffCP.
/**
* One-off patch updates a module then a CP updates another module rolling back the one-off.
*/
@Test
public void testOneOffCP() throws Exception {
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
final String patchElement1Id = randomString();
// create a module to be updated w/o a conflict
File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
String moduleAName = "org.a.module-a";
Module moduleA = new Module.Builder(moduleAName).resourceRoot(new ResourceItem(jarA.getName(), jarABytes)).miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH));
String moduleBName = "org.b.module-b";
Module moduleB = new Module.Builder(moduleBName).resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)).miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH));
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource a one-off".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement1Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
patchID = randomString();
final String patchElement2Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, HashUtils.hashFile(moduleBDir), moduleB);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "_CP1").getParent().upgradeElement(patchElement2Id, "base", false).addContentModification(moduleBModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, null);
assertControllerStarts();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class ShowHistoryUnitTestCase method testOneOffAndCP.
@Test
public void testOneOffAndCP() 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 = applyCP("cp1", targetHash);
final ModelNode response = showHistory();
assertTrue(response.has("outcome"));
assertEquals("success", response.get("outcome").asString());
assertTrue(response.has("result"));
final List<ModelNode> list = response.get("result").asList();
assertEquals(2, list.size());
assertPatchInfo(list.get(0), "cp1", "cumulative", "false");
assertPatchInfo(list.get(1), "oneoff1", "one-off", "false");
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class ShowHistoryUnitTestCase method testOneOff.
@Test
public void testOneOff() 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);
final ModelNode response = showHistory();
assertTrue(response.has("outcome"));
assertEquals("success", response.get("outcome").asString());
assertTrue(response.has("result"));
final List<ModelNode> list = response.get("result").asList();
assertEquals(1, list.size());
assertPatchInfo(list.get(0), "oneoff1", "one-off", "false");
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class AgeOutHistoryUnitTestCase method testCPBeforeCPWithOneOffs.
@Test
public void testCPBeforeCPWithOneOffs() 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("cp0", targetHash);
targetHash = applyCP("cp1", targetHash);
targetHash = applyOneOff("oneoff1", targetHash);
targetHash = applyOneOff("oneoff2", targetHash);
controller.start();
try {
client = createClient();
assertPatched(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, false });
assertRollbackList(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, false });
ageoutHistory(client);
assertCleanedUp("cp0");
assertPatched(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, true });
assertRollbackList(client, new String[] { "oneoff2", "oneoff1", "cp1" }, new boolean[] { false, false, true }, new boolean[] { false, false, false });
} finally {
controller.stop();
}
}
Aggregations