Here's a test case. On my machine, this generally fails in the early part of the read cycle, but sometimes fails during the initial write, and sometimes doesn't fail at all, and a reboot of the machine may prompt the next run to produce a failure.
I started with something more complicated and have been whittling down, and I think there can be more whittling....
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.collections.StoredMap;
import com.sleepycat.je.*;
import java.io.File;
import java.util.Random;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;
public class JETester {
private static final int ITEM_COUNT = 10 * 1000 * 1000;
private static final int BATCH_SIZE = 10 * 1000;
private static final String DB_NAME = "test";
private static final Random RANDOM = new Random();
private static final File DB_LOCATION = new File("H:
temp");
public static void main(final String[] args) throws DatabaseException, InterruptedException {
{
log("starting write cycle");
final File databaseDirectory = DB_LOCATION;
final Environment environment = setupEnvironment(databaseDirectory);
final Database database = getDatabase(environment);
final StoredMap<String,String> storedMap = setupMap(database);
populateMap(storedMap, ITEM_COUNT);
for (int i = 0; i <= ITEM_COUNT; i++ ) {
storedMap.get(String.valueOf(i).toLowerCase());
if (i % (BATCH_SIZE * 10) == 0) log("read tick-" + i);
}
database.close();
environment.truncateDatabase(null, DB_NAME, false);
environment.close();
log("read complete");
}
}
private static void populateMap(final StoredMap<String, String> storedMap, final int size) {
Map<String,String> buffer = new HashMap<String,String>();
int counter = 0;
while (counter < size) {
while (buffer.size() < BATCH_SIZE && counter < size) {
buffer.put(String.valueOf(counter++),randomStringValue(RANDOM.nextInt(256) + 256));
}
storedMap.putAll(buffer);
buffer.clear();
if (counter % (BATCH_SIZE * 10) == 0) log("write tick-" + counter);
}
}
private static void log(String str) {
System.out.println(SimpleDateFormat.getInstance().format(new Date()) + " " + str);
}
private static String randomStringValue(int length) {
StringBuilder sb = new StringBuilder();
while (sb.length() < length) sb.append((char)(RANDOM.nextInt(26) + 32) );
return sb.toString();
}
private static Database getDatabase(Environment environment) throws DatabaseException {
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
return environment.openDatabase(null, DB_NAME, dbConfig);
}
private static Environment setupEnvironment(File databaseDirectory) throws DatabaseException {
final EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setAllowCreate(true);
environmentConfig.setConfigParam(EnvironmentConfig.MAX_MEMORY, String.valueOf(10 * 1000 * 1000 ));
environmentConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, String.valueOf(10 * 1000 * 1000));
environmentConfig.setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "80");
environmentConfig.setConfigParam(EnvironmentConfig.LOG_VERIFY_CHECKSUMS, "true");
return new Environment(databaseDirectory, environmentConfig);
}
private static StoredMap<String,String> setupMap(final Database database) throws DatabaseException {
final TupleBinding<String> stringBinding = TupleBinding.getPrimitiveBinding(String.class);
return new StoredMap<String,String>(database, stringBinding, stringBinding, true);
}
}