Search in sources :

Example 26 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class IndexConsultedPropertyBlockSweeperTest method setUp.

@Before
public void setUp() throws IOException {
    api = dbRule.getGraphDatabaseAPI();
    nonIndexedPropKey = "notIndexed";
    indexedPropKey = "indexed";
    Label usedLabel = Label.label("UsedLabel");
    try (Transaction transaction = api.beginTx()) {
        api.schema().indexFor(usedLabel).on(indexedPropKey).create();
        transaction.success();
    }
    try (Transaction transaction = api.beginTx()) {
        indexedValue = "value1";
        nonIndexedValue = "value2";
        Node nodeA = api.createNode(usedLabel);
        nodeA.setProperty(indexedPropKey, indexedValue);
        nodeA.setProperty(nonIndexedPropKey, nonIndexedValue);
        nodeId = nodeA.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    propertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
    propertyStore = neoStores.getPropertyStore();
    nodeRecord = getRecord(nodeStore, nodeId);
    propertyId = nodeRecord.getNextProp();
    indexMock = mock(IndexLookup.Index.class);
    when(indexMock.contains(nodeId, indexedValue)).thenReturn(true);
    propertyRemoverMock = mock(DuplicatePropertyRemover.class);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

Example 27 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class IndexLookupTest method setUp.

@BeforeClass
public static void setUp() {
    api = dbRule.getGraphDatabaseAPI();
    String notUsedIndexPropKey = "notUsed";
    String usedIndexPropKey = "used";
    Label usedLabel = Label.label("UsedLabel");
    Label notUsedLabel = Label.label("NotUsedLabel");
    try (Transaction transaction = api.beginTx()) {
        api.schema().indexFor(usedLabel).on(usedIndexPropKey).create();
        transaction.success();
    }
    try (Transaction transaction = api.beginTx()) {
        api.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
        indexedNodePropertyValue = "value1";
        notIndexedNodePropertyValue = "value2";
        Node nodeA = api.createNode(usedLabel);
        nodeA.setProperty(usedIndexPropKey, indexedNodePropertyValue);
        nodeA.setProperty(notUsedIndexPropKey, notIndexedNodePropertyValue);
        indexedNode = nodeA.getId();
        Node nodeB = api.createNode(notUsedLabel);
        nodeB.setProperty(usedIndexPropKey, notIndexedNodePropertyValue);
        nodeB.setProperty(notUsedIndexPropKey, indexedNodePropertyValue);
        notIndexedNode = nodeB.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    SchemaStore schemaStore = neoStores.getSchemaStore();
    SchemaIndexProvider schemaIndexProvider = resolver.resolveDependency(SchemaIndexProvider.class);
    indexLookup = new IndexLookup(schemaStore, schemaIndexProvider);
    LabelTokenStore labelTokenStore = neoStores.getLabelTokenStore();
    notUsedLabelId = findTokenFor(labelTokenStore, notUsedLabel.name()).id();
    usedLabelId = findTokenFor(labelTokenStore, usedLabel.name()).id();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    notUsedPropertyId = findTokenFor(propertyKeyTokenStore, notUsedIndexPropKey).id();
    usedPropertyId = findTokenFor(propertyKeyTokenStore, usedIndexPropKey).id();
}
Also used : LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Transaction(org.neo4j.graphdb.Transaction) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) BeforeClass(org.junit.BeforeClass)

Example 28 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class CommitContentionTests method createNode.

private void createNode() {
    try (Transaction transaction = db.beginTx()) {
        db.createNode();
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 29 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method shouldAllowGraphCheckDisabled.

@Test
public void shouldAllowGraphCheckDisabled() throws IOException, ConsistencyCheckIncompleteException {
    GraphDatabaseService gds = getGraphDatabaseService();
    try (Transaction tx = gds.beginTx()) {
        gds.createNode();
        tx.success();
    }
    gds.shutdown();
    ConsistencyCheckService service = new ConsistencyCheckService();
    Config configuration = Config.embeddedDefaults(settings(ConsistencyCheckSettings.consistency_check_graph.name(), Settings.FALSE));
    // when
    Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertTrue(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) Result(org.neo4j.consistency.ConsistencyCheckService.Result) Test(org.junit.Test)

Example 30 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class AbstractShellIT method getCurrentNode.

protected Node getCurrentNode() throws RemoteException, ShellException {
    Serializable current = shellServer.interpretVariable(shellClient.getId(), Variables.CURRENT_KEY);
    int nodeId = parseInt(current.toString().substring(1));
    try (Transaction tx = db.beginTx()) {
        Node nodeById = db.getNodeById(nodeId);
        tx.success();
        return nodeById;
    }
}
Also used : Serializable(java.io.Serializable) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64