use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class DatabaseRecoveryIT method shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun.
@Test
void shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun() throws IOException {
GraphDatabaseService database = startDatabase(directory.homePath());
Label testLabel = Label.label("testLabel");
final String propertyToDelete = "propertyToDelete";
final String validPropertyName = "validProperty";
try (Transaction transaction = database.beginTx()) {
Node node = transaction.createNode();
node.addLabel(testLabel);
transaction.commit();
}
try (Transaction transaction = database.beginTx()) {
Node node = findNodeByLabel(transaction, testLabel);
node.setProperty(propertyToDelete, createLongString());
node.setProperty(validPropertyName, createLongString());
transaction.commit();
}
try (Transaction transaction = database.beginTx()) {
Node node = findNodeByLabel(transaction, testLabel);
node.removeProperty(propertyToDelete);
transaction.commit();
}
// copying only transaction log simulate non clean shutdown db that should be able to recover just from logs
var restoreDbLayout = copyStore();
// database should be restored and node should have expected properties
DatabaseManagementService recoveredService = getManagementService(restoreDbLayout.getNeo4jLayout().homeDirectory());
GraphDatabaseService recoveredDatabase = recoveredService.database(DEFAULT_DATABASE_NAME);
try (Transaction transaction = recoveredDatabase.beginTx()) {
Node node = findNodeByLabel(transaction, testLabel);
assertFalse(node.hasProperty(propertyToDelete));
assertTrue(node.hasProperty(validPropertyName));
}
recoveredService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class TransactionStateMachineSPIProviderV4Test method shouldReturnTransactionStateMachineSPIIfDatabaseExists.
@Test
void shouldReturnTransactionStateMachineSPIIfDatabaseExists() throws Throwable {
String databaseName = "database";
DatabaseManagementService managementService = managementService(databaseName);
TransactionStateMachineSPIProvider spiProvider = newSpiProvider(managementService);
TransactionStateMachineSPI spi = spiProvider.getTransactionStateMachineSPI(databaseName, mock(StatementProcessorReleaseManager.class));
assertThat(spi).isInstanceOf(TransactionStateMachineV4SPI.class);
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class TransactionStateMachineSPIProviderV4Test method shouldAllocateMemoryForTransactionStateMachineSPI.
@Test
void shouldAllocateMemoryForTransactionStateMachineSPI() throws BoltProtocolBreachFatality, BoltIOException {
String databaseName = "neo4j";
var clock = mock(SystemNanoClock.class);
DatabaseManagementService managementService = managementService(databaseName);
var memoryTracker = mock(MemoryTracker.class);
var scopedMemoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
when(mockBoltChannel.defaultDatabase()).thenReturn("neo4j");
when(memoryTracker.getScopedMemoryTracker()).thenReturn(scopedMemoryTracker);
var dbProvider = new BoltKernelDatabaseManagementServiceProvider(managementService, new Monitors(), clock, Duration.ZERO);
var spiProvider = new TransactionStateMachineSPIProviderV4(dbProvider, mockBoltChannel, clock, memoryTracker);
spiProvider.getTransactionStateMachineSPI("", mock(StatementProcessorReleaseManager.class));
verify(memoryTracker).getScopedMemoryTracker();
verify(scopedMemoryTracker).allocateHeap(TransactionStateMachineV4SPI.SHALLOW_SIZE);
verify(scopedMemoryTracker).allocateHeap(BoltKernelGraphDatabaseServiceProvider.SHALLOW_SIZE);
verify(scopedMemoryTracker).getScopedMemoryTracker();
verifyNoMoreInteractions(memoryTracker);
verifyNoMoreInteractions(scopedMemoryTracker);
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class ManyPropertyKeysIT method concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id.
@Test
void concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id() throws Exception {
// GIVEN
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
Worker worker1 = new Worker("w1", db);
Worker worker2 = new Worker("w2", db);
worker1.beginTx();
worker2.beginTx();
// WHEN
String key = "mykey";
worker1.setProperty(key);
worker2.setProperty(key);
worker1.commit();
worker2.commit();
worker1.close();
worker2.close();
// THEN
assertEquals(1, propertyKeyCount(db));
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class TestConcurrentRelationshipChainLoadingIssue method tryToTriggerRelationshipLoadingStoppingMidWay.
private void tryToTriggerRelationshipLoadingStoppingMidWay(int denseNodeThreshold) throws Throwable {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().setConfig(dense_node_threshold, denseNodeThreshold).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
Node node = createNodeWithRelationships(db);
checkStateToHelpDiagnoseFlakyTest(db, node);
long end = currentTimeMillis() + SECONDS.toMillis(5);
int iterations = 0;
while (currentTimeMillis() < end && iterations < 100) {
tryOnce(db, node);
iterations++;
}
managementService.shutdown();
}
Aggregations