Search in sources :

Example 46 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistry method allInternalTokens.

public Collection<NamedToken> allInternalTokens() {
    // Likely only a small fraction of all tokens are returned here.
    Registries reg = this.registries;
    List<NamedToken> list = new ArrayList<>();
    for (NamedToken token : reg.idToToken) {
        if (token.isInternal()) {
            list.add(token);
        }
    }
    return unmodifiableCollection(list);
}
Also used : ArrayList(java.util.ArrayList) NamedToken(org.neo4j.token.api.NamedToken)

Example 47 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class DelegatingTokenHolderTest method assertTokens.

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

Example 48 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method puttingPublicTokenBySameNameAsInternalTokenMustNotConflict.

@Test
void puttingPublicTokenBySameNameAsInternalTokenMustNotConflict() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    // This mustn't throw:
    registry.put(new NamedToken(INBOUND1_TYPE, 2));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 49 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method mustKeepOriginalPublicTokenWhenAddDuplicate.

@Test
void mustKeepOriginalPublicTokenWhenAddDuplicate() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    registry.put(new NamedToken(INBOUND2_TYPE, 2));
    assertThrows(NonUniqueTokenException.class, () -> registry.put(new NamedToken(INBOUND1_TYPE, 3)));
    assertEquals(1, registry.getId(INBOUND1_TYPE).intValue());
    assertEquals(2, registry.getId(INBOUND2_TYPE).intValue());
    assertNull(registry.getToken(3));
    assertNull(registry.getTokenInternal(3));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 50 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method allInternalTokensMustIncludeInternalTokensButNotIncludePublicTokens.

@Test
void allInternalTokensMustIncludeInternalTokensButNotIncludePublicTokens() {
    registry.putAll(asList(new NamedToken(INBOUND1_TYPE, 1), new NamedToken(INBOUND1_TYPE, 2, true), new NamedToken(INBOUND2_TYPE, 3), new NamedToken(INBOUND2_TYPE, 4, true)));
    Collection<NamedToken> tokens = registry.allInternalTokens();
    assertThat(tokens).contains(new NamedToken(INBOUND1_TYPE, 2, true), new NamedToken(INBOUND2_TYPE, 4, true));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Aggregations

NamedToken (org.neo4j.token.api.NamedToken)63 Test (org.junit.jupiter.api.Test)41 ArrayList (java.util.ArrayList)6 TokenNotFoundException (org.neo4j.token.api.TokenNotFoundException)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)5 TokenHolder (org.neo4j.token.api.TokenHolder)5 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IntSupplier (java.util.function.IntSupplier)3 KernelException (org.neo4j.exceptions.KernelException)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3 IdCapacityExceededException (org.neo4j.internal.id.IdCapacityExceededException)3 Token (org.neo4j.internal.kernel.api.Token)3 TokenWrite.checkValidTokenName (org.neo4j.internal.kernel.api.TokenWrite.checkValidTokenName)3 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)3 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 RelationshipTypeIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)3