Search in sources :

Example 21 with NamedToken

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

the class TokenRegistryTest method putAllMustThrowOnDuplicateIdWithExistingTokenEvenAcrossPublicAndInternalTokens.

@Test
void putAllMustThrowOnDuplicateIdWithExistingTokenEvenAcrossPublicAndInternalTokens() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    assertThrows(NonUniqueTokenException.class, () -> registry.putAll(singletonList(new NamedToken(INBOUND2_TYPE, 1, true))));
    assertThat(registry.getToken(1)).isEqualTo(new NamedToken(INBOUND1_TYPE, 1));
    assertThat(registry.getId(INBOUND1_TYPE)).isEqualTo(1);
    assertThat(registry.getId(INBOUND2_TYPE)).isNull();
    assertThat(registry.getIdInternal(INBOUND1_TYPE)).isNull();
    assertThat(registry.getIdInternal(INBOUND2_TYPE)).isNull();
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 22 with NamedToken

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

the class TokenRegistryTest method getTokenInternalMustFindInternalTokens.

@Test
void getTokenInternalMustFindInternalTokens() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    assertThat(registry.getTokenInternal(1)).isEqualTo(new NamedToken(INBOUND1_TYPE, 1, true));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 23 with NamedToken

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

the class TokenRegistryTest method putAllMustThrowOnDuplicateIdWithExistingTokenEvenAcrossInternalAndPublicTokens.

@Test
void putAllMustThrowOnDuplicateIdWithExistingTokenEvenAcrossInternalAndPublicTokens() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    assertThrows(NonUniqueTokenException.class, () -> registry.putAll(singletonList(new NamedToken(INBOUND2_TYPE, 1))));
    assertThat(registry.getTokenInternal(1)).isEqualTo(new NamedToken(INBOUND1_TYPE, 1, true));
    assertThat(registry.getToken(1)).isNull();
    assertThat(registry.getId(INBOUND1_TYPE)).isNull();
    assertThat(registry.getId(INBOUND2_TYPE)).isNull();
    assertThat(registry.getIdInternal(INBOUND1_TYPE)).isEqualTo(1);
    assertThat(registry.getIdInternal(INBOUND2_TYPE)).isNull();
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 24 with NamedToken

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

the class TokenRegistryTest method putAllMustThrowOnDuplicateIdWithExistingToken.

@Test
void putAllMustThrowOnDuplicateIdWithExistingToken() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    assertThrows(NonUniqueTokenException.class, () -> registry.putAll(singletonList(new NamedToken(INBOUND2_TYPE, 1))));
    assertThat(registry.getToken(1)).isEqualTo(new NamedToken(INBOUND1_TYPE, 1));
    assertThat(registry.getId(INBOUND1_TYPE)).isEqualTo(1);
    assertThat(registry.getId(INBOUND2_TYPE)).isNull();
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 25 with NamedToken

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

the class TokenStoreTestTemplate method gettingAllReadableTokensAndAllTokensMustAlsoReturnTokensThatAreInternal.

@Test
void gettingAllReadableTokensAndAllTokensMustAlsoReturnTokensThatAreInternal() {
    R tokenA = createInUseRecord(allocateNameRecords("TokenA"));
    R tokenB = createInUseRecord(allocateNameRecords("TokenB"));
    R tokenC = createInUseRecord(allocateNameRecords("TokenC"));
    tokenC.setInternal(true);
    R tokenD = createInUseRecord(allocateNameRecords("TokenD"));
    storeToken(tokenA);
    storeToken(tokenB);
    storeToken(tokenC);
    storeToken(tokenD);
    R readA = store.getRecord(tokenA.getId(), store.newRecord(), NORMAL, NULL);
    R readB = store.getRecord(tokenB.getId(), store.newRecord(), NORMAL, NULL);
    R readC = store.getRecord(tokenC.getId(), store.newRecord(), NORMAL, NULL);
    R readD = store.getRecord(tokenD.getId(), store.newRecord(), NORMAL, NULL);
    store.ensureHeavy(readA, NULL);
    store.ensureHeavy(readB, NULL);
    store.ensureHeavy(readC, NULL);
    store.ensureHeavy(readD, NULL);
    assertThat(readA).isEqualTo(tokenA);
    assertThat(readA.isInternal()).isEqualTo(tokenA.isInternal());
    assertThat(readB).isEqualTo(tokenB);
    assertThat(readB.isInternal()).isEqualTo(tokenB.isInternal());
    assertThat(readC).isEqualTo(tokenC);
    assertThat(readC.isInternal()).isEqualTo(tokenC.isInternal());
    assertThat(readD).isEqualTo(tokenD);
    assertThat(readD.isInternal()).isEqualTo(tokenD.isInternal());
    Iterator<NamedToken> itr = store.getAllReadableTokens(NULL).iterator();
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenA", 0));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenB", 1));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenC", 2, true));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenD", 3));
    itr = store.getTokens(NULL).iterator();
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenA", 0));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenB", 1));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenC", 2, true));
    assertTrue(itr.hasNext());
    assertThat(itr.next()).isEqualTo(new NamedToken("TokenD", 3));
}
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