Skip to content

Commit

Permalink
Cache DeadLock Detection test move from org.eclipse.persistence.jpa.j…
Browse files Browse the repository at this point in the history
…se.test into new org.eclipse.persistence.jpa.testapps.deadlock.diagnostic Maven module (#2304)

Cache DeadLock Detection test move from org.eclipse.persistence.jpa.jse.test into new org.eclipse.persistence.jpa.testapps.deadlock.diagnostic Maven module
There is move into new Maven module some test refactor and new test for WriteLockManager.acquireLocksForClone(...) method call and logging.
ConcurrentReadFetchJoinWithUOWLocksTest fix to allow test threads to finish.

Signed-off-by: Radek Felcman <[email protected]>
  • Loading branch information
rfelcman authored Jan 15, 2025
1 parent a108f5b commit 3b66e99
Show file tree
Hide file tree
Showing 19 changed files with 696 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -72,7 +72,7 @@ public void test(){
clonedPerson.setHobby(clonedProject);
uow.writeChanges();

Thread thread1 = new Thread(new ProjectReader(server.acquireClientSession(), project.getId()));
Thread thread1 = new Thread(new ProjectReader(server.acquireClientSession(), project.getId()), "Test Thread 1");
ConcurrentProject.RUNNING_TEST = ConcurrentProject.READ_WITH_UOW_LOCKS_TESTS;
//start reading Project, and have the thread wait while building DTF mappings
thread1.start();
Expand All @@ -84,7 +84,7 @@ public void test(){

//start uow commit, which will get locks on Person+Address, commit, then merge.
//merge should get a deferred lock on Project.
Thread thread2 = new Thread(new UOWCommit(uow));
Thread thread2 = new Thread(new UOWCommit(uow), "Test Thread 2");
thread2.start();

//while waiting, thread1 should wake and try to get a lock on Address. It will deadlock if it
Expand Down Expand Up @@ -112,7 +112,9 @@ public void verify(){
}

@Override
public void reset(){
public void reset() throws InterruptedException {
//To give threads from the test() chance to finish
Thread.sleep(1000);
ConcurrentProject.RUNNING_TEST = ConcurrentProject.NONE;
UnitOfWork uow = getSession().acquireUnitOfWork();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public class WriteLockManager {
private final Lock toWaitOnLock = new ReentrantLock();
private final Lock instancePrevailingQueueLock = new ReentrantLock();

private static final String ACQUIRE_LOCK_FOR_CLONE_METHOD_NAME = WriteLockManager.class.getName() + ".acquireLocksForClone(...)";

public WriteLockManager() {
this.prevailingQueue = new ExposedNodeLinkedList();
}
Expand Down Expand Up @@ -169,9 +171,8 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto
// of the concurrency manager that we use for creating the massive log dump
// to indicate that the current thread is now stuck trying to acquire some arbitrary
// cache key for writing
StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[1];
lastCacheKeyWeNeededToWaitToAcquire = toWaitOn;
lastCacheKeyWeNeededToWaitToAcquire.putThreadAsWaitingToAcquireLockForWriting(currentThread, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(...)");
lastCacheKeyWeNeededToWaitToAcquire.putThreadAsWaitingToAcquireLockForWriting(currentThread, ACQUIRE_LOCK_FOR_CLONE_METHOD_NAME);

// Since we know this one of those methods that can appear in the dead locks
// we threads frozen here forever inside of the wait that used to have no timeout
Expand Down
26 changes: 1 addition & 25 deletions jpa/eclipselink.jpa.test.jse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<scope>test</scope>
</dependency>
<!--ASM Implementations-->
<!--EclipseLink ASM Implementation-->
<dependency>
Expand Down Expand Up @@ -210,32 +200,18 @@
</configuration>
<executions>
<execution>
<id>test-jpa-jse-without-deadlock</id>
<id>test-jpa-jse</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skipTests>${test-skip-jpa-jse}</skipTests>
<reportNameSuffix>test-jpa-jse</reportNameSuffix>
<excludes>
<exclude>CacheDeadLockDetectionTest*</exclude>
</excludes>
<includes>
<include>*.Test*</include>
</includes>
</configuration>
</execution>
<execution>
<id>test-jpa-jse-deadlock</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>CacheDeadLockDetectionTest*</include>
</includes>
</configuration>
</execution>
<execution>
<id>verify-integration-tests</id>
<goals>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,4 @@
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties></properties>
</persistence-unit>

<persistence-unit name="cachedeadlockdetection-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.eclipse.persistence.jpa.test.cachedeadlock.model.CacheDeadLockDetectionMaster</class>
<class>org.eclipse.persistence.jpa.test.cachedeadlock.model.CacheDeadLockDetectionDetail</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.concurrency.manager.waittime" value="1"/>
<property name="eclipselink.concurrency.manager.maxsleeptime" value="2"/>
<property name="eclipselink.concurrency.manager.maxfrequencytodumptinymessage" value="800"/>
<property name="eclipselink.concurrency.manager.maxfrequencytodumpmassivemessage" value="1000"/>
<property name="eclipselink.concurrency.manager.build.object.complete.waittime" value="5"/>
<property name="eclipselink.concurrency.manager.allow.readlockstacktrace" value="true"/>
<property name="eclipselink.concurrency.manager.allow.concurrencyexception" value="true"/>
<property name="eclipselink.concurrency.manager.allow.interruptedexception" value="true"/>
</properties>
</persistence-unit>

<persistence-unit name="cachedeadlocksemaphore-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.eclipse.persistence.jpa.test.cachedeadlock.model.CacheDeadLockDetectionMaster</class>
<class>org.eclipse.persistence.jpa.test.cachedeadlock.model.CacheDeadLockDetectionDetail</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.concurrency.manager.waittime" value="1"/>
<property name="eclipselink.concurrency.manager.maxsleeptime" value="2"/>
<property name="eclipselink.concurrency.manager.maxfrequencytodumptinymessage" value="1000"/>
<property name="eclipselink.concurrency.manager.maxfrequencytodumpmassivemessage" value="2000"/>
<property name="eclipselink.concurrency.manager.allow.readlockstacktrace" value="true"/>
<property name="eclipselink.concurrency.manager.allow.concurrencyexception" value="true"/>
<property name="eclipselink.concurrency.manager.allow.interruptedexception" value="true"/>
<property name="eclipselink.concurrency.manager.object.building.semaphore" value="true"/>
<property name="eclipselink.concurrency.manager.object.building.no.threads" value="5"/>
<property name="eclipselink.concurrency.manager.write.lock.manager.semaphore" value="true"/>
<property name="eclipselink.concurrency.manager.write.lock.manager.no.threads" value="6"/>
<property name="eclipselink.concurrency.semaphore.max.time.permit" value="7"/>
<property name="eclipselink.concurrency.semaphore.log.timeout" value="8"/>
</properties>
</persistence-unit>

</persistence>
Loading

0 comments on commit 3b66e99

Please sign in to comment.