Search in sources :

Example 11 with DLockService

use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.

the class DistributedLockServiceDUnitTest method isLockGrantor.

/**
   * Accessed via reflection. DO NOT REMOVE.
   * 
   * @param serviceName
   * @return
   */
public static Boolean isLockGrantor(String serviceName) {
    DLockService service = (DLockService) DistributedLockService.getServiceNamed(serviceName);
    assertNotNull(service);
    Boolean result = Boolean.valueOf(service.isLockGrantor());
    logInfo("In isLockGrantor: " + result);
    return result;
}
Also used : DLockService(org.apache.geode.distributed.internal.locks.DLockService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 12 with DLockService

use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.

the class DistributedLockServiceDUnitTest method testGrantTokenCleanup.

// static volatile boolean startedThreadVM2_testTokenCleanup;
// static volatile boolean finishedThreadVM2_testTokenCleanup;
// static volatile DLockToken grantorDLockToken_testTokenCleanup;
@Test
public void testGrantTokenCleanup() throws Exception {
    final String dlsName = getUniqueName();
    final VM vmGrantor = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    // final VM vm2 = Host.getHost(0).getVM(2);
    final String key1 = "key1";
    // vmGrantor creates grantor
    vmGrantor.invoke(new SerializableRunnable() {

        public void run() {
            LogWriterUtils.getLogWriter().info("[testGrantTokenCleanup] vmGrantor creates grantor");
            connectDistributedSystem();
            DistributedLockService dls = DistributedLockService.create(dlsName, getSystem());
            assertTrue(dls.lock(key1, -1, -1));
            assertTrue(dls.isLockGrantor());
            DLockGrantor grantor = ((DLockService) dls).getGrantor();
            assertNotNull(grantor);
            DLockGrantor.DLockGrantToken grantToken = grantor.getGrantToken(key1);
            assertNotNull(grantToken);
            LogWriterUtils.getLogWriter().info("[testGrantTokenCleanup] vmGrantor unlocks key1");
            dls.unlock(key1);
            assertNull(grantor.getGrantToken(key1));
        }
    });
    if (true)
        // TODO: remove early-out and complete this test
        return;
    // vm1 locks and frees key1
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            LogWriterUtils.getLogWriter().info("[testTokenCleanup] vm1 locks key1");
            connectDistributedSystem();
            DLockService dls = (DLockService) DistributedLockService.create(dlsName, getSystem());
            assertTrue(dls.lock(key1, -1, -1));
            LogWriterUtils.getLogWriter().info("[testTokenCleanup] vm1 frees key1");
            dls.unlock(key1);
            // token for key1 still exists until freeResources is called
            assertNotNull(dls.getToken(key1));
            dls.freeResources(key1);
            // make sure token for key1 is gone
            DLockToken token = dls.getToken(key1);
            assertNull("Failed with bug 38180: " + token, token);
            // make sure there are NO tokens at all
            Collection tokens = dls.getTokens();
            assertEquals("Failed with bug 38180: tokens=" + tokens, 0, tokens.size());
        }
    });
    // vmGrantor frees key1
    vmGrantor.invoke(new SerializableRunnable() {

        public void run() {
            LogWriterUtils.getLogWriter().info("[testTokenCleanup] vmGrantor frees key1");
            DLockService dls = (DLockService) DistributedLockService.getServiceNamed(dlsName);
            if (true)
                // TODO: remove this when 38180/38179 are fixed
                return;
            // check for bug 38180...
            // make sure token for key1 is gone
            DLockToken token = dls.getToken(key1);
            assertNull("Failed with bug 38180: " + token, token);
            // make sure there are NO tokens at all
            Collection tokens = dls.getTokens();
            assertEquals("Failed with bug 38180: tokens=" + tokens, 0, tokens.size());
            // check for bug 38179...
            // make sure there are NO grant tokens at all
            DLockGrantor grantor = dls.getGrantor();
            Collection grantTokens = grantor.getGrantTokens();
            assertEquals("Failed with bug 38179: grantTokens=" + grantTokens, 0, grantTokens.size());
        // dls.freeResources(key1);
        // TODO: assert that DLockGrantToken for key1 is gone
        }
    });
}
Also used : DLockToken(org.apache.geode.distributed.internal.locks.DLockToken) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DLockService(org.apache.geode.distributed.internal.locks.DLockService) Collection(java.util.Collection) DLockGrantor(org.apache.geode.distributed.internal.locks.DLockGrantor) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Example 13 with DLockService

