Search in sources :

Example 1 with LockingConfiguration

use of com.walmartlabs.concord.server.cfg.LockingConfiguration in project concord by walmartlabs.

the class KvDaoTest method test.

@Test
public void test() throws Exception {
    assertTimeout(Duration.ofMillis(10000), () -> {
        KvDao kvDao = new KvDao(getConfiguration(), new Locks(new LockingConfiguration(8)));
        UUID projectId = UUID.randomUUID();
        String key = "key_" + System.currentTimeMillis();
        int threads = 3;
        int iterations = 50;
        AtomicLong counter = new AtomicLong(0);
        Runnable r = () -> {
            for (int i = 0; i < iterations; i++) {
                kvDao.inc(projectId, key);
                counter.incrementAndGet();
            }
        };
        Thread[] workes = new Thread[threads];
        for (int i = 0; i < threads; i++) {
            workes[i] = new Thread(r);
            workes[i].start();
        }
        for (Thread w : workes) {
            w.join();
        }
        Long total = counter.get();
        assertEquals(total, kvDao.getLong(projectId, key));
    });
}
Also used : KvDao(com.walmartlabs.concord.server.org.project.KvDao) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Locks(com.walmartlabs.concord.server.Locks) UUID(java.util.UUID) LockingConfiguration(com.walmartlabs.concord.server.cfg.LockingConfiguration) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Aggregations

AbstractDaoTest (com.walmartlabs.concord.server.AbstractDaoTest)1 Locks (com.walmartlabs.concord.server.Locks)1 LockingConfiguration (com.walmartlabs.concord.server.cfg.LockingConfiguration)1 KvDao (com.walmartlabs.concord.server.org.project.KvDao)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.jupiter.api.Test)1