Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBTM-2111. Zip object store in case of XTS crash recovery test failure #611

Merged
merged 1 commit into from Mar 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}

}