Search in sources :

Example 6 with InProcessLockProvider

use of org.apache.hudi.client.transaction.lock.InProcessLockProvider in project hudi by apache.

the class TestInProcessLockProvider method testRedundantUnlock.

@Test
public void testRedundantUnlock() {
    InProcessLockProvider inProcessLockProvider = new InProcessLockProvider(lockConfiguration, hadoopConfiguration);
    assertDoesNotThrow(() -> {
        inProcessLockProvider.lock();
    });
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
}
Also used : InProcessLockProvider(org.apache.hudi.client.transaction.lock.InProcessLockProvider) Test(org.junit.jupiter.api.Test)

Example 7 with InProcessLockProvider

use of org.apache.hudi.client.transaction.lock.InProcessLockProvider in project hudi by apache.

the class TestInProcessLockProvider method testLockReAcquisitionByDifferentThread.

@Test
public void testLockReAcquisitionByDifferentThread() {
    InProcessLockProvider inProcessLockProvider = new InProcessLockProvider(lockConfiguration, hadoopConfiguration);
    final AtomicBoolean writer2Completed = new AtomicBoolean(false);
    // Main test thread
    assertDoesNotThrow(() -> {
        inProcessLockProvider.lock();
    });
    // Another writer thread in parallel, should block
    // and later acquire the lock once it is released
    Thread writer2 = new Thread(new Runnable() {

        @Override
        public void run() {
            assertDoesNotThrow(() -> {
                inProcessLockProvider.lock();
            });
            assertDoesNotThrow(() -> {
                inProcessLockProvider.unlock();
            });
            writer2Completed.set(true);
        }
    });
    writer2.start();
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
    try {
        writer2.join();
    } catch (InterruptedException e) {
    // 
    }
    Assertions.assertTrue(writer2Completed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InProcessLockProvider(org.apache.hudi.client.transaction.lock.InProcessLockProvider) Test(org.junit.jupiter.api.Test)

Example 8 with InProcessLockProvider

use of org.apache.hudi.client.transaction.lock.InProcessLockProvider in project hudi by apache.

the class TestInProcessLockProvider method testLockReAcquisitionBySameThread.

@Test
public void testLockReAcquisitionBySameThread() {
    InProcessLockProvider inProcessLockProvider = new InProcessLockProvider(lockConfiguration, hadoopConfiguration);
    assertDoesNotThrow(() -> {
        inProcessLockProvider.lock();
    });
    assertThrows(HoodieLockException.class, () -> {
        inProcessLockProvider.lock();
    });
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
}
Also used : InProcessLockProvider(org.apache.hudi.client.transaction.lock.InProcessLockProvider) Test(org.junit.jupiter.api.Test)

Example 9 with InProcessLockProvider

use of org.apache.hudi.client.transaction.lock.InProcessLockProvider in project hudi by apache.

the class TestInProcessLockProvider method testTryLockReAcquisitionByDifferentThread.

@Test
public void testTryLockReAcquisitionByDifferentThread() {
    InProcessLockProvider inProcessLockProvider = new InProcessLockProvider(lockConfiguration, hadoopConfiguration);
    final AtomicBoolean writer2Completed = new AtomicBoolean(false);
    // Main test thread
    Assertions.assertTrue(inProcessLockProvider.tryLock());
    // Another writer thread
    Thread writer2 = new Thread(() -> {
        Assertions.assertFalse(inProcessLockProvider.tryLock(100L, TimeUnit.MILLISECONDS));
        writer2Completed.set(true);
    });
    writer2.start();
    try {
        writer2.join();
    } catch (InterruptedException e) {
    // 
    }
    Assertions.assertTrue(writer2Completed.get());
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InProcessLockProvider(org.apache.hudi.client.transaction.lock.InProcessLockProvider) Test(org.junit.jupiter.api.Test)

Example 10 with InProcessLockProvider

use of org.apache.hudi.client.transaction.lock.InProcessLockProvider in project hudi by apache.

the class TestInProcessLockProvider method testTryLockAcquisition.

@Test
public void testTryLockAcquisition() {
    InProcessLockProvider inProcessLockProvider = new InProcessLockProvider(lockConfiguration, hadoopConfiguration);
    Assertions.assertTrue(inProcessLockProvider.tryLock());
    assertDoesNotThrow(() -> {
        inProcessLockProvider.unlock();
    });
}
Also used : InProcessLockProvider(org.apache.hudi.client.transaction.lock.InProcessLockProvider) Test(org.junit.jupiter.api.Test)

Aggregations

InProcessLockProvider (org.apache.hudi.client.transaction.lock.InProcessLockProvider)11 Test (org.junit.jupiter.api.Test)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 CountDownLatch (java.util.concurrent.CountDownLatch)1