Skip to content

DATAJDBC-493 Add failing test deadlocks with update and delete. #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import lombok.Getter;
import lombok.With;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
Expand Down Expand Up @@ -123,6 +125,71 @@ public void updateConcurrencyWithEmptyReferences() throws Exception {
assertThat(exceptions).isEmpty();
}

@Test // DATAJDBC-493
@Ignore("failing test")
public void updateConcurrencyWithDelete() throws Exception {

DummyEntity entity = createDummyEntity();
entity = repository.save(entity);

Long targetId = entity.getId();
assertThat(targetId).isNotNull();

List<DummyEntity> concurrencyEntities = createEntityStates(entity);

TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);

List<Exception> exceptions = new CopyOnWriteArrayList<>();
CountDownLatch startLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for all threads to wait on.
CountDownLatch doneLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for main thread to wait on until all threads are done.

// update
concurrencyEntities.stream() //
.map(e -> new Thread(() -> {

try {

startLatch.countDown();
startLatch.await();

transactionTemplate.execute(status -> repository.save(e));
} catch (Exception ex) {
// When the delete execution is complete, the Update execution throws an IncorrectUpdateSemanticsDataAccessException.
if (ex.getCause() instanceof IncorrectUpdateSemanticsDataAccessException) {
return;
}

exceptions.add(ex);
} finally {
doneLatch.countDown();
}
})) //
.forEach(Thread::start);

// delete
new Thread(() -> {
try {

startLatch.countDown();
startLatch.await();

transactionTemplate.execute(status -> {
repository.deleteById(targetId);
return null;
});
} catch (Exception ex) {
exceptions.add(ex);
} finally {
doneLatch.countDown();
}
}).start();

doneLatch.await();

assertThat(exceptions).isEmpty();
assertThat(repository.findById(entity.id)).isEmpty();
}

private List<DummyEntity> createEntityStates(DummyEntity entity) {

List<DummyEntity> concurrencyEntities = new ArrayList<>();
Expand Down