|
@@ -1,4 +1,5 @@
|
|
package org.apache.bookkeeper.test;
|
|
package org.apache.bookkeeper.test;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
*
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@@ -20,157 +21,132 @@ package org.apache.bookkeeper.test;
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
|
|
-
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.Charset;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Enumeration;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.bookkeeper.client.AsyncCallback.AddCallback;
|
|
import org.apache.bookkeeper.client.AsyncCallback.AddCallback;
|
|
import org.apache.bookkeeper.client.BKException;
|
|
import org.apache.bookkeeper.client.BKException;
|
|
import org.apache.bookkeeper.client.BookKeeper;
|
|
import org.apache.bookkeeper.client.BookKeeper;
|
|
|
|
+import org.apache.bookkeeper.client.LedgerEntry;
|
|
import org.apache.bookkeeper.client.LedgerHandle;
|
|
import org.apache.bookkeeper.client.LedgerHandle;
|
|
-import org.apache.bookkeeper.client.LedgerSequence;
|
|
|
|
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback;
|
|
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback;
|
|
-import org.apache.bookkeeper.proto.BookieServer;
|
|
|
|
|
|
+import org.apache.bookkeeper.client.BookKeeper.DigestType;
|
|
import org.apache.bookkeeper.streaming.LedgerInputStream;
|
|
import org.apache.bookkeeper.streaming.LedgerInputStream;
|
|
import org.apache.bookkeeper.streaming.LedgerOutputStream;
|
|
import org.apache.bookkeeper.streaming.LedgerOutputStream;
|
|
-
|
|
|
|
-import org.apache.log4j.ConsoleAppender;
|
|
|
|
-import org.apache.log4j.Level;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.apache.log4j.Logger;
|
|
-import org.apache.log4j.PatternLayout;
|
|
|
|
-import org.apache.zookeeper.CreateMode;
|
|
|
|
import org.apache.zookeeper.KeeperException;
|
|
import org.apache.zookeeper.KeeperException;
|
|
import org.apache.zookeeper.WatchedEvent;
|
|
import org.apache.zookeeper.WatchedEvent;
|
|
import org.apache.zookeeper.Watcher;
|
|
import org.apache.zookeeper.Watcher;
|
|
-import org.apache.zookeeper.ZooKeeper;
|
|
|
|
-import org.apache.zookeeper.ZooDefs.Ids;
|
|
|
|
-import org.apache.zookeeper.server.NIOServerCnxn;
|
|
|
|
-import org.apache.zookeeper.server.ZooKeeperServer;
|
|
|
|
-import org.apache.zookeeper.test.ClientBase;
|
|
|
|
-
|
|
|
|
|
|
+import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This test tests read and write, synchronous and
|
|
|
|
- * asynchronous, strings and integers for a BookKeeper client.
|
|
|
|
- * The test deployment uses a ZooKeeper server
|
|
|
|
- * and three BookKeepers.
|
|
|
|
|
|
+ * This test tests read and write, synchronous and asynchronous, strings and
|
|
|
|
+ * integers for a BookKeeper client. The test deployment uses a ZooKeeper server
|
|
|
|
+ * and three BookKeepers.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
|
|
-public class BookieReadWriteTest
|
|
|
|
- extends junit.framework.TestCase
|
|
|
|
- implements AddCallback, ReadCallback{
|
|
|
|
|
|
+public class BookieReadWriteTest extends BaseTestCase implements AddCallback, ReadCallback {
|
|
|
|
|
|
- //Depending on the taste, select the amount of logging
|
|
|
|
|
|
+ // Depending on the taste, select the amount of logging
|
|
// by decommenting one of the two lines below
|
|
// by decommenting one of the two lines below
|
|
- //static Logger LOG = Logger.getRootLogger();
|
|
|
|
|
|
+ // static Logger LOG = Logger.getRootLogger();
|
|
static Logger LOG = Logger.getLogger(BookieReadWriteTest.class);
|
|
static Logger LOG = Logger.getLogger(BookieReadWriteTest.class);
|
|
|
|
|
|
- static ConsoleAppender ca = new ConsoleAppender(new PatternLayout());
|
|
|
|
-
|
|
|
|
- // ZooKeeper related variables
|
|
|
|
- private static final String HOSTPORT = "127.0.0.1:2181";
|
|
|
|
- static Integer ZooKeeperDefaultPort = 2181;
|
|
|
|
- ZooKeeperServer zks;
|
|
|
|
- ZooKeeper zkc; //zookeeper client
|
|
|
|
- NIOServerCnxn.Factory serverFactory;
|
|
|
|
- File ZkTmpDir;
|
|
|
|
-
|
|
|
|
- //BookKeeper
|
|
|
|
- File tmpDirB1, tmpDirB2, tmpDirB3;
|
|
|
|
- BookieServer bs1, bs2, bs3;
|
|
|
|
- Integer initialPort = 5000;
|
|
|
|
- BookKeeper bkc; // bookkeeper client
|
|
|
|
byte[] ledgerPassword = "aaa".getBytes();
|
|
byte[] ledgerPassword = "aaa".getBytes();
|
|
LedgerHandle lh, lh2;
|
|
LedgerHandle lh, lh2;
|
|
long ledgerId;
|
|
long ledgerId;
|
|
- LedgerSequence ls;
|
|
|
|
-
|
|
|
|
- //test related variables
|
|
|
|
|
|
+ Enumeration<LedgerEntry> ls;
|
|
|
|
+
|
|
|
|
+ // test related variables
|
|
int numEntriesToWrite = 200;
|
|
int numEntriesToWrite = 200;
|
|
int maxInt = 2147483647;
|
|
int maxInt = 2147483647;
|
|
- Random rng; // Random Number Generator
|
|
|
|
|
|
+ Random rng; // Random Number Generator
|
|
ArrayList<byte[]> entries; // generated entries
|
|
ArrayList<byte[]> entries; // generated entries
|
|
ArrayList<Integer> entriesSize;
|
|
ArrayList<Integer> entriesSize;
|
|
|
|
|
|
|
|
+ DigestType digestType;
|
|
|
|
+
|
|
|
|
+ public BookieReadWriteTest(DigestType digestType){
|
|
|
|
+ super(3);
|
|
|
|
+ this.digestType = digestType;
|
|
|
|
+ }
|
|
// Synchronization
|
|
// Synchronization
|
|
SyncObj sync;
|
|
SyncObj sync;
|
|
Set<Object> syncObjs;
|
|
Set<Object> syncObjs;
|
|
-
|
|
|
|
|
|
+
|
|
class SyncObj {
|
|
class SyncObj {
|
|
int counter;
|
|
int counter;
|
|
- boolean value;
|
|
|
|
|
|
+ boolean value;
|
|
|
|
+
|
|
public SyncObj() {
|
|
public SyncObj() {
|
|
counter = 0;
|
|
counter = 0;
|
|
value = false;
|
|
value = false;
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void testOpenException()
|
|
|
|
- throws KeeperException, IOException, InterruptedException {
|
|
|
|
- bkc = new BookKeeper("127.0.0.1");
|
|
|
|
- try{
|
|
|
|
- lh = bkc.openLedger(0, ledgerPassword);
|
|
|
|
|
|
+ public void testOpenException() throws KeeperException, IOException, InterruptedException {
|
|
|
|
+ try {
|
|
|
|
+ lh = bkc.openLedger(0, digestType, ledgerPassword);
|
|
fail("Haven't thrown exception");
|
|
fail("Haven't thrown exception");
|
|
} catch (BKException e) {
|
|
} catch (BKException e) {
|
|
LOG.warn("Successfully thrown and caught exception:", e);
|
|
LOG.warn("Successfully thrown and caught exception:", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * test the streaming api for reading
|
|
|
|
- * and writing
|
|
|
|
|
|
+ * test the streaming api for reading and writing
|
|
|
|
+ *
|
|
* @throws {@link IOException}, {@link KeeperException}
|
|
* @throws {@link IOException}, {@link KeeperException}
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
- public void testStreamingClients() throws IOException,
|
|
|
|
- KeeperException, BKException, InterruptedException {
|
|
|
|
|
|
+ public void testStreamingClients() throws IOException, KeeperException, BKException, InterruptedException {
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- //write a string so that we cna
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ // write a string so that we cna
|
|
// create a buffer of a single bytes
|
|
// create a buffer of a single bytes
|
|
// and check for corner cases
|
|
// and check for corner cases
|
|
- String toWrite = "we need to check for this string to match " +
|
|
|
|
- "and for the record mahadev is the best";
|
|
|
|
- LedgerOutputStream lout = new LedgerOutputStream(lh , 1);
|
|
|
|
|
|
+ String toWrite = "we need to check for this string to match " + "and for the record mahadev is the best";
|
|
|
|
+ LedgerOutputStream lout = new LedgerOutputStream(lh, 1);
|
|
byte[] b = toWrite.getBytes();
|
|
byte[] b = toWrite.getBytes();
|
|
lout.write(b);
|
|
lout.write(b);
|
|
lout.close();
|
|
lout.close();
|
|
long lId = lh.getId();
|
|
long lId = lh.getId();
|
|
lh.close();
|
|
lh.close();
|
|
- //check for sanity
|
|
|
|
- lh = bkc.openLedger(lId, ledgerPassword);
|
|
|
|
- LedgerInputStream lin = new LedgerInputStream(lh, 1);
|
|
|
|
|
|
+ // check for sanity
|
|
|
|
+ lh = bkc.openLedger(lId, digestType, ledgerPassword);
|
|
|
|
+ LedgerInputStream lin = new LedgerInputStream(lh, 1);
|
|
byte[] bread = new byte[b.length];
|
|
byte[] bread = new byte[b.length];
|
|
int read = 0;
|
|
int read = 0;
|
|
- while (read < b.length) {
|
|
|
|
|
|
+ while (read < b.length) {
|
|
read = read + lin.read(bread, read, b.length);
|
|
read = read + lin.read(bread, read, b.length);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
String newString = new String(bread);
|
|
String newString = new String(bread);
|
|
assertTrue("these two should same", toWrite.equals(newString));
|
|
assertTrue("these two should same", toWrite.equals(newString));
|
|
lin.close();
|
|
lin.close();
|
|
lh.close();
|
|
lh.close();
|
|
- //create another ledger to write one byte at a time
|
|
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
|
|
+ // create another ledger to write one byte at a time
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
lout = new LedgerOutputStream(lh);
|
|
lout = new LedgerOutputStream(lh);
|
|
- for (int i=0; i < b.length;i++) {
|
|
|
|
|
|
+ for (int i = 0; i < b.length; i++) {
|
|
lout.write(b[i]);
|
|
lout.write(b[i]);
|
|
}
|
|
}
|
|
lout.close();
|
|
lout.close();
|
|
lId = lh.getId();
|
|
lId = lh.getId();
|
|
lh.close();
|
|
lh.close();
|
|
- lh = bkc.openLedger(lId, ledgerPassword);
|
|
|
|
|
|
+ lh = bkc.openLedger(lId, digestType, ledgerPassword);
|
|
lin = new LedgerInputStream(lh);
|
|
lin = new LedgerInputStream(lh);
|
|
bread = new byte[b.length];
|
|
bread = new byte[b.length];
|
|
- read= 0;
|
|
|
|
|
|
+ read = 0;
|
|
while (read < b.length) {
|
|
while (read < b.length) {
|
|
read = read + lin.read(bread, read, b.length);
|
|
read = read + lin.read(bread, read, b.length);
|
|
}
|
|
}
|
|
@@ -179,62 +155,60 @@ public class BookieReadWriteTest
|
|
lin.close();
|
|
lin.close();
|
|
lh.close();
|
|
lh.close();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void testReadWriteAsyncSingleClient() throws IOException{
|
|
|
|
|
|
+ public void testReadWriteAsyncSingleClient() throws IOException {
|
|
try {
|
|
try {
|
|
// Create a BookKeeper client and a ledger
|
|
// Create a BookKeeper client and a ledger
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- //bkc.initMessageDigest("SHA1");
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ // bkc.initMessageDigest("SHA1");
|
|
ledgerId = lh.getId();
|
|
ledgerId = lh.getId();
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
- for(int i = 0; i < numEntriesToWrite; i++){
|
|
|
|
|
|
+ for (int i = 0; i < numEntriesToWrite; i++) {
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.position(0);
|
|
entry.position(0);
|
|
-
|
|
|
|
|
|
+
|
|
entries.add(entry.array());
|
|
entries.add(entry.array());
|
|
entriesSize.add(entry.array().length);
|
|
entriesSize.add(entry.array().length);
|
|
lh.asyncAddEntry(entry.array(), this, sync);
|
|
lh.asyncAddEntry(entry.array(), this, sync);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// wait for all entries to be acknowledged
|
|
// wait for all entries to be acknowledged
|
|
synchronized (sync) {
|
|
synchronized (sync) {
|
|
- while (sync.counter < numEntriesToWrite){
|
|
|
|
|
|
+ while (sync.counter < numEntriesToWrite) {
|
|
LOG.debug("Entries counter = " + sync.counter);
|
|
LOG.debug("Entries counter = " + sync.counter);
|
|
sync.wait();
|
|
sync.wait();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("*** WRITE COMPLETE ***");
|
|
LOG.debug("*** WRITE COMPLETE ***");
|
|
- // close ledger
|
|
|
|
|
|
+ // close ledger
|
|
lh.close();
|
|
lh.close();
|
|
-
|
|
|
|
- //*** WRITING PART COMPLETE // READ PART BEGINS ***
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // *** WRITING PART COMPLETE // READ PART BEGINS ***
|
|
|
|
+
|
|
// open ledger
|
|
// open ledger
|
|
- lh = bkc.openLedger(ledgerId, ledgerPassword);
|
|
|
|
- LOG.debug("Number of entries written: " + lh.getLast());
|
|
|
|
- assertTrue("Verifying number of entries written", lh.getLast() == (numEntriesToWrite - 1));
|
|
|
|
-
|
|
|
|
- //read entries
|
|
|
|
|
|
+ lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
|
|
|
|
+ LOG.debug("Number of entries written: " + (lh.getLastAddConfirmed() + 1));
|
|
|
|
+ assertTrue("Verifying number of entries written", lh.getLastAddConfirmed() == (numEntriesToWrite - 1));
|
|
|
|
+
|
|
|
|
+ // read entries
|
|
lh.asyncReadEntries(0, numEntriesToWrite - 1, this, (Object) sync);
|
|
lh.asyncReadEntries(0, numEntriesToWrite - 1, this, (Object) sync);
|
|
-
|
|
|
|
|
|
+
|
|
synchronized (sync) {
|
|
synchronized (sync) {
|
|
- while(sync.value == false){
|
|
|
|
|
|
+ while (sync.value == false) {
|
|
sync.wait();
|
|
sync.wait();
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- assertTrue("Checking number of read entries", ls.size() == numEntriesToWrite);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("*** READ COMPLETE ***");
|
|
LOG.debug("*** READ COMPLETE ***");
|
|
-
|
|
|
|
- // at this point, LedgerSequence ls is filled with the returned values
|
|
|
|
|
|
+
|
|
|
|
+ // at this point, LedgerSequence ls is filled with the returned
|
|
|
|
+ // values
|
|
int i = 0;
|
|
int i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
ByteBuffer origbb = ByteBuffer.wrap(entries.get(i));
|
|
ByteBuffer origbb = ByteBuffer.wrap(entries.get(i));
|
|
Integer origEntry = origbb.getInt();
|
|
Integer origEntry = origbb.getInt();
|
|
byte[] entry = ls.nextElement().getEntry();
|
|
byte[] entry = ls.nextElement().getEntry();
|
|
@@ -248,6 +222,8 @@ public class BookieReadWriteTest
|
|
assertTrue("Checking entry " + i + " for size", entry.length == entriesSize.get(i).intValue());
|
|
assertTrue("Checking entry " + i + " for size", entry.length == entriesSize.get(i).intValue());
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
+ assertTrue("Checking number of read entries", i == numEntriesToWrite);
|
|
|
|
+
|
|
lh.close();
|
|
lh.close();
|
|
} catch (KeeperException e) {
|
|
} catch (KeeperException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
@@ -258,71 +234,72 @@ public class BookieReadWriteTest
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
fail("Test failed due to interruption");
|
|
fail("Test failed due to interruption");
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void testSyncReadAsyncWriteStringsSingleClient() throws IOException{
|
|
|
|
|
|
+ public void testSyncReadAsyncWriteStringsSingleClient() throws IOException {
|
|
LOG.info("TEST READ WRITE STRINGS MIXED SINGLE CLIENT");
|
|
LOG.info("TEST READ WRITE STRINGS MIXED SINGLE CLIENT");
|
|
String charset = "utf-8";
|
|
String charset = "utf-8";
|
|
- LOG.debug("Default charset: " + Charset.defaultCharset());
|
|
|
|
|
|
+ LOG.debug("Default charset: " + Charset.defaultCharset());
|
|
try {
|
|
try {
|
|
// Create a BookKeeper client and a ledger
|
|
// Create a BookKeeper client and a ledger
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- //bkc.initMessageDigest("SHA1");
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ // bkc.initMessageDigest("SHA1");
|
|
ledgerId = lh.getId();
|
|
ledgerId = lh.getId();
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
- for(int i = 0; i < numEntriesToWrite; i++){
|
|
|
|
|
|
+ for (int i = 0; i < numEntriesToWrite; i++) {
|
|
int randomInt = rng.nextInt(maxInt);
|
|
int randomInt = rng.nextInt(maxInt);
|
|
byte[] entry = new String(Integer.toString(randomInt)).getBytes(charset);
|
|
byte[] entry = new String(Integer.toString(randomInt)).getBytes(charset);
|
|
entries.add(entry);
|
|
entries.add(entry);
|
|
lh.asyncAddEntry(entry, this, sync);
|
|
lh.asyncAddEntry(entry, this, sync);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// wait for all entries to be acknowledged
|
|
// wait for all entries to be acknowledged
|
|
synchronized (sync) {
|
|
synchronized (sync) {
|
|
- while (sync.counter < numEntriesToWrite){
|
|
|
|
|
|
+ while (sync.counter < numEntriesToWrite) {
|
|
LOG.debug("Entries counter = " + sync.counter);
|
|
LOG.debug("Entries counter = " + sync.counter);
|
|
sync.wait();
|
|
sync.wait();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("*** ASYNC WRITE COMPLETE ***");
|
|
LOG.debug("*** ASYNC WRITE COMPLETE ***");
|
|
- // close ledger
|
|
|
|
|
|
+ // close ledger
|
|
lh.close();
|
|
lh.close();
|
|
-
|
|
|
|
- //*** WRITING PART COMPLETED // READ PART BEGINS ***
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // *** WRITING PART COMPLETED // READ PART BEGINS ***
|
|
|
|
+
|
|
// open ledger
|
|
// open ledger
|
|
- lh = bkc.openLedger(ledgerId, ledgerPassword);
|
|
|
|
- LOG.debug("Number of entries written: " + lh.getLast());
|
|
|
|
- assertTrue("Verifying number of entries written", lh.getLast() == (numEntriesToWrite - 1));
|
|
|
|
-
|
|
|
|
- //read entries
|
|
|
|
|
|
+ lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
|
|
|
|
+ LOG.debug("Number of entries written: " + (lh.getLastAddConfirmed() + 1));
|
|
|
|
+ assertTrue("Verifying number of entries written", lh.getLastAddConfirmed() == (numEntriesToWrite - 1));
|
|
|
|
+
|
|
|
|
+ // read entries
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
-
|
|
|
|
- assertTrue("Checking number of read entries", ls.size() == numEntriesToWrite);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("*** SYNC READ COMPLETE ***");
|
|
LOG.debug("*** SYNC READ COMPLETE ***");
|
|
-
|
|
|
|
- // at this point, LedgerSequence ls is filled with the returned values
|
|
|
|
|
|
+
|
|
|
|
+ // at this point, LedgerSequence ls is filled with the returned
|
|
|
|
+ // values
|
|
int i = 0;
|
|
int i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
byte[] origEntryBytes = entries.get(i++);
|
|
byte[] origEntryBytes = entries.get(i++);
|
|
byte[] retrEntryBytes = ls.nextElement().getEntry();
|
|
byte[] retrEntryBytes = ls.nextElement().getEntry();
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("Original byte entry size: " + origEntryBytes.length);
|
|
LOG.debug("Original byte entry size: " + origEntryBytes.length);
|
|
LOG.debug("Saved byte entry size: " + retrEntryBytes.length);
|
|
LOG.debug("Saved byte entry size: " + retrEntryBytes.length);
|
|
-
|
|
|
|
|
|
+
|
|
String origEntry = new String(origEntryBytes, charset);
|
|
String origEntry = new String(origEntryBytes, charset);
|
|
String retrEntry = new String(retrEntryBytes, charset);
|
|
String retrEntry = new String(retrEntryBytes, charset);
|
|
-
|
|
|
|
|
|
+
|
|
LOG.debug("Original entry: " + origEntry);
|
|
LOG.debug("Original entry: " + origEntry);
|
|
LOG.debug("Retrieved entry: " + retrEntry);
|
|
LOG.debug("Retrieved entry: " + retrEntry);
|
|
-
|
|
|
|
|
|
+
|
|
assertTrue("Checking entry " + i + " for equality", origEntry.equals(retrEntry));
|
|
assertTrue("Checking entry " + i + " for equality", origEntry.equals(retrEntry));
|
|
}
|
|
}
|
|
|
|
+ assertTrue("Checking number of read entries", i == numEntriesToWrite);
|
|
|
|
+
|
|
lh.close();
|
|
lh.close();
|
|
} catch (KeeperException e) {
|
|
} catch (KeeperException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
@@ -333,34 +310,34 @@ public class BookieReadWriteTest
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
fail("Test failed due to interruption");
|
|
fail("Test failed due to interruption");
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testReadWriteSyncSingleClient() throws IOException {
|
|
public void testReadWriteSyncSingleClient() throws IOException {
|
|
try {
|
|
try {
|
|
// Create a BookKeeper client and a ledger
|
|
// Create a BookKeeper client and a ledger
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- //bkc.initMessageDigest("SHA1");
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ // bkc.initMessageDigest("SHA1");
|
|
ledgerId = lh.getId();
|
|
ledgerId = lh.getId();
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
- for(int i = 0; i < numEntriesToWrite; i++){
|
|
|
|
|
|
+ for (int i = 0; i < numEntriesToWrite; i++) {
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.position(0);
|
|
entry.position(0);
|
|
- entries.add(entry.array());
|
|
|
|
|
|
+ entries.add(entry.array());
|
|
lh.addEntry(entry.array());
|
|
lh.addEntry(entry.array());
|
|
}
|
|
}
|
|
lh.close();
|
|
lh.close();
|
|
- lh = bkc.openLedger(ledgerId, ledgerPassword);
|
|
|
|
- LOG.debug("Number of entries written: " + lh.getLast());
|
|
|
|
- assertTrue("Verifying number of entries written", lh.getLast() == (numEntriesToWrite - 1));
|
|
|
|
-
|
|
|
|
|
|
+ lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
|
|
|
|
+ LOG.debug("Number of entries written: " + lh.getLastAddConfirmed());
|
|
|
|
+ assertTrue("Verifying number of entries written", lh.getLastAddConfirmed() == (numEntriesToWrite - 1));
|
|
|
|
+
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
int i = 0;
|
|
int i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
ByteBuffer origbb = ByteBuffer.wrap(entries.get(i++));
|
|
ByteBuffer origbb = ByteBuffer.wrap(entries.get(i++));
|
|
Integer origEntry = origbb.getInt();
|
|
Integer origEntry = origbb.getInt();
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
@@ -381,42 +358,42 @@ public class BookieReadWriteTest
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
fail("Test failed due to interruption");
|
|
fail("Test failed due to interruption");
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testReadWriteZero() throws IOException {
|
|
public void testReadWriteZero() throws IOException {
|
|
try {
|
|
try {
|
|
// Create a BookKeeper client and a ledger
|
|
// Create a BookKeeper client and a ledger
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- //bkc.initMessageDigest("SHA1");
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ // bkc.initMessageDigest("SHA1");
|
|
ledgerId = lh.getId();
|
|
ledgerId = lh.getId();
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
LOG.info("Ledger ID: " + lh.getId());
|
|
- for(int i = 0; i < numEntriesToWrite; i++){
|
|
|
|
- lh.addEntry(new byte[0]);
|
|
|
|
|
|
+ for (int i = 0; i < numEntriesToWrite; i++) {
|
|
|
|
+ lh.addEntry(new byte[0]);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Write a non-zero entry
|
|
* Write a non-zero entry
|
|
*/
|
|
*/
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
ByteBuffer entry = ByteBuffer.allocate(4);
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.putInt(rng.nextInt(maxInt));
|
|
entry.position(0);
|
|
entry.position(0);
|
|
- entries.add(entry.array());
|
|
|
|
- lh.addEntry( entry.array());
|
|
|
|
-
|
|
|
|
|
|
+ entries.add(entry.array());
|
|
|
|
+ lh.addEntry(entry.array());
|
|
|
|
+
|
|
lh.close();
|
|
lh.close();
|
|
- lh = bkc.openLedger(ledgerId, ledgerPassword);
|
|
|
|
- LOG.debug("Number of entries written: " + lh.getLast());
|
|
|
|
- assertTrue("Verifying number of entries written", lh.getLast() == numEntriesToWrite);
|
|
|
|
-
|
|
|
|
|
|
+ lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
|
|
|
|
+ LOG.debug("Number of entries written: " + lh.getLastAddConfirmed());
|
|
|
|
+ assertTrue("Verifying number of entries written", lh.getLastAddConfirmed() == numEntriesToWrite);
|
|
|
|
+
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
int i = 0;
|
|
int i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
-
|
|
|
|
|
|
+
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
}
|
|
}
|
|
lh.close();
|
|
lh.close();
|
|
@@ -429,52 +406,54 @@ public class BookieReadWriteTest
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
fail("Test failed due to interruption");
|
|
fail("Test failed due to interruption");
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testMultiLedger() throws IOException {
|
|
public void testMultiLedger() throws IOException {
|
|
try {
|
|
try {
|
|
// Create a BookKeeper client and a ledger
|
|
// Create a BookKeeper client and a ledger
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
bkc = new BookKeeper("127.0.0.1");
|
|
- lh = bkc.createLedger(ledgerPassword);
|
|
|
|
- lh2 = bkc.createLedger(ledgerPassword);
|
|
|
|
-
|
|
|
|
|
|
+ lh = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+ lh2 = bkc.createLedger(digestType, ledgerPassword);
|
|
|
|
+
|
|
long ledgerId = lh.getId();
|
|
long ledgerId = lh.getId();
|
|
long ledgerId2 = lh2.getId();
|
|
long ledgerId2 = lh2.getId();
|
|
-
|
|
|
|
- //bkc.initMessageDigest("SHA1");
|
|
|
|
|
|
+
|
|
|
|
+ // bkc.initMessageDigest("SHA1");
|
|
LOG.info("Ledger ID 1: " + lh.getId() + ", Ledger ID 2: " + lh2.getId());
|
|
LOG.info("Ledger ID 1: " + lh.getId() + ", Ledger ID 2: " + lh2.getId());
|
|
- for(int i = 0; i < numEntriesToWrite; i++){
|
|
|
|
- lh.addEntry( new byte[0]);
|
|
|
|
|
|
+ for (int i = 0; i < numEntriesToWrite; i++) {
|
|
|
|
+ lh.addEntry(new byte[0]);
|
|
lh2.addEntry(new byte[0]);
|
|
lh2.addEntry(new byte[0]);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
lh.close();
|
|
lh.close();
|
|
lh2.close();
|
|
lh2.close();
|
|
-
|
|
|
|
- lh = bkc.openLedger(ledgerId, ledgerPassword);
|
|
|
|
- lh2 = bkc.openLedger(ledgerId2, ledgerPassword);
|
|
|
|
-
|
|
|
|
- LOG.debug("Number of entries written: " + lh.getLast() + ", " + lh2.getLast());
|
|
|
|
- assertTrue("Verifying number of entries written lh (" + lh.getLast() + ")" , lh.getLast() == (numEntriesToWrite - 1));
|
|
|
|
- assertTrue("Verifying number of entries written lh2 (" + lh2.getLast() + ")", lh2.getLast() == (numEntriesToWrite - 1));
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ lh = bkc.openLedger(ledgerId, digestType, ledgerPassword);
|
|
|
|
+ lh2 = bkc.openLedger(ledgerId2, digestType, ledgerPassword);
|
|
|
|
+
|
|
|
|
+ LOG.debug("Number of entries written: " + lh.getLastAddConfirmed() + ", " + lh2.getLastAddConfirmed());
|
|
|
|
+ assertTrue("Verifying number of entries written lh (" + lh.getLastAddConfirmed() + ")", lh
|
|
|
|
+ .getLastAddConfirmed() == (numEntriesToWrite - 1));
|
|
|
|
+ assertTrue("Verifying number of entries written lh2 (" + lh2.getLastAddConfirmed() + ")", lh2
|
|
|
|
+ .getLastAddConfirmed() == (numEntriesToWrite - 1));
|
|
|
|
+
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
ls = lh.readEntries(0, numEntriesToWrite - 1);
|
|
int i = 0;
|
|
int i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
-
|
|
|
|
|
|
+
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
}
|
|
}
|
|
lh.close();
|
|
lh.close();
|
|
- ls = lh2.readEntries( 0, numEntriesToWrite - 1);
|
|
|
|
|
|
+ ls = lh2.readEntries(0, numEntriesToWrite - 1);
|
|
i = 0;
|
|
i = 0;
|
|
- while(ls.hasMoreElements()){
|
|
|
|
|
|
+ while (ls.hasMoreElements()) {
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
ByteBuffer result = ByteBuffer.wrap(ls.nextElement().getEntry());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
LOG.debug("Length of result: " + result.capacity());
|
|
-
|
|
|
|
|
|
+
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
assertTrue("Checking if entry " + i + " has zero bytes", result.capacity() == 0);
|
|
}
|
|
}
|
|
lh2.close();
|
|
lh2.close();
|
|
@@ -487,14 +466,10 @@ public class BookieReadWriteTest
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
LOG.error("Test failed", e);
|
|
LOG.error("Test failed", e);
|
|
fail("Test failed due to interruption");
|
|
fail("Test failed due to interruption");
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- public void addComplete(int rc,
|
|
|
|
- LedgerHandle lh,
|
|
|
|
- long entryId,
|
|
|
|
- Object ctx) {
|
|
|
|
|
|
+
|
|
|
|
+ public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
|
|
SyncObj x = (SyncObj) ctx;
|
|
SyncObj x = (SyncObj) ctx;
|
|
synchronized (x) {
|
|
synchronized (x) {
|
|
x.counter++;
|
|
x.counter++;
|
|
@@ -502,135 +477,45 @@ public class BookieReadWriteTest
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void readComplete(int rc,
|
|
|
|
- LedgerHandle lh,
|
|
|
|
- LedgerSequence seq,
|
|
|
|
- Object ctx) {
|
|
|
|
- ls = seq;
|
|
|
|
|
|
+ public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx) {
|
|
|
|
+ ls = seq;
|
|
synchronized (sync) {
|
|
synchronized (sync) {
|
|
sync.value = true;
|
|
sync.value = true;
|
|
sync.notify();
|
|
sync.notify();
|
|
}
|
|
}
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected void setUp() throws IOException, InterruptedException {
|
|
|
|
- LOG.addAppender(ca);
|
|
|
|
- LOG.setLevel((Level) Level.DEBUG);
|
|
|
|
-
|
|
|
|
- // create a ZooKeeper server(dataDir, dataLogDir, port)
|
|
|
|
- LOG.debug("Running ZK server");
|
|
|
|
- //ServerStats.registerAsConcrete();
|
|
|
|
- ClientBase.setupTestEnv();
|
|
|
|
- ZkTmpDir = File.createTempFile("zookeeper", "test");
|
|
|
|
- ZkTmpDir.delete();
|
|
|
|
- ZkTmpDir.mkdir();
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
|
|
|
|
- serverFactory = new NIOServerCnxn.Factory(ZooKeeperDefaultPort);
|
|
|
|
- serverFactory.startup(zks);
|
|
|
|
- } catch (IOException e1) {
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
- e1.printStackTrace();
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- boolean b = ClientBase.waitForServerUp(HOSTPORT, ClientBase.CONNECTION_TIMEOUT);
|
|
|
|
-
|
|
|
|
- LOG.debug("Server up: " + b);
|
|
|
|
-
|
|
|
|
- // create a zookeeper client
|
|
|
|
- LOG.debug("Instantiate ZK Client");
|
|
|
|
- zkc = new ZooKeeper("127.0.0.1", ZooKeeperDefaultPort, new emptyWatcher());
|
|
|
|
-
|
|
|
|
- //initialize the zk client with values
|
|
|
|
- try {
|
|
|
|
- zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
|
- zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
|
- zkc.create("/ledgers/available/127.0.0.1:" + Integer.toString(initialPort), new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
|
- zkc.create("/ledgers/available/127.0.0.1:" + Integer.toString(initialPort + 1), new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
|
- zkc.create("/ledgers/available/127.0.0.1:" + Integer.toString(initialPort + 2), new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
|
- } catch (KeeperException e) {
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Create Bookie Servers (B1, B2, B3)
|
|
|
|
- tmpDirB1 = File.createTempFile("bookie1", "test");
|
|
|
|
- tmpDirB1.delete();
|
|
|
|
- tmpDirB1.mkdir();
|
|
|
|
-
|
|
|
|
- bs1 = new BookieServer(initialPort, tmpDirB1, new File[]{tmpDirB1});
|
|
|
|
- bs1.start();
|
|
|
|
-
|
|
|
|
- tmpDirB2 = File.createTempFile("bookie2", "test");
|
|
|
|
- tmpDirB2.delete();
|
|
|
|
- tmpDirB2.mkdir();
|
|
|
|
-
|
|
|
|
- bs2 = new BookieServer(initialPort + 1, tmpDirB2, new File[]{tmpDirB2});
|
|
|
|
- bs2.start();
|
|
|
|
-
|
|
|
|
- tmpDirB3 = File.createTempFile("bookie3", "test");
|
|
|
|
- tmpDirB3.delete();
|
|
|
|
- tmpDirB3.mkdir();
|
|
|
|
-
|
|
|
|
- bs3 = new BookieServer(initialPort + 2, tmpDirB3, new File[]{tmpDirB3});
|
|
|
|
- bs3.start();
|
|
|
|
-
|
|
|
|
- rng = new Random(System.currentTimeMillis()); // Initialize the Random Number Generator
|
|
|
|
- entries = new ArrayList<byte[]>(); // initialize the entries list
|
|
|
|
- entriesSize = new ArrayList<Integer>();
|
|
|
|
- sync = new SyncObj(); // initialize the synchronization data structure
|
|
|
|
- zkc.close();
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- protected void tearDown(){
|
|
|
|
- LOG.info("TearDown");
|
|
|
|
|
|
|
|
- //shutdown bookie servers
|
|
|
|
- try {
|
|
|
|
- bs1.shutdown();
|
|
|
|
- bs2.shutdown();
|
|
|
|
- bs3.shutdown();
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- cleanUpDir(tmpDirB1);
|
|
|
|
- cleanUpDir(tmpDirB2);
|
|
|
|
- cleanUpDir(tmpDirB3);
|
|
|
|
-
|
|
|
|
- //shutdown ZK server
|
|
|
|
- serverFactory.shutdown();
|
|
|
|
- assertTrue("waiting for server down",
|
|
|
|
- ClientBase.waitForServerDown(HOSTPORT,
|
|
|
|
- ClientBase.CONNECTION_TIMEOUT));
|
|
|
|
- //ServerStats.unregister();
|
|
|
|
- cleanUpDir(ZkTmpDir);
|
|
|
|
|
|
+ @Before
|
|
|
|
+ public void setUp() throws Exception{
|
|
|
|
+ super.setUp();
|
|
|
|
+ rng = new Random(System.currentTimeMillis()); // Initialize the Random
|
|
|
|
+ // Number Generator
|
|
|
|
+ entries = new ArrayList<byte[]>(); // initialize the entries list
|
|
|
|
+ entriesSize = new ArrayList<Integer>();
|
|
|
|
+ sync = new SyncObj(); // initialize the synchronization data structure
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /* Clean up a directory recursively */
|
|
|
|
- protected boolean cleanUpDir(File dir){
|
|
|
|
|
|
+ /* Clean up a directory recursively */
|
|
|
|
+ protected boolean cleanUpDir(File dir) {
|
|
if (dir.isDirectory()) {
|
|
if (dir.isDirectory()) {
|
|
LOG.info("Cleaning up " + dir.getName());
|
|
LOG.info("Cleaning up " + dir.getName());
|
|
String[] children = dir.list();
|
|
String[] children = dir.list();
|
|
for (String string : children) {
|
|
for (String string : children) {
|
|
boolean success = cleanUpDir(new File(dir, string));
|
|
boolean success = cleanUpDir(new File(dir, string));
|
|
- if (!success) return false;
|
|
|
|
|
|
+ if (!success)
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// The directory is now empty so delete it
|
|
// The directory is now empty so delete it
|
|
- return dir.delete();
|
|
|
|
|
|
+ return dir.delete();
|
|
}
|
|
}
|
|
|
|
|
|
- /* User for testing purposes, void */
|
|
|
|
- class emptyWatcher implements Watcher{
|
|
|
|
- public void process(WatchedEvent event) {}
|
|
|
|
|
|
+ /* User for testing purposes, void */
|
|
|
|
+ class emptyWatcher implements Watcher {
|
|
|
|
+ public void process(WatchedEvent event) {
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|