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)));
}
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)));
}
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));
}
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;
}
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;
}
Aggregations