/* Create with legal range values. */
config.setRange(1, 2);
config.setInitialValue(1);
config.setCacheSize(0);
Sequence seq = db.openSequence(txn, key, config);
/* Key must not exist if ExclusiveCreate=true. */
config.setExclusiveCreate(true);
try {
db.openSequence(txn, key, config);
fail();
} catch (DatabaseException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("already exists") >= 0);
}
config.setExclusiveCreate(false);
seq.close();
/* Key must exist if AllowCreate=false. */
db.removeSequence(txn, key);
config.setAllowCreate(false);
try {
db.openSequence(txn, key, config);
fail();
} catch (DatabaseException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("does not exist") >= 0);
}
/* Check wrapping not allowed. */
db.removeSequence(txn, key);
config.setAllowCreate(true);
config.setRange(-5, 5);
config.setInitialValue(-5);
seq = db.openSequence(txn, key, config);
for (long i = config.getRangeMin(); i <= config.getRangeMax(); i++) {
assertEquals(i, seq.get(txn, 1));
}
try {
seq.get(txn, 1);
fail();
} catch (DatabaseException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("overflow") >= 0);
}
/* Check wrapping not allowed, decrement. */
db.removeSequence(txn, key);
config.setAllowCreate(true);
config.setAllowCreate(true);
config.setRange(-5, 5);
config.setInitialValue(5);
config.setDecrement(true);
seq = db.openSequence(txn, key, config);
for (long i = config.getRangeMax(); i >= config.getRangeMin(); i--) {
assertEquals(i, seq.get(txn, 1));
}
try {
seq.get(txn, 1);
fail();
} catch (DatabaseException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("overflow") >= 0);
}
/* Check delta less than one. */
try {
seq.get(txn, 0);
fail();
} catch (IllegalArgumentException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("greater than zero") >= 0);
}
/* Check delta greater than range. */
try {
seq.get(txn, 11);
fail();
} catch (IllegalArgumentException expected) {
String msg = expected.getMessage();
assertTrue(msg, msg.indexOf("larger than the range") >= 0);
}
seq.close();
txnCommit(txn);
db.close();
}