Search in sources :

Example 1 with IndexServiceInternal

use of com.enonic.xp.repo.impl.index.IndexServiceInternal in project xp by enonic.

the class CreateNodeCommand_path_integrity_test method create.

@Test
public void create() {
    final int concurrentAttempts = 5;
    final int expectedSuccessfulAttempts = 1;
    final AtomicInteger exceptionCounter = new AtomicInteger();
    CompletableFuture.allOf(IntStream.range(0, concurrentAttempts).mapToObj(i -> CompletableFuture.runAsync(CreateNodeTask.create().binaryService(this.binaryService).storageService(this.storageService).nodeSearchService(this.searchService).indexServiceInternal(this.indexServiceInternal).context(ContextAccessor.current()).build()).exceptionally(throwable -> {
        exceptionCounter.incrementAndGet();
        return null;
    })).toArray(CompletableFuture[]::new)).join();
    assertEquals(concurrentAttempts - expectedSuccessfulAttempts, exceptionCounter.get());
    refresh();
    final FindNodesByQueryResult result = doFindByQuery(NodeQuery.create().path(NodePath.create(NodePath.ROOT, "myNode").build()).build());
    assertEquals(expectedSuccessfulAttempts, result.getTotalHits());
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) NodePath(com.enonic.xp.node.NodePath) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.jupiter.api.Test) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Test(org.junit.jupiter.api.Test)

Example 2 with IndexServiceInternal

use of com.enonic.xp.repo.impl.index.IndexServiceInternal in project xp by enonic.

the class RepositoryEntryServiceImpl method findRepositoryEntryIds.

@Override
public RepositoryIds findRepositoryEntryIds() {
    final ImmutableList.Builder<RepositoryId> repositoryIds = ImmutableList.builder();
    final FindNodesByParentParams findNodesByParentParams = FindNodesByParentParams.create().parentPath(RepositoryConstants.REPOSITORY_STORAGE_PARENT_PATH).size(-1).build();
    final FindNodesByParentResult findNodesByParentResult = createContext().callWith(() -> FindNodesByParentCommand.create().params(findNodesByParentParams).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute());
    findNodesByParentResult.getNodeIds().stream().map(nodeId -> RepositoryId.from(nodeId.toString())).forEach(repositoryIds::add);
    return RepositoryIds.from(repositoryIds.build());
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) EventPublisher(com.enonic.xp.event.EventPublisher) Node(com.enonic.xp.node.Node) RepositoryIds(com.enonic.xp.repository.RepositoryIds) Branch(com.enonic.xp.branch.Branch) Component(org.osgi.service.component.annotations.Component) RepositoryId(com.enonic.xp.repository.RepositoryId) ImmutableList(com.google.common.collect.ImmutableList) UpdateNodeCommand(com.enonic.xp.repo.impl.node.UpdateNodeCommand) ContextAccessor(com.enonic.xp.context.ContextAccessor) RefreshCommand(com.enonic.xp.repo.impl.node.RefreshCommand) NodeEvents(com.enonic.xp.repo.impl.NodeEvents) ContextBuilder(com.enonic.xp.context.ContextBuilder) ByteSource(com.google.common.io.ByteSource) SystemConstants(com.enonic.xp.security.SystemConstants) RepositoryEvents(com.enonic.xp.repo.impl.RepositoryEvents) FindNodesByParentCommand(com.enonic.xp.repo.impl.node.FindNodesByParentCommand) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) AttachedBinary(com.enonic.xp.node.AttachedBinary) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) DeleteNodeByIdCommand(com.enonic.xp.repo.impl.node.DeleteNodeByIdCommand) Context(com.enonic.xp.context.Context) Reference(org.osgi.service.component.annotations.Reference) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) Repository(com.enonic.xp.repository.Repository) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) ImmutableList(com.google.common.collect.ImmutableList) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 3 with IndexServiceInternal

use of com.enonic.xp.repo.impl.index.IndexServiceInternal in project xp by enonic.

the class ProjectServiceImplTest method create_in_non_master_node.

@Test
void create_in_non_master_node() {
    IndexServiceInternal indexServiceInternalMock = Mockito.mock(IndexServiceInternal.class);
    when(indexServiceInternalMock.waitForYellowStatus()).thenReturn(true);
    indexService.setIndexServiceInternal(indexServiceInternalMock);
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final Project project = adminContext().callWith(() -> doCreateProject(ProjectName.from(projectRepoId), null, true, null));
    assertNotNull(project);
    assertEquals("test-project", project.getName().toString());
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(Node.ROOT_UUID, InternalContext.create(adminContext()).repositoryId(projectRepoId).build());
    assertNotNull(nodeBranchEntry);
    adminContext().runWith(() -> {
        final Repository pro = repositoryService.get(projectRepoId);
        assertNotNull(pro);
    });
}
Also used : Project(com.enonic.xp.project.Project) Repository(com.enonic.xp.repository.Repository) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

IndexServiceInternal (com.enonic.xp.repo.impl.index.IndexServiceInternal)3 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 BinaryService (com.enonic.xp.repo.impl.binary.BinaryService)2 NodeSearchService (com.enonic.xp.repo.impl.search.NodeSearchService)2 NodeStorageService (com.enonic.xp.repo.impl.storage.NodeStorageService)2 Repository (com.enonic.xp.repository.Repository)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2 Test (org.junit.jupiter.api.Test)2 Branch (com.enonic.xp.branch.Branch)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 Node (com.enonic.xp.node.Node)1 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)1 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1