Search in sources :

Example 1 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class IntegrityValidatorTest method transactionsStartedBeforeAConstraintWasCreatedAreDisallowed.

@Test
public void transactionsStartedBeforeAConstraintWasCreatedAreDisallowed() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    IndexingService indexes = mock(IndexingService.class);
    when(metaDataStore.getLatestConstraintIntroducingTx()).thenReturn(10L);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    // When
    try {
        validator.validateTransactionStartKnowledge(1);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 2 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class CountsStoreRecoveryTest method flushNeoStoreOnly.

private void flushNeoStoreOnly() {
    NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    metaDataStore.flush(NULL);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 3 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class IntegrityValidatorTest method transactionsStartedBeforeAConstraintWasCreatedAreDisallowed.

@Test
void transactionsStartedBeforeAConstraintWasCreatedAreDisallowed() {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    when(metaDataStore.getLatestConstraintIntroducingTx()).thenReturn(10L);
    IntegrityValidator validator = new IntegrityValidator(store);
    // When
    assertThrows(Exception.class, () -> validator.validateTransactionStartKnowledge(1));
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.jupiter.api.Test)

Example 4 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class IntegrityValidatorTest method relationshipPropertyIndexesNotAllowedForOldKernelVersions.

@Test
void relationshipPropertyIndexesNotAllowedForOldKernelVersions() {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
    IndexUpdateListener indexes = mock(IndexUpdateListener.class);
    IntegrityValidator validator = new IntegrityValidator(store);
    validator.setIndexValidator(indexes);
    var index = IndexPrototype.forSchema(SchemaDescriptor.forRelType(3, 14)).withIndexType(IndexType.BTREE).withName("any name").materialise(4);
    // When
    assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Test(org.junit.jupiter.api.Test)

Example 5 with MetaDataStore

use of org.neo4j.kernel.impl.store.MetaDataStore in project neo4j by neo4j.

the class RecordStorageEngineTestUtils method applyLogicalChanges.

public static void applyLogicalChanges(RecordStorageEngine storageEngine, ThrowingBiConsumer<ReadableTransactionState, TxStateVisitor, Exception> changes) throws Exception {
    ReadableTransactionState txState = mock(ReadableTransactionState.class);
    doAnswer(invocationOnMock -> {
        TxStateVisitor visitor = invocationOnMock.getArgument(0);
        changes.accept(txState, visitor);
        return null;
    }).when(txState).accept(any());
    List<StorageCommand> commands = new ArrayList<>();
    NeoStores neoStores = storageEngine.testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    CursorContext cursorContext = CursorContext.NULL;
    try (RecordStorageCommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(EmptyMemoryTracker.INSTANCE)) {
        commandCreationContext.initialize(cursorContext);
        storageEngine.createCommands(commands, txState, storageEngine.newReader(), commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, metaDataStore.getLastCommittedTransactionId(), t -> t, cursorContext, EmptyMemoryTracker.INSTANCE);
        storageEngine.apply(new GroupOfCommands(metaDataStore.nextCommittingTransactionId(), commands.toArray(new StorageCommand[0])), TransactionApplicationMode.EXTERNAL);
    }
}
Also used : TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ArrayList(java.util.ArrayList) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Aggregations

MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)15 NeoStores (org.neo4j.kernel.impl.store.NeoStores)8 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 PageCache (org.neo4j.io.pagecache.PageCache)2 TransactionId (org.neo4j.kernel.impl.store.TransactionId)2 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 RequestContext (org.neo4j.com.RequestContext)1