use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class TestRecoveryScenarios method shouldRecoverCounts.
@Test
void shouldRecoverCounts() throws Exception {
// GIVEN
Node node = createNode(label);
checkPoint();
deleteNode(node);
// WHEN
crashAndRestart();
// THEN
// -- really the problem was that recovery threw exception, so mostly assert that.
Kernel kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, LoginContext.AUTH_DISABLED)) {
assertEquals(0, tx.dataRead().countsForNode(ANY_LABEL));
final TokenHolder holder = db.getDependencyResolver().resolveDependency(TokenHolders.class).labelTokens();
int labelId = holder.getIdByName(label.name());
assertEquals(0, tx.dataRead().countsForNode(labelId));
tx.commit();
}
}
use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class RecordLoadingTest method shouldReturnsFalseOnMissingToken.
@Test
void shouldReturnsFalseOnMissingToken() {
// given
NodeRecord entity = new NodeRecord(0);
TokenHolder tokenHolder = new DelegatingTokenHolder(new ReadOnlyTokenCreator(), "Test");
TokenStore<PropertyKeyTokenRecord> store = mock(TokenStore.class);
BiConsumer noopReporter = mock(BiConsumer.class);
// when
boolean valid = RecordLoading.checkValidToken(entity, 0, tokenHolder, store, noopReporter, noopReporter, CursorContext.NULL);
// then
assertFalse(valid);
}
use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class StoreTokens method readOnlyTokenHolders.
/**
* Create read-only token holders initialised with the tokens from the given {@link NeoStores}.
* <p>
* Note that this call will ignore tokens that cannot be loaded due to inconsistencies, rather than throwing an exception.
* The reason for this is that the read-only token holders are primarily used by tools, such as the consistency checker.
*
* @param neoStores The {@link NeoStores} from which to load the initial tokens.
* @return TokenHolders that can be used for reading tokens, but cannot create new ones.
*/
public static TokenHolders readOnlyTokenHolders(NeoStores neoStores, CursorContext cursorContext) {
TokenHolder propertyKeyTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY);
TokenHolder labelTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL);
TokenHolder relationshipTypeTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE);
TokenHolders tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
tokenHolders.setInitialTokens(allReadableTokens(neoStores), cursorContext);
return tokenHolders;
}
use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class RecordStorageEngineFactory method tokenHoldersForSchemaStore.
private static TokenHolders tokenHoldersForSchemaStore(NeoStores stores, TokenCreator propertyKeyTokenCreator, CursorContext cursorContext) {
TokenHolder propertyKeyTokens = new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY);
TokenHolders dstTokenHolders = new TokenHolders(propertyKeyTokens, StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
dstTokenHolders.propertyKeyTokens().setInitialTokens(stores.getPropertyKeyTokenStore().getTokens(cursorContext));
return dstTokenHolders;
}
use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class GraphStoreFixture method writableTokenHolders.
public TokenHolders writableTokenHolders() {
TokenHolder propertyKeyTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
int id = next.propertyKey();
tx.propertyKey(id, name, internal);
return id;
}), TokenHolder.TYPE_PROPERTY_KEY);
TokenHolder labelTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
int id = next.label();
tx.nodeLabel(id, name, internal);
return id;
}), TokenHolder.TYPE_LABEL);
TokenHolder relationshipTypeTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
int id = next.relationshipType();
tx.relationshipType(id, name, internal);
return id;
}), TokenHolder.TYPE_RELATIONSHIP_TYPE);
TokenHolders tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
tokenHolders.setInitialTokens(allReadableTokens(directStoreAccess().nativeStores()), NULL);
return tokenHolders;
}
Aggregations