Search in sources :

Example 1 with FailingGenericNativeIndexProviderFactory

use of org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustDiscoverNodeInIndexMissingFromStore.

@Disabled("Turns out that this is not something that the consistency checker actually looks for, currently. " + "The test is disabled until the consistency checker is extended with checks that will discover this sort of inconsistency.")
@Test
void mustDiscoverNodeInIndexMissingFromStore() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(NODE_CREATE, "nodes", asStrList("Label"), asStrList("prop"))).close();
        tx.commit();
    }
    long nodeId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        Node node = tx.createNode(Label.label("Label"));
        nodeId = node.getId();
        node.setProperty("prop", "value");
        tx.commit();
    }
    // Remove the property without updating the index
    managementService.shutdown();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setFileSystem(fs).removeExtensions(INDEX_PROVIDERS_FILTER).addExtension(new FailingGenericNativeIndexProviderFactory(SKIP_ONLINE_UPDATES)).addExtension(new TokenIndexProviderFactory()).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.getNodeById(nodeId).removeProperty("prop");
        tx.commit();
    }
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) FailingGenericNativeIndexProviderFactory(org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with FailingGenericNativeIndexProviderFactory

use of org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory in project neo4j by neo4j.

the class ConstraintIndexFailureIT method shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed.

@Test
void shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() throws Exception {
    // given a perfectly normal constraint
    Path dir = directory.homePath();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(dir).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.schema().constraintFor(label("Label1")).assertPropertyIsUnique("key1").create();
        tx.commit();
    } finally {
        managementService.shutdown();
    }
    // Remove the indexes offline and start up with an index provider which reports FAILED as initial state. An ordeal, I know right...
    FileUtils.deleteDirectory(IndexDirectoryStructure.baseSchemaIndexFolder(dir));
    managementService = new TestDatabaseManagementServiceBuilder(dir).removeExtensions(INDEX_PROVIDERS_FILTER).addExtension(new FailingGenericNativeIndexProviderFactory(INITIAL_STATE)).addExtension(new TokenIndexProviderFactory()).noOpSystemGraphInitializer().build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    // when
    try (Transaction tx = db.beginTx()) {
        var e = assertThrows(ConstraintViolationException.class, () -> tx.createNode(label("Label1")).setProperty("key1", "value1"));
        assertThat(e.getCause()).isInstanceOf(UnableToValidateConstraintException.class);
        assertThat(e.getCause().getCause().getMessage()).contains("The index is in a failed state:").contains(INITIAL_STATE_FAILURE_MESSAGE);
    } finally {
        managementService.shutdown();
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) FailingGenericNativeIndexProviderFactory(org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 FailingGenericNativeIndexProviderFactory (org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory)2 TokenIndexProviderFactory (org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory)2 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)2 Path (java.nio.file.Path)1 Disabled (org.junit.jupiter.api.Disabled)1 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)1 Node (org.neo4j.graphdb.Node)1