小编ysl*_*ysl的帖子

如何使用Spring Boot + Spring Data JPA对悲观锁定进行单元测试

我想测试是否FooRepository.lock()有人工作,有人打电话给lock(),其他人打电话给它应该等待.

以下是我最好的尝试,它不起作用.我相信原因是entityManger并且fooRepository正在参与同一笔交易.

如何lock()从另一个交易中调用?或者对悲观锁进行单元测试的任何建议?谢谢!!

FooRepositoryTest:

package com.example.demo;

import java.util.UUID;

import javax.persistence.LockModeType;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataJpaTest
public class FooRepositoryTest {

    @Autowired
    private TestEntityManager entityManager;    

    @Autowired
    private FooRepository fooRepository;

    @Test
    public void lockTest() {
        // given
        Foo foo = new Foo();
        foo.setName("foo-name");

        UUID fooId = fooRepository.save(foo).getFooId();
        entityManager.flush();
        entityManager.clear();

        // when
        Foo savedFoo = fooRepository.findOne(fooId);
        fooRepository.lock(savedFoo);

        // then
        // I want something like this …
Run Code Online (Sandbox Code Playgroud)

java unit-testing spring-data-jpa spring-boot

7
推荐指数
1
解决办法
1070
查看次数

如何在Maven中调试工件替换

我有一个父项目包含十几个子项目,其中一个子项目使用org.apache.httpcomponents:httpclient:jar:4.3.5,这取决于org.apache.httpcomponents:httpcore:jar:4.3.2.

但是,结果版本httpcore被解析为4.2.1而不是4.3.2.

以下是dependency:tree在Eclipse中选中调试选项运行时的输出提取:

...
[DEBUG] Using mirror nexus (http://192.168.0.111:8081/nexus/content/groups/public) for apache.snapshots (http://repository.apache.org/snapshots).
[DEBUG]   testArtifact: artifact=org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[DEBUG]   includeArtifact: artifact=org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[DEBUG]   startProcessChildren: artifact=org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[DEBUG]     manageArtifactVersion: artifact=org.apache.httpcomponents:httpcore:jar:4.3.2:compile, replacement=org.apache.httpcomponents:httpcore:jar:4.2.1
[DEBUG] Using mirror nexus (http://192.168.0.111:8081/nexus/content/groups/public) for apache.snapshots (http://repository.apache.org/snapshots).
...
Run Code Online (Sandbox Code Playgroud)

它只是显示replacement=org.apache.httpcomponents:httpcore:jar:4.2.1,但它没有说明更换的原因.父项目的pom.xml使用了很多依赖项,即使我可以尝试逐个删除这些依赖项并检查结果,但这将非常耗时.有没有更有效的方法来调试工件更换?


这里几乎是dependency:treeEclipse 的完整日志,并且选中了调试选项.

artifact pom.xml maven transitive-dependency

2
推荐指数
1
解决办法
2860
查看次数