Skip to content

Commit

Permalink
JBTM-2111. Zip object store in case of XTS crash recovery test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
gytis committed Mar 4, 2014
1 parent a809192 commit c27554e
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Expand Up @@ -10,6 +10,7 @@
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

Expand Down Expand Up @@ -164,6 +165,7 @@ public void tearDown()
File objectStore = new File(dir);
boolean ischeck = checkTxObjectStore(objectStore);
if(!ischeck) {
archiveObjectStore(jbossHome, testName);
StringBuffer buffer = exploreDirectory(objectStore, 0);
System.out.println(buffer);
}
Expand Down Expand Up @@ -314,4 +316,24 @@ private StringBuffer exploreDirectory(File directory, int level) {
}
return result;
}

private void archiveObjectStore(final String jbossHome, final String testName) {
final String source = jbossHome + "/standalone/data/tx-object-store";
String target = "target/";

if (testName != null) {
target += testName + "_tx-object-store.zip";
} else {
target += new Date().getTime() + "_tx-object-store.zip";
}

final ZipArchiver zipArchiver = new ZipArchiver();

try {
zipArchiver.createArchive(source, target);
} catch (IOException e) {
e.printStackTrace();
}
}

}
@@ -0,0 +1,81 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package com.arjuna.qa.junit;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
*
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*
*/
public final class ZipArchiver {

public void createArchive(final String source, final String target) throws IOException {
final File targetFile = new File(target);
final File sourceFile = new File(source);
final FileOutputStream targetFileOutputStream = new FileOutputStream(targetFile);
final ZipOutputStream targetZipOutputStream = new ZipOutputStream(targetFileOutputStream);

archiveFile(sourceFile, targetZipOutputStream, new ZipEntry(sourceFile.getName()));

targetZipOutputStream.close();
targetFileOutputStream.close();
}

private void archiveDirectory(final File sourceDirectory, final ZipOutputStream targetOutputStream,
final ZipEntry zipEntry) throws IOException {

for (final File file : sourceDirectory.listFiles()) {
final ZipEntry fileZipEntry = new ZipEntry(zipEntry.getName() + "/" + file.getName());

archiveFile(file, targetOutputStream, fileZipEntry);
}
}

private void archiveFile(final File sourceFile, final ZipOutputStream targetOutputStream,
final ZipEntry zipEntry) throws IOException {

if (sourceFile.isDirectory()) {
archiveDirectory(sourceFile, targetOutputStream, zipEntry);
} else {
byte[] buffer = new byte[1024];
final FileInputStream sourceInputStream = new FileInputStream(sourceFile);
int lenght;

targetOutputStream.putNextEntry(zipEntry);

while ((lenght = sourceInputStream.read(buffer)) > 0) {
targetOutputStream.write(buffer, 0, lenght);
}

sourceInputStream.close();
}
}

}

0 comments on commit c27554e

Please sign in to comment.