Skip to content

Commit 567650e

Browse files
committed
Fix for WFCORE-7269, ProvisioningConsistencyTestCase failures with s390 Semeru
1 parent 4415292 commit 567650e

File tree

2 files changed

+157
-13
lines changed

2 files changed

+157
-13
lines changed

testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/provisioning/ProvisioningConsistencyTestCase.java

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import java.util.TreeSet;
2525
import java.util.concurrent.atomic.AtomicReference;
2626

27+
import org.apache.commons.io.FileUtils;
28+
import static org.jboss.as.test.shared.FileUtils.computeHash;
29+
import static org.jboss.as.test.shared.FileUtils.unzipFile;
30+
2731
import org.jboss.logging.Logger;
28-
import org.junit.AssumptionViolatedException;
29-
import org.junit.BeforeClass;
3032
import org.junit.Test;
3133

3234
/**
@@ -59,17 +61,13 @@ private static Path resolveJBossHome() {
5961
}
6062
}
6163

62-
@BeforeClass
63-
public static void assumeNotS390() {
64-
if ("s390x".equalsIgnoreCase(System.getProperty("os.arch"))) {
65-
throw new AssumptionViolatedException("WFCORE-7269");
66-
}
64+
private static File getDistFile(Path channelPath, boolean exists, boolean directory, List<String> errors) {
65+
return getDistFile(CHANNEL_INSTALLATION, channelPath, DIST_INSTALLATION, exists, directory, errors);
6766
}
6867

69-
private static File getDistFile(Path channelPath, boolean exists, boolean directory, List<String> errors) {
70-
Path relative = CHANNEL_INSTALLATION.relativize(channelPath);
71-
System.out.println("Getting dist file for relative path " + relative);
72-
Path path = DIST_INSTALLATION.resolve(relative);
68+
private static File getDistFile(Path currentRoot, Path currentPath, Path distRoot, boolean exists, boolean directory, List<String> errors) {
69+
Path relative = currentRoot.relativize(currentPath);
70+
Path path = distRoot.resolve(relative);
7371
File test = path.toFile();
7472
File result = null;
7573
if (exists) {
@@ -142,9 +140,14 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
142140
} else {
143141
File distFile = getDistFile(path, true, false, errors);
144142
if (distFile != null) {
145-
if (path.toFile().length() != distFile.length()) {
146-
errors.add(String.format("dist file for %s has an unexpected length: %d not %d",
143+
if (path.toFile().length() != distFile.length()) {
144+
log.trace("File size is different");
145+
// This can happen on some platforms for fat jar generated at provisioning time.
146+
// Check that the actual jar content is identical.
147+
if (!sameJarContent(path, distFile.toPath(), errors)) {
148+
errors.add(String.format("dist file for %s has an unexpected length: %d not %d",
147149
path, distFile.length(), path.toFile().length()));
150+
}
148151
}
149152
}
150153
}
@@ -169,4 +172,89 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
169172
fail(errors.toString());
170173
}
171174
}
175+
176+
private static boolean sameJarContent(Path current, Path dist, List<String> errors) {
177+
if (!dist.getFileName().toString().endsWith(".jar")) {
178+
return false;
179+
}
180+
log.trace("Checking jar " + current);
181+
Path tempFolder = null;
182+
try {
183+
tempFolder = Files.createTempDirectory("checkconsistency");
184+
Path distUnzipped = tempFolder.resolve("dist");
185+
Path currentUnzipped = tempFolder.resolve("current");
186+
unzipFile(dist, distUnzipped);
187+
unzipFile(current, currentUnzipped);
188+
checkContent(currentUnzipped, distUnzipped, errors);
189+
if(errors.isEmpty()) return true;
190+
} catch (IOException ex) {
191+
errors.add("Exception occurred when checking " + dist + " file content. " + ex);
192+
} finally {
193+
try {
194+
if (tempFolder != null) {
195+
FileUtils.deleteDirectory(tempFolder.toFile());
196+
}
197+
} catch (IOException ex) {
198+
throw new RuntimeException(ex);
199+
}
200+
}
201+
return false;
202+
}
203+
204+
private static void checkContent(Path currentRoot, Path dist, List<String> errors) throws IOException {
205+
Files.walkFileTree(currentRoot, new FileVisitor<>() {
206+
@Override
207+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
208+
log.trace("Testing " + dir);
209+
if (dir.equals(currentRoot)) {
210+
File distRoot = getDistFile(currentRoot, dir, dist, true, true, errors);
211+
Set<String> channelChildren = new TreeSet<>(Arrays.asList(Objects.requireNonNull(dir.toFile().list())));
212+
Set<String> distChildren = new TreeSet<>(Arrays.asList(Objects.requireNonNull(distRoot.list())));
213+
assertEquals(dir.toString(), channelChildren, distChildren);
214+
return FileVisitResult.CONTINUE;
215+
} else {
216+
File distDir = getDistFile(currentRoot, dir, dist, true, true, errors);
217+
if (distDir != null) {
218+
assertTrue(dir.toString(), Objects.deepEquals(dir.toFile().list(), distDir.list()));
219+
return FileVisitResult.CONTINUE;
220+
} else {
221+
return FileVisitResult.SKIP_SUBTREE;
222+
}
223+
}
224+
}
225+
226+
@Override
227+
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
228+
System.out.println("Checking " + path);
229+
File distFile = getDistFile(currentRoot, path, dist, true, false, errors);
230+
if (distFile == null) {
231+
errors.add(String.format("current file %s has not been found in %s",
232+
path, dist));
233+
} else {
234+
try {
235+
String hash1 = computeHash(path);
236+
String hash2 = computeHash(distFile.toPath());
237+
if (!hash1.equals(hash2)) {
238+
errors.add(String.format("dist file for %s has an unexpected content",
239+
path));
240+
}
241+
} catch (Exception ex) {
242+
errors.add(String.format("dist file for %s has an unexpected length: %d not %d",
243+
path, distFile.length(), path.toFile().length()));
244+
}
245+
}
246+
return FileVisitResult.CONTINUE;
247+
}
248+
249+
@Override
250+
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
251+
throw exc;
252+
}
253+
254+
@Override
255+
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
256+
return FileVisitResult.CONTINUE;
257+
}
258+
});
259+
}
172260
}

testsuite/shared/src/main/java/org/jboss/as/test/shared/FileUtils.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111
import java.io.FileNotFoundException;
1212
import java.io.IOException;
1313
import java.io.InputStream;
14+
import java.math.BigInteger;
1415
import java.net.URL;
1516
import java.nio.charset.StandardCharsets;
17+
import java.nio.file.FileAlreadyExistsException;
18+
import java.nio.file.FileSystem;
19+
import java.nio.file.FileSystems;
20+
import java.nio.file.FileVisitOption;
21+
import java.nio.file.FileVisitResult;
1622
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.nio.file.SimpleFileVisitor;
1725
import java.nio.file.StandardCopyOption;
26+
import java.nio.file.attribute.BasicFileAttributes;
27+
import java.security.MessageDigest;
28+
import java.util.EnumSet;
1829

1930
/**
2031
* Shared fs utils for the test suite.
@@ -130,5 +141,50 @@ public static void close(Closeable closeable) {
130141
}
131142
}
132143

144+
public static String computeHash(Path p) throws Exception {
145+
byte[] data = Files.readAllBytes(p);
146+
byte[] hash = MessageDigest.getInstance("MD5").digest(data);
147+
return new BigInteger(1, hash).toString(16);
148+
}
149+
150+
public static void unzipFile(Path zipFile, Path targetDir) throws IOException {
151+
if (!Files.exists(targetDir)) {
152+
Files.createDirectories(targetDir);
153+
}
154+
try (FileSystem zipfs = newFileSystem(zipFile)) {
155+
for (Path zipRoot : zipfs.getRootDirectories()) {
156+
unzip(zipRoot, targetDir);
157+
}
158+
}
159+
}
160+
161+
private static FileSystem newFileSystem(Path path) throws IOException {
162+
return FileSystems.newFileSystem(path, (ClassLoader) null);
163+
}
133164

165+
private static void unzip(Path source, Path target) throws IOException {
166+
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
167+
new SimpleFileVisitor<Path>() {
168+
@Override
169+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
170+
throws IOException {
171+
final Path targetDir = target.resolve(source.relativize(dir).toString());
172+
try {
173+
Files.copy(dir, targetDir);
174+
} catch (FileAlreadyExistsException e) {
175+
if (!Files.isDirectory(targetDir)) {
176+
throw e;
177+
}
178+
}
179+
return FileVisitResult.CONTINUE;
180+
}
181+
182+
@Override
183+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
184+
throws IOException {
185+
Files.copy(file, target.resolve(source.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING);
186+
return FileVisitResult.CONTINUE;
187+
}
188+
});
189+
}
134190
}// class

0 commit comments

Comments
 (0)