Search in sources :

Example 16 with Token

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

the class TokenHolderTest method assertTokens.

private void assertTokens(Iterable<Token> allTokens, Token... expectedTokens) {
    Map<String, Token> existing = new HashMap<>();
    for (Token token : allTokens) {
        existing.put(token.name(), token);
    }
    Map<String, Token> expected = new HashMap<>();
    for (Token token : expectedTokens) {
        expected.put(token.name(), token);
    }
    assertEquals(expected, existing);
}
Also used : HashMap(java.util.HashMap) Token(org.neo4j.storageengine.api.Token)

Example 17 with Token

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

the class NeoStoresTest method validateRelTypes.

private void validateRelTypes(int relType1, int relType2) throws IOException {
    Token data = rtStore.getToken(relType1);
    assertEquals(relType1, data.id());
    assertEquals("relationshiptype1", data.name());
    data = rtStore.getToken(relType2);
    assertEquals(relType2, data.id());
    assertEquals("relationshiptype2", data.name());
    List<RelationshipTypeToken> allData = rtStore.getTokens(Integer.MAX_VALUE);
    assertEquals(2, allData.size());
    for (int i = 0; i < 2; i++) {
        if (allData.get(i).id() == relType1) {
            assertEquals(relType1, allData.get(i).id());
            assertEquals("relationshiptype1", allData.get(i).name());
        } else if (allData.get(i).id() == relType2) {
            assertEquals(relType2, allData.get(i).id());
            assertEquals("relationshiptype2", allData.get(i).name());
        } else {
            throw new IOException();
        }
    }
}
Also used : RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) Token(org.neo4j.storageengine.api.Token) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 18 with Token

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

the class NonIndexedConflictResolverTest method shouldReuseExistingPropertyKeyTokensWhenThatHaveAlreadyCreatedOnPreviousNodes.

@Test
public void shouldReuseExistingPropertyKeyTokensWhenThatHaveAlreadyCreatedOnPreviousNodes() throws IOException {
    // Given
    NonIndexedConflictResolver resolver = new NonIndexedConflictResolver(propertyKeyTokenStore, propertyStore);
    List<DuplicateCluster> clusterListA = new ArrayList<>();
    long propertyIdA = addDuplicateCluster(nodeIdA, clusterListA);
    List<DuplicateCluster> clusterListB = new ArrayList<>();
    long propertyIdB = addDuplicateCluster(nodeIdB, clusterListB);
    // When
    resolver.visited(0, clusterListA);
    resolver.visited(0, clusterListB);
    // Then
    Token duplicateTokenA = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_1");
    assertNotNull(duplicateTokenA);
    Set<Integer> propertyKeyIdsA = collectPropertyKeyIds(propertyIdA);
    assertThat(propertyKeyIdsA, contains(tokenA.id(), duplicateTokenA.id()));
    Set<Integer> propertyKeyIdsB = collectPropertyKeyIds(propertyIdB);
    assertThat(propertyKeyIdsB, contains(tokenA.id(), duplicateTokenA.id()));
}
Also used : ArrayList(java.util.ArrayList) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 19 with Token

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

the class NonIndexedConflictResolverTest method setUp.

@Before
public void setUp() {
    api = dbRule.getGraphDatabaseAPI();
    String propKeyA = "keyA";
    String propKeyB = "keyB";
    String propKeyC = "keyC";
    String propKeyD = "keyD";
    String propKeyE = "keyE";
    try (Transaction transaction = api.beginTx()) {
        Node nodeA = api.createNode();
        nodeA.setProperty(propKeyA, "value");
        nodeA.setProperty(propKeyB, "value");
        nodeIdA = nodeA.getId();
        Node nodeB = api.createNode();
        nodeB.setProperty(propKeyA, "value");
        nodeB.setProperty(propKeyB, "value");
        nodeIdB = nodeB.getId();
        Node nodeC = api.createNode();
        nodeC.setProperty(propKeyA, "longer val");
        nodeC.setProperty(propKeyB, "longer val");
        nodeC.setProperty(propKeyC, "longer val");
        nodeC.setProperty(propKeyD, "longer val");
        nodeC.setProperty(propKeyE, "longer val");
        nodeIdC = nodeC.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    propertyStore = neoStores.getPropertyStore();
    propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    tokenA = findTokenFor(propertyKeyTokenStore, propKeyA);
    Token tokenB = findTokenFor(propertyKeyTokenStore, propKeyB);
    Token tokenC = findTokenFor(propertyKeyTokenStore, propKeyC);
    Token tokenD = findTokenFor(propertyKeyTokenStore, propKeyD);
    Token tokenE = findTokenFor(propertyKeyTokenStore, propKeyE);
    replacePropertyKey(propertyStore, nodeStore.getRecord(nodeIdA, nodeStore.newRecord(), FORCE), tokenB, tokenA);
    replacePropertyKey(propertyStore, nodeStore.getRecord(nodeIdB, nodeStore.newRecord(), FORCE), tokenB, tokenA);
    NodeRecord nodeRecordC = nodeStore.getRecord(nodeIdC, nodeStore.newRecord(), FORCE);
    replacePropertyKey(propertyStore, nodeRecordC, tokenB, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenC, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenD, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenE, tokenA);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Token(org.neo4j.storageengine.api.Token) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

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