小编Vip*_*pul的帖子

如何顺序执行junit测试用例

我正在编写集成测试用例,用于创建和更新数据

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class, webEnvironment = 
SpringBootTest.WebEnvironment.DEFINED_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MyIntegrationTest {

private String baseUrl="http://192.168.6.177/api/v1/";
@Autowired
TestRestTemplate restTemplate;
Long createdId;        // trying to set ID which is coming after test1_AddData

@Test
public void test1_AddData() throws Exception {
    ABC abc = new ABC("Name");
    HttpEntity<ABC> requestBodyData = new HttpEntity<>(ABC);
    ParameterizedTypeReference<RestTemplateResponseEnvelope<ABC>> typeReference =
            new ParameterizedTypeReference<RestTemplateResponseEnvelope<ABC>>() {
            };

    ResponseEntity<RestTemplateResponseEnvelope<ABC>> response = restTemplate.exchange(
            baseUrl + "/presenceType",
            HttpMethod.POST, requestBodyData, typeReference);

    Assert.assertTrue(HttpStatus.CREATED.equals(response.getStatusCode()));
    createdId = response.getBody().getData().getId();
}


@Test
public void test2_updateData() throws Exception {


    ABC abc = …
Run Code Online (Sandbox Code Playgroud)

junit spring integration-testing

5
推荐指数
1
解决办法
6476
查看次数

如何使用 spring-data 在 mongodb 中创建全文搜索查询?

我在 java 或 kotlin 上有 spring-data-mogodb 应用程序,需要通过 spring 模板创建对 mongodb 的文本搜索请求。

在 mongo shell 中,它看起来像这样:

  db.stores.find(
   { $text: { $search: "java coffee shop" } },
   { score: { $meta: "textScore" } }
  ).sort( { score: { $meta: "textScore" } } )
Run Code Online (Sandbox Code Playgroud)

我已经尝试做一些事情,但这并不是我所需要的:

@override fun getSearchedFiles(searchQuery: String, pageNumber: Long, pageSize: Long, direction: Sort.Direction, sortColumn: String): MutableList<SystemFile> {

    val matching = TextCriteria.forDefaultLanguage().matching(searchQuery)


    val match = MatchOperation(matching)
    val sort = SortOperation(Sort(direction, sortColumn))
    val skip = SkipOperation((pageNumber * pageSize))
    val limit = LimitOperation(pageSize)

    val …
Run Code Online (Sandbox Code Playgroud)

java kotlin spring-data-mongodb

4
推荐指数
1
解决办法
4078
查看次数

Executor 执行两次

我正在尝试同时运行 2 个线程以实现多线程,并且我的程序正在运行,但我怀疑为什么我的程序打印到标准输出两次。

这是我的代码库:

public class SimpleExec {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        CountDownLatch countDownLatch6 = new CountDownLatch(5);
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        System.out.println("start" + LocalDateTime.now());
        executorService.execute(new MyThread("first ", countDownLatch));
        executorService.execute(new MyThread("Second", countDownLatch6));

        try {
            countDownLatch.await();
            countDownLatch6.await();
        } catch (InterruptedException e) {
            System.out.println(e);
        }
        System.out.println("end" + LocalDateTime.now());
        executorService.shutdown();

    }
}

class MyThread implements Runnable {
    String name;
    CountDownLatch cdl;

    public MyThread(String name, CountDownLatch cdl) {
        this.cdl = cdl;
        this.name = name;
        new Thread(this).start();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java multithreading executorservice

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