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;
}
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
}
});
}
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();
}
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;
}
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;
}
Aggregations