From do-not-reply at jboss.org Wed Aug 4 13:19:50 2010 Content-Type: multipart/mixed; boundary="===============7816417641137754256==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r9504 - in trunk: tests/src/org/hornetq/tests/integration/journal and 2 other directories. Date: Wed, 04 Aug 2010 13:19:50 -0400 Message-ID: <201008041719.o74HJoXG003710@svn01.web.mwc.hst.phx2.redhat.com> --===============7816417641137754256== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: clebert.suconic(a)jboss.com Date: 2010-08-04 13:19:50 -0400 (Wed, 04 Aug 2010) New Revision: 9504 Added: trunk/src/main/org/hornetq/core/journal/impl/ExportJournal.java trunk/src/main/org/hornetq/core/journal/impl/ImportJournal.java trunk/tests/src/org/hornetq/tests/integration/journal/NIOImportExportTes= t.java Removed: trunk/tests/src/org/hornetq/tests/util/ListJournal.java Modified: trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalImplTest= Base.java Log: HORNETQ-180 - Import / export tool Added: trunk/src/main/org/hornetq/core/journal/impl/ExportJournal.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/org/hornetq/core/journal/impl/ExportJournal.java = (rev 0) +++ trunk/src/main/org/hornetq/core/journal/impl/ExportJournal.java 2010-08= -04 17:19:50 UTC (rev 9504) @@ -0,0 +1,191 @@ +/* + * Copyright 2010 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.core.journal.impl; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.List; + +import org.hornetq.core.journal.*; + +import org.hornetq.core.journal.SequentialFileFactory; +import org.hornetq.utils.Base64; + +/** + * Use this class to export the journal data. You can use it as a main cla= ss or through its native method {@link ExportJournal#exportJournal(String, = String, String, int, int, String)} + * = + * If you use the main method, use it as + * = + * Example: java -cp hornetq-core.jar org.hornetq.core.journal.impl.Export= Journal /journalDir hornetq-data hq 2 10485760 /tmp/export.dat + * + * @author Clebert Suconic<= /a> + * + * + */ +public class ExportJournal +{ + + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + // Static -------------------------------------------------------- + + // Constructors -------------------------------------------------- + + // Public -------------------------------------------------------- + + public static void main(String arg[]) + { + if (arg.length !=3D 6) + { + System.err.println("Use: java -cp hornetq-core.jar org.hornetq.co= re.journal.impl.ExportJournal "); + return; + } + + try + { + exportJournal(arg[0], arg[1], arg[2], Integer.parseInt(arg[3]), I= nteger.parseInt(arg[4]), arg[5]); + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + + public static void exportJournal(String directory, + String journalPrefix, + String journalSuffix, + int minFiles, + int fileSize, + String fileOutpu) throws Exception + { + NIOSequentialFileFactory nio =3D new NIOSequentialFileFactory(direct= ory); + + JournalImpl journal =3D new JournalImpl(fileSize, minFiles, 0, 0, ni= o, journalPrefix, journalSuffix, 1); + = + FileOutputStream fileOut =3D new FileOutputStream(new File(fileOutpu= )); + + BufferedOutputStream buffOut =3D new BufferedOutputStream(fileOut); + + PrintStream out =3D new PrintStream(buffOut); + + List files =3D journal.orderFiles(); + + for (JournalFile file : files) + { + out.println("#File," + file); + + exportJournalFile(out, nio, file); + } + + out.close(); + } + + /** + * @param out + * @param fileFactory + * @param file + * @throws Exception + */ + public static void exportJournalFile(final PrintStream out, SequentialF= ileFactory fileFactory, JournalFile file) throws Exception + { + JournalImpl.readJournalFile(fileFactory, file, new JournalReaderCall= back() + { + + public void onReadUpdateRecordTX(long transactionID, RecordInfo r= ecordInfo) throws Exception + { + out.println("operation(a)UpdateTX,txID@" + transactionID + ","= + describeRecord(recordInfo)); + } + + public void onReadUpdateRecord(RecordInfo recordInfo) throws Exce= ption + { + out.println("operation(a)Update," + describeRecord(recordInfo)= ); + } + + public void onReadRollbackRecord(long transactionID) throws Excep= tion + { + out.println("operation(a)Rollback,txID@" + transactionID); + } + + public void onReadPrepareRecord(long transactionID, byte[] extraD= ata, int numberOfRecords) throws Exception + { + out.println("operation(a)Prepare,txID@" + transactionID + + ",numberOfRecords@" + + numberOfRecords + + ",extraData@" + + encode(extraData)); + } + + public void onReadDeleteRecordTX(long transactionID, RecordInfo r= ecordInfo) throws Exception + { + out.println("operation(a)DeleteRecordTX,txID@" + transactionID= + "," + describeRecord(recordInfo)); + } + + public void onReadDeleteRecord(long recordID) throws Exception + { + out.println("operation(a)DeleteRecord,id@" + recordID); + } + + public void onReadCommitRecord(long transactionID, int numberOfRe= cords) throws Exception + { + out.println("operation(a)Commit,txID@" + transactionID + ",num= berOfRecords@" + numberOfRecords); + } + + public void onReadAddRecordTX(long transactionID, RecordInfo reco= rdInfo) throws Exception + { + out.println("operation(a)AddRecordTX,txID@" + transactionID + = "," + describeRecord(recordInfo)); + } + + public void onReadAddRecord(RecordInfo recordInfo) throws Excepti= on + { + out.println("operation(a)AddRecord," + describeRecord(recordIn= fo)); + } + + public void markAsDataFile(JournalFile file) + { + } + }); + } + + private static String describeRecord(RecordInfo recordInfo) + { + return "id@" + recordInfo.id + + ",userRecordType@" + + recordInfo.userRecordType + + ",length@" + + recordInfo.data.length + + ",isUpdate@" + + recordInfo.isUpdate + + ",data@" + + encode(recordInfo.data); + } + + private static String encode(byte[] data) + { + return Base64.encodeBytes(data, 0, data.length, Base64.DONT_BREAK_LI= NES | Base64.URL_SAFE); + } + + // Package protected --------------------------------------------- + + // Protected ----------------------------------------------------- + + // Private ------------------------------------------------------- + + // Inner classes ------------------------------------------------- + +} Added: trunk/src/main/org/hornetq/core/journal/impl/ImportJournal.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/org/hornetq/core/journal/impl/ImportJournal.java = (rev 0) +++ trunk/src/main/org/hornetq/core/journal/impl/ImportJournal.java 2010-08= -04 17:19:50 UTC (rev 9504) @@ -0,0 +1,358 @@ +/* + * Copyright 2010 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.core.journal.impl; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; + +import org.hornetq.core.journal.RecordInfo; +import org.hornetq.core.journal.impl.JournalImpl.JournalRecord; +import org.hornetq.utils.Base64; + +/** + * Use this class to import the journal data from a listed file. You can u= se it as a main class or through its native method {@link ImportJournal#imp= ortJournal(String, String, String, int, int, String)} + * = + * If you use the main method, use it as + * = + * Example: java -cp hornetq-core.jar org.hornetq.core.journal.impl.Export= Journal /journalDir hornetq-data hq 2 10485760 /tmp/export.dat + * + * @author Clebert Suconic<= /a> + * + * + */ +public class ImportJournal +{ + + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + // Static -------------------------------------------------------- + + // Constructors -------------------------------------------------- + + // Public -------------------------------------------------------- + + public static void main(String arg[]) + { + if (arg.length !=3D 6) + { + System.err.println("Use: java -cp hornetq-core.jar org.hornetq.co= re.journal.impl.ImportJournal "); + return; + } + + try + { + importJournal(arg[0], arg[1], arg[2], Integer.parseInt(arg[3]), I= nteger.parseInt(arg[4]), arg[5]); + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + + public static void importJournal(String directory, + String journalPrefix, + String journalSuffix, + int minFiles, + int fileSize, + String fileInput) throws Exception + { + + File journalDir =3D new File(directory); + + journalDir.mkdirs(); + + NIOSequentialFileFactory nio =3D new NIOSequentialFileFactory(direct= ory); + + JournalImpl journal =3D new JournalImpl(fileSize, minFiles, 0, 0, ni= o, journalPrefix, journalSuffix, 1); + + if (journal.orderFiles().size() !=3D 0) + { + throw new IllegalStateException("Import needs to create a brand n= ew journal"); + } + + journal.start(); + + // The journal is empty, as we checked already. Calling load just to= initialize the internal data + journal.loadInternalOnly(); + + FileInputStream fileInputStream =3D new FileInputStream(new File(fil= eInput)); + + BufferedReader reader =3D new BufferedReader(new InputStreamReader(f= ileInputStream)); + + String line; + + HashMap txCounters =3D new HashMap(); + + long lineNumber =3D 0; + = + Map journalRecords =3D journal.getRecords(); + + while ((line =3D reader.readLine()) !=3D null) + { + lineNumber++; + String splitLine[] =3D line.split(","); + if (splitLine[0].equals("#File")) + { + txCounters.clear(); + continue; + } + + Properties lineProperties =3D parseLine(splitLine); + + String operation =3D null; + try + { + operation =3D lineProperties.getProperty("operation"); + + if (operation.equals("AddRecord")) + { + RecordInfo info =3D parseRecord(lineProperties); + journal.appendAddRecord(info.id, info.userRecordType, info.= data, false); + } + else if (operation.equals("AddRecordTX")) + { + long txID =3D parseLong("txID", lineProperties); + AtomicInteger counter =3D getCounter(txID, txCounters); + counter.incrementAndGet(); + RecordInfo info =3D parseRecord(lineProperties); + journal.appendAddRecordTransactional(txID, info.id, info.us= erRecordType, info.data); + } + else if (operation.equals("AddRecordTX")) + { + long txID =3D parseLong("txID", lineProperties); + AtomicInteger counter =3D getCounter(txID, txCounters); + counter.incrementAndGet(); + RecordInfo info =3D parseRecord(lineProperties); + journal.appendAddRecordTransactional(txID, info.id, info.us= erRecordType, info.data); + } + else if (operation.equals("UpdateTX")) + { + long txID =3D parseLong("txID", lineProperties); + AtomicInteger counter =3D getCounter(txID, txCounters); + counter.incrementAndGet(); + RecordInfo info =3D parseRecord(lineProperties); + journal.appendUpdateRecordTransactional(txID, info.id, info= .userRecordType, info.data); + } + else if (operation.equals("Update")) + { + RecordInfo info =3D parseRecord(lineProperties); + journal.appendUpdateRecord(info.id, info.userRecordType, in= fo.data, false); + } + else if (operation.equals("DeleteRecord")) + { + long id =3D parseLong("id", lineProperties); + = + // If not found it means the append/update records were rec= laimed already + if (journalRecords.get((Long)id) !=3D null) + { + journal.appendDeleteRecord(id, false); + } + } + else if (operation.equals("DeleteRecordTX")) + { + long txID =3D parseLong("txID", lineProperties); + long id =3D parseLong("id", lineProperties); + AtomicInteger counter =3D getCounter(txID, txCounters); + counter.incrementAndGet(); + + // If not found it means the append/update records were rec= laimed already + if (journalRecords.get((Long)id) !=3D null) + { + journal.appendDeleteRecordTransactional(txID, id); + } + } + else if (operation.equals("Prepare")) + { + long txID =3D parseLong("txID", lineProperties); + int numberOfRecords =3D parseInt("numberOfRecords", linePro= perties); + AtomicInteger counter =3D getCounter(txID, txCounters); + byte[] data =3D parseEncoding("extraData", lineProperties); + + if (counter.get() =3D=3D numberOfRecords) + { + journal.appendPrepareRecord(txID, data, false); + } + else + { + System.err.println("Transaction " + txID + + " at line " + + lineNumber + + " is incomplete. The prepare record e= xpected " + + numberOfRecords + + " while the import only had " + + counter); + } + } + else if (operation.equals("Commit")) + { + long txID =3D parseLong("txID", lineProperties); + int numberOfRecords =3D parseInt("numberOfRecords", linePro= perties); + AtomicInteger counter =3D getCounter(txID, txCounters); + if (counter.get() =3D=3D numberOfRecords) + { + journal.appendCommitRecord(txID, false); + } + else + { + System.err.println("Transaction " + txID + + " at line " + + lineNumber + + " is incomplete. The commit record ex= pected " + + numberOfRecords + + " while the import only had " + + counter); + } + } + else if (operation.equals("Rollback")) + { + long txID =3D parseLong("txID", lineProperties); + journal.appendRollbackRecord(txID, false); + } + else + { + System.err.println("Invalid opeartion " + operation + " at = line " + lineNumber); + } + } + catch (Exception ex) + { + System.err.println("Error at line " + lineNumber + ", operatio= n=3D" + operation + " msg =3D " + ex.getMessage()); + } + } + + journal.compact(); + = + journal.stop(); + } + + protected static AtomicInteger getCounter(Long txID, Map txCounters) + { + + AtomicInteger counter =3D txCounters.get(txID); + if (counter =3D=3D null) + { + counter =3D new AtomicInteger(0); + txCounters.put(txID, counter); + } + + return counter; + } + + protected static RecordInfo parseRecord(Properties properties) throws E= xception + { + int id =3D parseInt("id", properties); + byte userRecordType =3D parseByte("userRecordType", properties); + boolean isUpdate =3D parseBoolean("isUpdate", properties); + byte[] data =3D parseEncoding("data", properties); + return new RecordInfo(id, userRecordType, data, isUpdate); + } + + private static byte[] parseEncoding(String name, Properties properties)= throws Exception + { + String value =3D parseString(name, properties); + + return decode(value); + } + + /** + * @param properties + * @return + */ + private static int parseInt(String name, Properties properties) throws = Exception + { + String value =3D parseString(name, properties); + + return Integer.parseInt(value); + } + + private static long parseLong(String name, Properties properties) throw= s Exception + { + String value =3D parseString(name, properties); + + return Long.parseLong(value); + } + + private static boolean parseBoolean(String name, Properties properties)= throws Exception + { + String value =3D parseString(name, properties); + + return Boolean.parseBoolean(value); + } + + private static byte parseByte(String name, Properties properties) throw= s Exception + { + String value =3D parseString(name, properties); + + return Byte.parseByte(value); + } + + /** + * @param name + * @param properties + * @return + * @throws Exception + */ + private static String parseString(String name, Properties properties) t= hrows Exception + { + String value =3D properties.getProperty(name); + + if (value =3D=3D null) + { + throw new Exception("property " + name + " not found"); + } + return value; + } + + protected static Properties parseLine(String[] splitLine) + { + Properties properties =3D new Properties(); + + for (String el : splitLine) + { + String[] tuple =3D el.split("@"); + if (tuple.length =3D=3D 2) + { + properties.put(tuple[0], tuple[1]); + } + else + { + properties.put(tuple[0], tuple[0]); + } + } + + return properties; + } + + private static byte[] decode(String data) + { + return Base64.decode(data, Base64.DONT_BREAK_LINES | Base64.URL_SAFE= ); + } + + // Package protected --------------------------------------------- + + // Protected ----------------------------------------------------- + + // Private ------------------------------------------------------- + + // Inner classes ------------------------------------------------- + +} Modified: trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2010-08-0= 4 07:16:42 UTC (rev 9503) +++ trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2010-08-0= 4 17:19:50 UTC (rev 9504) @@ -13,7 +13,6 @@ = package org.hornetq.core.journal.impl; = -import java.io.PrintStream; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; @@ -447,91 +446,10 @@ } = = - /** - * @param fileFactory - * @param journal - * @throws Exception - */ - public static void listJournalFiles(final PrintStream out, final Journa= lImpl journal) throws Exception - { - List files =3D journal.orderFiles(); - = - SequentialFileFactory fileFactory =3D journal.fileFactory; = - for (JournalFile file : files) - { - out.println("####### listing file " + file.getFile().getFileName(= ) + - " sequence =3D " + - file.getFileID()); = - listJournalFile(out, fileFactory, file); - } - } = - /** - * @param out - * @param fileFactory - * @param file - * @throws Exception - */ - public static void listJournalFile(final PrintStream out, SequentialFil= eFactory fileFactory, JournalFile file) throws Exception - { - JournalImpl.readJournalFile(fileFactory, file, new JournalReaderCall= back() - { = - public void onReadUpdateRecordTX(long transactionID, RecordInfo r= ecordInfo) throws Exception - { - out.println("ReadUpdateTX, txID=3D" + transactionID + ", " + r= ecordInfo); - } - - public void onReadUpdateRecord(RecordInfo recordInfo) throws Exce= ption - { - out.println("ReadUpdate " + recordInfo); - } - - public void onReadRollbackRecord(long transactionID) throws Excep= tion - { - out.println("Rollback txID=3D" + transactionID); - } - - public void onReadPrepareRecord(long transactionID, byte[] extraD= ata, int numberOfRecords) throws Exception - { - out.println("Prepare txID=3D" + transactionID + ", numberOfRec= ords=3D" + numberOfRecords); - } - - public void onReadDeleteRecordTX(long transactionID, RecordInfo r= ecordInfo) throws Exception - { - out.println("DeleteRecordTX txID=3D" + transactionID + ", " + = recordInfo); - } - - public void onReadDeleteRecord(long recordID) throws Exception - { - out.println("DeleteRecord id=3D" + recordID); - } - - public void onReadCommitRecord(long transactionID, int numberOfRe= cords) throws Exception - { - out.println("CommitRecord txID=3D" + transactionID + ", number= OfRecords=3D" + numberOfRecords); - } - - public void onReadAddRecordTX(long transactionID, RecordInfo reco= rdInfo) throws Exception - { - out.println("AddRecordTX, txID=3D" + transactionID + ", " + re= cordInfo); - } - - public void onReadAddRecord(RecordInfo recordInfo) throws Excepti= on - { - out.println("AddRecord " + recordInfo); - } - - public void markAsDataFile(JournalFile file) - { - } - }); - } - - - /** this method is used internally only however tools may use it to mai= ntenance. */ public static int readJournalFile(final SequentialFileFactory fileFacto= ry, final JournalFile file, @@ -3319,7 +3237,7 @@ = while (nextFile =3D=3D null) { - nextFile =3D openedFiles.poll(60, TimeUnit.SECONDS); + nextFile =3D openedFiles.poll(5, TimeUnit.SECONDS); if (nextFile =3D=3D null) { JournalImpl.log.warn("Couldn't open a file in 60 Seconds", Added: trunk/tests/src/org/hornetq/tests/integration/journal/NIOImportExpor= tTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/integration/journal/NIOImportExportTe= st.java (rev 0) +++ trunk/tests/src/org/hornetq/tests/integration/journal/NIOImportExportTe= st.java 2010-08-04 17:19:50 UTC (rev 9504) @@ -0,0 +1,210 @@ +/* + * Copyright 2010 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.tests.integration.journal; + +import java.io.File; + +import org.hornetq.core.journal.EncodingSupport; +import org.hornetq.core.journal.SequentialFileFactory; +import org.hornetq.core.journal.impl.NIOSequentialFileFactory; +import org.hornetq.tests.unit.core.journal.impl.JournalImplTestBase; +import org.hornetq.tests.unit.core.journal.impl.fakes.SimpleEncoding; + +/** + * A NIOImportExportTest + * + * @author Clebert Suconic<= /a> + * + * + */ +public class NIOImportExportTest extends JournalImplTestBase +{ + + /* (non-Javadoc) + * @see org.hornetq.tests.unit.core.journal.impl.JournalImplTestBase#ge= tFileFactory() + */ + @Override + protected SequentialFileFactory getFileFactory() throws Exception + { + File file =3D new File(getTestDir()); + + deleteDirectory(file); + + file.mkdir(); + + return new NIOSequentialFileFactory(getTestDir(), true); + } + + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + // Static -------------------------------------------------------- + + // Constructors -------------------------------------------------- + + // Public -------------------------------------------------------- + + protected void tearDown() throws Exception + { + + } + + public void testExportImport() throws Exception + { + setup(10, 10 * 1024, true); + + createJournal(); + + startJournal(); + + load(); + + add(1, 2); + + journal.forceMoveNextFile(); + + delete(1, 2); + + add(3, 4); + + journal.forceMoveNextFile(); + + addTx(5, 6, 7, 8); + + journal.forceMoveNextFile(); + + addTx(5, 9); + + commit(5); + + journal.forceMoveNextFile(); + + deleteTx(10, 6, 7, 8, 9); + + commit(10); + + addTx(11, 11, 12); + commit(11); + + stopJournal(); + + exportImportJournal(); + + createJournal(); + + startJournal(); + + loadAndCheck(); + + } + + + public void testExportImport3() throws Exception + { + setup(10, 10 * 1024, true); + + createJournal(); + + startJournal(); + + load(); + + add(1, 2); + + journal.forceMoveNextFile(); + + delete(1, 2); + + add(3, 4); + + journal.forceMoveNextFile(); + + addTx(5, 6, 7, 8); + + journal.forceMoveNextFile(); + + addTx(5, 9); + + commit(5); + + journal.forceMoveNextFile(); + + deleteTx(10, 6, 7, 8, 9); + + commit(10); + + addTx(11, 12, 13); + + EncodingSupport xid =3D new SimpleEncoding(10, (byte)0); + prepare(11, xid); + + stopJournal(); + + exportImportJournal(); + + createJournal(); + + startJournal(); + + loadAndCheck(); + = + commit(11); + + stopJournal(); + + exportImportJournal(); + + createJournal(); + + startJournal(); + + loadAndCheck(); + = + = + } + + public void testExportImport2() throws Exception + { + setup(10, 10 * 1024, true); + + createJournal(); + + startJournal(); + + load(); + + add(1); + + stopJournal(); + + exportImportJournal(); + + createJournal(); + + startJournal(); + + loadAndCheck(); + + } + + // Package protected --------------------------------------------- + + // Protected ----------------------------------------------------- + + // Private ------------------------------------------------------- + + // Inner classes ------------------------------------------------- + +} Modified: trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalI= mplTestBase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalImplTes= tBase.java 2010-08-04 07:16:42 UTC (rev 9503) +++ trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalImplTes= tBase.java 2010-08-04 17:19:50 UTC (rev 9504) @@ -13,6 +13,8 @@ = package org.hornetq.tests.unit.core.journal.impl; = +import java.io.File; +import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; @@ -28,6 +30,8 @@ import org.hornetq.core.journal.RecordInfo; import org.hornetq.core.journal.SequentialFileFactory; import org.hornetq.core.journal.TestableJournal; +import org.hornetq.core.journal.impl.ExportJournal; +import org.hornetq.core.journal.impl.ImportJournal; import org.hornetq.core.journal.impl.JournalImpl; import org.hornetq.core.logging.Logger; import org.hornetq.tests.util.UnitTestCase; @@ -165,6 +169,50 @@ journal.stop(); } = + /** + * @throws Exception + */ + protected void exportImportJournal() throws Exception + { + System.out.println("Exporting to " + getTestDir() + "/output.log"); + + ExportJournal.exportJournal(getTestDir(), + this.filePrefix, + this.fileExtension, + this.minFiles, + this.fileSize, + getTestDir() + "/output.log"); + + File dir =3D new File(getTestDir()); + + FilenameFilter fnf =3D new FilenameFilter() + { + public boolean accept(final File file, final String name) + { + return name.endsWith("." + fileExtension); + } + }; + + System.out.println("file =3D " + dir); + + File files[] =3D dir.listFiles(fnf); + + for (File file : files) + { + System.out.println("Deleting " + file); + file.delete(); + } + + ImportJournal.importJournal(getTestDir(), + filePrefix, + fileExtension, + minFiles, + fileSize, + getTestDir() + "/output.log"); + } + + + = protected void loadAndCheck() throws Exception { loadAndCheck(false); Deleted: trunk/tests/src/org/hornetq/tests/util/ListJournal.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/util/ListJournal.java 2010-08-04 07:1= 6:42 UTC (rev 9503) +++ trunk/tests/src/org/hornetq/tests/util/ListJournal.java 2010-08-04 17:1= 9:50 UTC (rev 9504) @@ -1,128 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * Red Hat licenses this file to you under the Apache License, version - * 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package org.hornetq.tests.util; - -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; - -import org.hornetq.core.config.impl.FileConfiguration; -import org.hornetq.core.journal.PreparedTransactionInfo; -import org.hornetq.core.journal.RecordInfo; -import org.hornetq.core.journal.SequentialFileFactory; -import org.hornetq.core.journal.impl.AIOSequentialFileFactory; -import org.hornetq.core.journal.impl.JournalImpl; - -/** - * Lists the journal content for debug purposes. - * = - * This is just a class useful on debug during development, - * - * @author Clebert Suconic<= /a> - * = - * Created Dec 12, 2008 11:42:35 AM - * - * - */ -public class ListJournal -{ - - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - // Public -------------------------------------------------------- - - public static void main(final String arg[]) - { - try - { - FileConfiguration fileConf =3D new FileConfiguration(); - - fileConf.setJournalDirectory("/work/projects/trunk/journal"); - - // fileConf.setConfigurationUrl(arg[0]); - - fileConf.start(); - - SequentialFileFactory fileFactory =3D new AIOSequentialFileFactor= y(fileConf.getJournalDirectory()); - - JournalImpl journal =3D new JournalImpl(fileConf.getJournalFileSi= ze(), - 10, - 0, - 0, - fileFactory, - "hornetq-data", - "hq", - fileConf.getJournalMaxIO_NI= O()); - - ArrayList records =3D new ArrayList(); - ArrayList prepared =3D new ArrayList(); - - journal.start(); - - - PrintStream out =3D new PrintStream(new FileOutputStream("/tmp/fi= le.out")); - - out.println("######### Journal records per file"); - = - JournalImpl.listJournalFiles(out, journal); - - journal.load(records, prepared, null); - = - out.println(); - = - out.println("##########################################"); - out.println("# T O T A L L I S T #"); - - if (prepared.size() > 0) - { - out.println("There are " + prepared.size() + " prepared transa= ctions on the journal"); - } - - out.println("Total of " + records.size() + " committed records"); - - for (RecordInfo record : records) - { - out.println("user record: " + record); - } - - journal.checkReclaimStatus(); - - System.out.println("Data =3D " + journal.debug()); - = - journal.stop(); - = - out.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - // Private ------------------------------------------------------- - - // Inner classes ------------------------------------------------- - -} --===============7816417641137754256==--