~akiban-technologies/akiban-persistit/3.2.9

« back to all changes in this revision

Viewing changes to src/test/java/com/persistit/ExchangeLockTest.java

merge pbeaman: Fixes bug1126868.

https://code.launchpad.net/~pbeaman/akiban-persistit/fix-1126868-lock-table-pruning/+merge/152063

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import static org.junit.Assert.assertTrue;
20
20
import static org.junit.Assert.fail;
21
21
 
 
22
import java.util.Properties;
 
23
import java.util.Random;
22
24
import java.util.concurrent.Semaphore;
23
25
 
24
26
import org.junit.Test;
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;
29
32
 
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);
33
36
 
 
37
    @Override
 
38
    public Properties getProperties(final boolean cleanup) {
 
39
        return UnitTestProperties.getBiggerProperties(cleanup);
 
40
    }
 
41
 
34
42
    @Test
35
43
    public void singleThreadedLock() throws Exception {
36
44
        final Exchange ex = _persistit.getExchange("persistit", "ExchangeLockTest", true);
231
239
        assertEquals(1, succeeded);
232
240
    }
233
241
 
 
242
    /**
 
243
     * This test is intended to exercise lock management for transactions
 
244
     * executed sequentially, each of which performs lots of locks (similar to
 
245
     * DataLoadingTest.)
 
246
     * 
 
247
     * @throws Exception
 
248
     */
234
249
    @Test
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();
238
 
        txn.begin();
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++) {
 
255
            txn.begin();
 
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();
 
259
            }
 
260
            txn.commit();
 
261
            txn.end();
241
262
        }
242
 
        txn.commit();
243
 
        txn.end();
 
263
        assertTrue("Too many lock volume pages uses",
 
264
                _persistit.getLockVolume().getStorage().getNextAvailablePage() < 100);
244
265
 
245
266
        final Exchange lockExchange = new Exchange(_persistit.getLockVolume().getTree("ExchangeLockTest", false));
246
 
        lockExchange.ignoreMVCCFetch(true);
247
 
 
248
 
        final int count1 = keyCount(lockExchange);
249
 
        assertTrue(count1 > 0);
250
 
 
251
 
        _persistit.getTransactionIndex().updateActiveTransactionCache();
252
 
 
253
 
        for (int i = 0; i < 10000; i++) {
254
 
            lockExchange.clear().append(i).append(RED_FOX).prune();
255
 
        }
256
 
 
257
 
        final int count2 = keyCount(lockExchange);
258
 
        assertTrue(count2 < count1);
259
 
 
260
 
        _persistit.getCleanupManager().poll();
261
 
 
262
 
        final int count3 = keyCount(lockExchange);
263
 
        assertEquals(0, count3);
264
 
 
 
267
        final int count = keyCount(lockExchange);
 
268
 
 
269
        assertEquals("Unpruned lock records", 0, count);
265
270
    }
266
271
 
267
272
    private int keyCount(final Exchange ex) throws PersistitException {