use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.
the class StoreUpgradeIntegrationTest method checkGlobalNodeCount.
private static void checkGlobalNodeCount(Store store, GraphDatabaseAPI db) {
try (Transaction ignored = db.beginTx()) {
ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
Statement statement = bridge.get();
assertThat(statement.readOperations().countsForNode(-1), is(store.expectedNodeCount));
}
}
use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.
the class GraphDatabaseFacade method init.
/**
* Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies
*/
public void init(SPI spi, Guard guard, ThreadToStatementContextBridge txBridge, Config config) {
this.spi = spi;
this.defaultTransactionTimeout = config.get(GraphDatabaseSettings.transaction_timeout);
Supplier<Statement> statementSupplier = spi::currentStatement;
Supplier<KernelTransaction> transactionSupplier = spi::currentTransaction;
ThrowingAction<RuntimeException> assertTransactionOpen = this::assertTransactionOpen;
this.schema = new SchemaImpl(statementSupplier);
this.relActions = new StandardRelationshipActions(statementSupplier, transactionSupplier, assertTransactionOpen, (id) -> new NodeProxy(nodeActions, id), this);
this.nodeActions = new StandardNodeActions(statementSupplier, transactionSupplier, assertTransactionOpen, relActions, this);
this.indexManager = Suppliers.lazySingleton(() -> {
IndexProviderImpl idxProvider = new IndexProviderImpl(this, statementSupplier);
AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>(() -> new ReadOnlyIndexFacade<>(idxProvider.getOrCreateNodeIndex(NODE_AUTO_INDEX, null)), spi.autoIndexing().nodes());
RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade(() -> new ReadOnlyRelationshipIndexFacade(idxProvider.getOrCreateRelationshipIndex(RELATIONSHIP_AUTO_INDEX, null)), spi.autoIndexing().relationships());
return new IndexManagerImpl(statementSupplier, idxProvider, nodeAutoIndexer, relAutoIndexer);
});
this.contextFactory = Neo4jTransactionalContextFactory.create(spi, guard, txBridge, locker);
}
use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.
the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.
@Test
public void shouldAllowManyLabelsAndPropertyCursor() throws Exception {
int propertyCount = 10;
int labelCount = 15;
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
Node node;
try (Transaction tx = db.beginTx()) {
node = db.createNode();
for (int i = 0; i < propertyCount; i++) {
node.setProperty("foo" + i, "bar");
}
for (int i = 0; i < labelCount; i++) {
node.addLabel(label("label" + i));
}
tx.success();
}
Set<Integer> seenProperties = new HashSet<>();
Set<Integer> seenLabels = new HashSet<>();
try (Transaction tx = db.beginTx()) {
DependencyResolver resolver = db.getDependencyResolver();
ThreadToStatementContextBridge bridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
try (Statement statement = bridge.getTopLevelTransactionBoundToThisThread(true).acquireStatement()) {
try (Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId())) {
try (Cursor<PropertyItem> properties = statement.readOperations().nodeGetProperties(nodeCursor.get())) {
while (properties.next()) {
seenProperties.add(properties.get().propertyKeyId());
consume(nodeCursor.get().labels().iterator(), seenLabels::add);
}
}
}
}
tx.success();
}
assertEquals(propertyCount, seenProperties.size());
assertEquals(labelCount, seenLabels.size());
}
use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.
the class TransactionStateMachineSPITest method createTxSpi.
private static TransactionStateMachineSPI createTxSpi(TransactionIdStore txIdStore, Duration txAwaitDuration, AvailabilityGuard availabilityGuard, Clock clock) {
GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
when(queryService.getDependencyResolver()).thenReturn(mock(DependencyResolver.class));
return new TransactionStateMachineSPI(mock(GraphDatabaseAPI.class), new ThreadToStatementContextBridge(), mock(QueryExecutionEngine.class), txIdStore, availabilityGuard, queryService, txAwaitDuration, clock);
}
use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.
@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (TransientTransactionFailureException e) {
// THEN Good
}
}
Aggregations