use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class PointPropertiesRecordFormatIT method createPointArrayPropertyOnLatestDatabase.
@Test
void createPointArrayPropertyOnLatestDatabase() {
Path storeDir = testDirectory.homePath();
Label pointNode = Label.label("PointNode");
String propertyKey = "a";
PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
DatabaseManagementService managementService = startDatabaseService(storeDir);
GraphDatabaseService database = getDefaultDatabase(managementService);
try (Transaction transaction = database.beginTx()) {
Node node = transaction.createNode(pointNode);
node.setProperty(propertyKey, new PointValue[] { pointValue, pointValue });
transaction.commit();
}
managementService.shutdown();
managementService = startDatabaseService(storeDir);
GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
try (Transaction tx = restartedDatabase.beginTx()) {
try (ResourceIterator<Node> nodes = tx.findNodes(pointNode)) {
Node node = nodes.next();
PointValue[] points = (PointValue[]) node.getProperty(propertyKey);
assertThat(points).hasSize(2);
}
}
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class PointPropertiesRecordFormatIT method createPointPropertyOnLatestDatabase.
@Test
void createPointPropertyOnLatestDatabase() {
Path storeDir = testDirectory.homePath();
Label pointNode = Label.label("PointNode");
String propertyKey = "a";
PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
DatabaseManagementService managementService = startDatabaseService(storeDir);
GraphDatabaseService database = getDefaultDatabase(managementService);
try (Transaction transaction = database.beginTx()) {
Node node = transaction.createNode(pointNode);
node.setProperty(propertyKey, pointValue);
transaction.commit();
}
managementService.shutdown();
managementService = startDatabaseService(storeDir);
GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
try (Transaction transaction = restartedDatabase.beginTx()) {
assertNotNull(transaction.findNode(pointNode, propertyKey, pointValue));
}
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method startStopDatabaseAndGetTxOffset.
private long startStopDatabaseAndGetTxOffset() {
DatabaseManagementService managementService = databaseFactory.build();
final GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
storageEngineFactory = database.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
long offset = getLastClosedTransactionOffset(database);
managementService.shutdown();
return offset;
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method restoreCheckpointLogVersionFromFileVersion.
@Test
void restoreCheckpointLogVersionFromFileVersion() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransaction(database);
managementService.shutdown();
int rotations = 10;
try (Lifespan lifespan = new Lifespan(logFiles)) {
CheckpointFile checkpointFile = logFiles.getCheckpointFile();
DetachedCheckpointAppender checkpointAppender = (DetachedCheckpointAppender) checkpointFile.getCheckpointAppender();
for (int i = 0; i < rotations; i++) {
checkpointAppender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, HEADER_OFFSET), Instant.now(), "test" + i);
checkpointAppender.rotate();
}
}
for (int i = rotations - 1; i > 0; i--) {
var restartedDbms = databaseFactory.build();
try {
StorageEngine storageEngine = ((GraphDatabaseAPI) restartedDbms.database(DEFAULT_DATABASE_NAME)).getDependencyResolver().resolveDependency(StorageEngine.class);
assertEquals(i, storageEngine.metadataProvider().getCheckpointLogVersion());
} finally {
restartedDbms.shutdown();
}
// we remove 3 checkpoints: 1 from shutdown and 1 from recovery and one that we created in a loop before
removeLastCheckpointRecordFromLastLogFile();
removeLastCheckpointRecordFromLastLogFile();
removeLastCheckpointRecordFromLastLogFile();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method failToStartWithTransactionLogsWithDataAfterLastEntry.
@Test
void failToStartWithTransactionLogsWithDataAfterLastEntry() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransaction(database);
managementService.shutdown();
writeRandomBytesAfterLastCommandInLastLogFile(() -> ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5 }));
startStopDatabase();
assertThat(logProvider).assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessageContaining("Transaction log files with version 0 has some data available after last readable " + "log entry. Last readable position " + (996 + txOffsetAfterStart));
}
Aggregations