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());
}
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();
}
}
Aggregations