Search in sources :

Example 6 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class LabelIT method shouldListAllLabels.

@Test
public void shouldListAllLabels() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int label1Id = statement.tokenWriteOperations().labelGetOrCreateForName("label1");
    int label2Id = statement.tokenWriteOperations().labelGetOrCreateForName("label2");
    // when
    Iterator<Token> labelIdsBeforeCommit = statement.readOperations().labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsBeforeCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> labelIdsAfterCommit = readOperations.labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsAfterCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 7 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class PropertyIT method shouldListAllPropertyKeys.

@Test
public void shouldListAllPropertyKeys() throws Exception {
    // given
    dbWithNoCache();
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
    int prop2 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop2");
    // when
    Iterator<Token> propIdsBeforeCommit = statement.readOperations().propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsBeforeCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> propIdsAfterCommit = readOperations.propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsAfterCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 8 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class ReplicatedTokenHolderTest method shouldReplicateTokenRequestForNewToken.

@Test
public void shouldReplicateTokenRequestForNewToken() throws Exception {
    // given
    StorageEngine storageEngine = mockedStorageEngine();
    when(dependencies.resolveDependency(StorageEngine.class)).thenReturn(storageEngine);
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    IdGenerator idGenerator = mock(IdGenerator.class);
    when(idGenerator.nextId()).thenReturn(1L);
    when(idGeneratorFactory.get(any(IdType.class))).thenReturn(idGenerator);
    TokenRegistry<Token> registry = new TokenRegistry<>("Label");
    int generatedTokenId = 1;
    ReplicatedTokenHolder<Token> tokenHolder = new ReplicatedLabelTokenHolder(registry, (content, trackResult) -> {
        CompletableFuture<Object> completeFuture = new CompletableFuture<>();
        completeFuture.complete(generatedTokenId);
        return completeFuture;
    }, idGeneratorFactory, dependencies);
    // when
    Integer tokenId = tokenHolder.getOrCreateId("name1");
    // then
    assertThat(tokenId, equalTo(generatedTokenId));
}
Also used : IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) Token(org.neo4j.storageengine.api.Token) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) StorageEngine(org.neo4j.storageengine.api.StorageEngine) IdType(org.neo4j.kernel.impl.store.id.IdType) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 9 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class NonIndexedConflictResolver method buildPropertyKeyIndex.

private Map<String, Integer> buildPropertyKeyIndex(PropertyKeyTokenStore tokenStore) throws IOException {
    List<Token> tokens = tokenStore.getTokens((int) tokenStore.getHighestPossibleIdInUse() + 1);
    Map<String, Integer> map = new HashMap<>();
    for (Token token : tokens) {
        map.put(token.name(), token.id());
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Token(org.neo4j.storageengine.api.Token)

Example 10 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class CacheInvalidationTransactionApplier method visitPropertyKeyTokenCommand.

@Override
public boolean visitPropertyKeyTokenCommand(PropertyKeyTokenCommand command) throws IOException {
    Token index = propertyKeyTokenStore.getToken((int) command.getKey());
    cacheAccess.addPropertyKeyToken(index);
    return false;
}
Also used : RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) Token(org.neo4j.storageengine.api.Token)

Aggregations

Token (org.neo4j.storageengine.api.Token)19 Test (org.junit.Test)8 RelationshipTypeToken (org.neo4j.kernel.impl.core.RelationshipTypeToken)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 UniquenessConstraint (org.neo4j.kernel.api.constraints.UniquenessConstraint)2 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)2 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)2 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)2 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)2 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1