/**
* Copyright 2011-2012 Akiban Technologies, Inc.
*
* Licensed 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 com.persistit;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class Bug877656Test extends PersistitUnitTestCase {
@Test
public void testForward() throws Exception {
final Transaction txn = _persistit.getTransaction();
txn.begin();
final Exchange ex = _persistit.getExchange("persistit", "Bug877656Test", true);
for (int i = 1; i < 10; i++) {
ex.to(i).store();
}
txn.commit();
txn.end();
// ----------
txn.begin();
for (int i = 1; i < 10; i++) {
ex.to(i).remove();
}
ex.to(0);
int count = 0;
for (; count < 10; count++) {
if (!ex.traverse(Key.GTEQ, true)) {
break;
}
}
assertEquals("{{before}}", ex.getKey().toString());
txn.commit();
txn.end();
assertEquals(0, count);
}
@Test
public void testReverse() throws Exception {
final Transaction txn = _persistit.getTransaction();
txn.begin();
final Exchange ex = _persistit.getExchange("persistit", "Bug877656Test", true);
for (int i = 1; i < 10; i++) {
ex.to(i).store();
}
txn.commit();
txn.end();
// ----------
txn.begin();
for (int i = 1; i < 10; i++) {
ex.to(i).remove();
}
ex.to(11);
int count = 0;
for (; count < 10; count++) {
if (!ex.traverse(Key.LTEQ, true)) {
break;
}
}
assertEquals("{{after}}", ex.getKey().toString());
txn.commit();
txn.end();
assertEquals(0, count);
}
}