刘光辉
118 分钟以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package jnpf.dmsService.search;
 
import jnpf.dmsEntity.permission.entity.DmsDocumentEntity;
import jnpf.dmsEntity.search.model.DmsSearchIndexSource;
import jnpf.dmsMapper.DmsDocumentMapper;
import jnpf.dmsMapper.DmsSearchIndexSourceMapper;
import jnpf.dmsService.search.meili.*;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import java.util.UUID;
import static org.mockito.Mockito.*;
 
class DmsSearchIndexWriterTest {
    @Test void lateExtractionCannotPublishAfterExpiryAndLockPrecedesFinalRead() throws Exception {
        DmsDocumentMapper documents = mock(DmsDocumentMapper.class);
        DmsSearchIndexSourceMapper sources = mock(DmsSearchIndexSourceMapper.class);
        DmsMeilisearchClient client = mock(DmsMeilisearchClient.class);
        DmsSearchIndexWriter writer = new DmsSearchIndexWriter(documents, sources, client);
        UUID doc = UUID.randomUUID(), version = UUID.randomUUID();
        DmsSearchIndexDocument value = new DmsSearchIndexDocument();
        value.setTenantId("t"); value.setDocumentId(doc.toString()); value.setFileVersionId(version.toString());
        when(documents.selectByTenantAndIdForUpdate("t", doc)).thenReturn(new DmsDocumentEntity());
        writer.publish(value);
        verifyNoInteractions(client);
        clearInvocations(documents, sources);
        when(sources.selectSource("t", doc, version)).thenReturn(new DmsSearchIndexSource());
        writer.publish(value);
        InOrder order = inOrder(documents, sources, client);
        order.verify(documents).selectByTenantAndIdForUpdate("t", doc);
        order.verify(sources).selectSource("t", doc, version);
        order.verify(client).upsert(value);
    }
}