26
28
import com.persistit.exception.InUseException;
27
29
import com.persistit.exception.InvalidKeyException;
28
30
import com.persistit.exception.PersistitException;
31
import com.persistit.unit.UnitTestProperties;
30
33
public class ExchangeLockTest extends PersistitUnitTestCase {
31
34
private final static long DMILLIS = SharedResource.DEFAULT_MAX_WAIT_TIME;
32
35
private final Semaphore _coordinator = new Semaphore(0);
38
public Properties getProperties(final boolean cleanup) {
39
return UnitTestProperties.getBiggerProperties(cleanup);
35
43
public void singleThreadedLock() throws Exception {
36
44
final Exchange ex = _persistit.getExchange("persistit", "ExchangeLockTest", true);
231
239
assertEquals(1, succeeded);
243
* This test is intended to exercise lock management for transactions
244
* executed sequentially, each of which performs lots of locks (similar to
235
250
public void lockTablePruning() throws Exception {
236
251
final Exchange ex = _persistit.getExchange("persistit", "ExchangeLockTest", true);
252
final Random random = new Random();
237
253
final Transaction txn = ex.getTransaction();
239
for (int i = 0; i < 10000; i++) {
240
ex.clear().append(i).append(RED_FOX).lock();
254
for (int j = 0; j < 100; j++) {
256
for (int i = 0; i < 10000; i++) {
257
final int k = random.nextInt(100000);
258
ex.clear().append(k + (j * 100000)).append(RED_FOX).lock();
263
assertTrue("Too many lock volume pages uses",
264
_persistit.getLockVolume().getStorage().getNextAvailablePage() < 100);
245
266
final Exchange lockExchange = new Exchange(_persistit.getLockVolume().getTree("ExchangeLockTest", false));
246
lockExchange.ignoreMVCCFetch(true);
248
final int count1 = keyCount(lockExchange);
249
assertTrue(count1 > 0);
251
_persistit.getTransactionIndex().updateActiveTransactionCache();
253
for (int i = 0; i < 10000; i++) {
254
lockExchange.clear().append(i).append(RED_FOX).prune();
257
final int count2 = keyCount(lockExchange);
258
assertTrue(count2 < count1);
260
_persistit.getCleanupManager().poll();
262
final int count3 = keyCount(lockExchange);
263
assertEquals(0, count3);
267
final int count = keyCount(lockExchange);
269
assertEquals("Unpruned lock records", 0, count);
267
272
private int keyCount(final Exchange ex) throws PersistitException {