use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.

the class PartitionedRepositoryManagerJUnitTest method setUp.

@Before
public void setUp() {
    cache = Fakes.cache();
    userRegion = Mockito.mock(PartitionedRegion.class);
    userDataStore = Mockito.mock(PartitionedRegionDataStore.class);
    when(userRegion.getDataStore()).thenReturn(userDataStore);
    when(cache.getRegion("/testRegion")).thenReturn(userRegion);
    serializer = new HeterogeneousLuceneSerializer(new String[] { "a", "b" });
    DLockService lockService = mock(DLockService.class);
    when(lockService.lock(any(), anyLong(), anyLong())).thenReturn(true);
    DLockService.addLockServiceForTests(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME, lockService);
    createIndexAndRepoManager();
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HeterogeneousLuceneSerializer(org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer) DLockService(org.apache.geode.distributed.internal.locks.DLockService) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) Before(org.junit.Before)

Example 14 with DLockService

use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.

the class DLockDependencyMonitor method getBlockedThreads.

public Set<Dependency<Thread, Serializable>> getBlockedThreads(Thread[] allThreads) {
    Set<Dependency<Thread, Serializable>> results = new HashSet<Dependency<Thread, Serializable>>();
    // for investigating bug #43496
    DLockService.dumpAllServices();
    Map<String, DLockService> services = DLockService.snapshotAllServices();
    for (Map.Entry<String, DLockService> entry : services.entrySet()) {
        String serviceName = entry.getKey();
        DLockService service = entry.getValue();
        UnsafeThreadLocal<Object> blockedThreadLocal = service.getBlockedOn();
        for (Thread thread : allThreads) {
            Object lockName = blockedThreadLocal.get(thread);
            if (lockName != null) {
                results.add(new Dependency<Thread, Serializable>(thread, new LockId(serviceName, (Serializable) lockName)));
            }
        }
    }
    return results;
}
Also used : Serializable(java.io.Serializable) DLockService(org.apache.geode.distributed.internal.locks.DLockService) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with DLockService

use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.

the class DLockDependencyMonitor method getHeldResources.

public Set<Dependency<Serializable, Thread>> getHeldResources(Thread[] allThreads) {
    InternalDistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    if (ds == null) {
        return Collections.emptySet();
    }
    Set<Dependency<Serializable, Thread>> results = new HashSet<Dependency<Serializable, Thread>>();
    Map<String, DLockService> services = DLockService.snapshotAllServices();
    for (Map.Entry<String, DLockService> entry : services.entrySet()) {
        String serviceName = entry.getKey();
        DLockService service = entry.getValue();
        Map<Object, DLockToken> tokens = service.snapshotService();
        for (Map.Entry<Object, DLockToken> tokenEntry : tokens.entrySet()) {
            Object tokenName = tokenEntry.getKey();
            DLockToken token = tokenEntry.getValue();
            synchronized (token) {
                Thread holdingThread = token.getThread();
                if (holdingThread != null) {
                    results.add(new Dependency(new LockId(serviceName, (Serializable) tokenName), holdingThread));
                }
            }
        }
    }
    return results;
}
Also used : Serializable(java.io.Serializable) DLockToken(org.apache.geode.distributed.internal.locks.DLockToken) DLockService(org.apache.geode.distributed.internal.locks.DLockService) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

DLockService (org.apache.geode.distributed.internal.locks.DLockService)26 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 Test (org.junit.Test)8 DLockTest (org.apache.geode.test.junit.categories.DLockTest)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)6 HashSet (java.util.HashSet)5 VM (org.apache.geode.test.dunit.VM)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 Serializable (java.io.Serializable)3 DLockToken (org.apache.geode.distributed.internal.locks.DLockToken)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Region (org.apache.geode.cache.Region)2 DLockGrantor (org.apache.geode.distributed.internal.locks.DLockGrantor)2 DLockRecoverGrantorProcessor (org.apache.geode.distributed.internal.locks.DLockRecoverGrantorProcessor)2 DLockRemoteToken (org.apache.geode.distributed.internal.locks.DLockRemoteToken)2 RemoteThread (org.apache.geode.distributed.internal.locks.RemoteThread)2