resolved JIRA issue 536

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@394214 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Vajda 2006-04-14 22:23:20 +00:00
parent 0065df6858
commit 597b011b27
2 changed files with 265 additions and 40 deletions

View File

@ -192,8 +192,12 @@ public class File extends Object {
if (cursor.getSearchKey(cursorKey, cursorData, null) != OperationStatus.NOTFOUND) {
cursor.delete();
while (cursor.getNextDup(cursorKey, cursorData, null) != OperationStatus.NOTFOUND) {
advance: while (cursor.getNext(cursorKey, cursorData, null) != OperationStatus.NOTFOUND) {
byte[] temp = cursorKey.getData();
for (int i = 0; i < bytes.length; i++)
if (bytes[i] != temp[i]) {
break advance;
}
cursor.delete();
}
}

View File

@ -27,29 +27,34 @@ import junit.framework.TestCase;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.je.JEDirectory;
import com.sleepycat.je.Cursor;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.Transaction;
/**
* Tests {@link JEDirectory}.
*
* Adapted from Andi Vajda's org.apache.lucene.db.DbStoreTest.
*
* @author Aaron Donovan
*/
public class JEStoreTest extends TestCase {
protected File dbHome = new File("index");
protected Environment env;
protected Database index, blocks;
public void setUp()
throws Exception
{
public void setUp() throws Exception {
if (!dbHome.exists())
dbHome.mkdir();
else {
@ -79,8 +84,7 @@ public class JEStoreTest extends TestCase {
index = env.openDatabase(txn, "__index__", dbConfig);
blocks = env.openDatabase(txn, "__blocks__", dbConfig);
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -94,9 +98,8 @@ public class JEStoreTest extends TestCase {
}
}
public void tearDown()
throws Exception
{
public void tearDown() throws Exception {
if (index != null)
index.close();
if (blocks != null)
@ -105,9 +108,7 @@ public class JEStoreTest extends TestCase {
env.close();
}
public void testBytes()
throws Exception
{
public void tesBytes() throws Exception {
final int count = 250;
final int LENGTH_MASK = 0xffff;
@ -146,8 +147,7 @@ public class JEStoreTest extends TestCase {
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -196,8 +196,7 @@ public class JEStoreTest extends TestCase {
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -233,8 +232,7 @@ public class JEStoreTest extends TestCase {
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -255,9 +253,236 @@ public class JEStoreTest extends TestCase {
System.out.println(" total milliseconds");
}
public void testArrays()
throws Exception
{
public void testDelete() throws Exception {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random gen = new Random(1251971);
int totalLength = 0;
int duration;
Date end;
Date veryStart = new Date();
Date start = new Date();
Transaction txn = null;
Directory store = null;
System.out.println("Writing files byte by byte");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
for (int i = 0; i < count; i++) {
String name = i + ".dat";
int length = gen.nextInt() & LENGTH_MASK;
IndexOutput file = store.createOutput(name);
totalLength += length;
for (int j = 0; j < length; j++) {
byte b = (byte) (gen.nextInt() & 0x7F);
file.writeByte(b);
}
file.close();
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to read, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(1251971);
start = new Date();
for (int i = 0; i < count; i++) {
if (i % 2 == 0) {
String name = i + ".dat";
store.deleteFile(name);
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
System.out.print(end.getTime() - start.getTime());
System.out.println(" total milliseconds to delete even files");
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to create, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(1251971);
start = new Date();
for (int i = 0; i < count; i++) {
int length = gen.nextInt() & LENGTH_MASK;
if (i % 2 != 0) {
String name = i + ".dat";
IndexInput file = store.openInput(name);
if (file.length() != length)
throw new Exception("length incorrect");
for (int j = 0; j < length; j++) {
byte b = (byte) (gen.nextInt() & 0x7F);
if (file.readByte() != b)
throw new Exception("contents incorrect");
}
file.close();
} else {
for (int j = 0; j < length; j++) {
gen.nextInt();
}
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to read, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(1251971);
start = new Date();
for (int i = 0; i < count; i++) {
if (i % 2 != 0) {
String name = i + ".dat";
store.deleteFile(name);
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
System.out.print(end.getTime() - start.getTime());
System.out.println(" total milliseconds to delete");
System.out.print(end.getTime() - veryStart.getTime());
System.out.println(" total milliseconds");
Cursor cursor = null;
try {
cursor = index.openCursor(null, null);
DatabaseEntry foundKey = new DatabaseEntry();
DatabaseEntry foundData = new DatabaseEntry();
if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
fail("index database is not empty");
}
} catch (DatabaseException e) {
throw e;
} finally {
if (cursor != null)
cursor.close();
}
cursor = null;
try {
cursor = blocks.openCursor(null, null);
DatabaseEntry foundKey = new DatabaseEntry();
DatabaseEntry foundData = new DatabaseEntry();
if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
fail("blocks database is not empty");
}
} catch (DatabaseException e) {
throw e;
} finally {
if (cursor != null)
cursor.close();
}
}
public void tesArrays() throws Exception {
final int count = 250;
final int LENGTH_MASK = 0xffff;
@ -294,8 +519,7 @@ public class JEStoreTest extends TestCase {
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -345,8 +569,7 @@ public class JEStoreTest extends TestCase {
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -372,18 +595,17 @@ public class JEStoreTest extends TestCase {
gen = new Random(1251971);
start = new Date();
for (int i = 0; i < count; i++) {
String name = i + ".dat";
store.deleteFile(name);
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null)
{
if (txn != null) {
txn.abort();
txn = null;
}
@ -404,4 +626,3 @@ public class JEStoreTest extends TestCase {
System.out.println(" total milliseconds");
}
}