use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.
the class GBPTreeTest method verifyHeader.
private void verifyHeader(PageCache pageCache, byte[] expectedHeader) throws IOException {
// WHEN
byte[] readHeader = new byte[expectedHeader.length];
AtomicInteger length = new AtomicInteger();
Header.Reader headerReader = headerData -> {
length.set(headerData.limit());
headerData.get(readHeader);
};
// Read as part of construction
// open/close is enough to read header
index(pageCache).with(headerReader).build().close();
// THEN
assertEquals(expectedHeader.length, length.get());
assertArrayEquals(expectedHeader, readHeader);
// WHEN
// Read separate
GBPTree.readHeader(pageCache, indexFile, headerReader, DEFAULT_DATABASE_NAME, NULL);
assertEquals(expectedHeader.length, length.get());
assertArrayEquals(expectedHeader, readHeader);
}
use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.
the class GBPTreeTest method overwriteHeaderMustOnlyOverwriteHeaderNotState.
@Test
void overwriteHeaderMustOnlyOverwriteHeaderNotState() throws Exception {
byte[] initialHeader = new byte[random.nextInt(100)];
random.nextBytes(initialHeader);
Consumer<PageCursor> headerWriter = pc -> pc.putBytes(initialHeader);
try (PageCache pageCache = createPageCache(defaultPageSize)) {
index(pageCache).with(headerWriter).build().close();
Pair<TreeState, TreeState> treeStatesBeforeOverwrite = readTreeStates(pageCache);
byte[] newHeader = new byte[random.nextInt(100)];
random.nextBytes(newHeader);
GBPTree.overwriteHeader(pageCache, indexFile, pc -> pc.putBytes(newHeader), DEFAULT_DATABASE_NAME, NULL);
Pair<TreeState, TreeState> treeStatesAfterOverwrite = readTreeStates(pageCache);
// TreeStates are the same
assertEquals(treeStatesBeforeOverwrite.getLeft(), treeStatesAfterOverwrite.getLeft(), "expected tree state to exactly the same before and after overwriting header");
assertEquals(treeStatesBeforeOverwrite.getRight(), treeStatesAfterOverwrite.getRight(), "expected tree state to exactly the same before and after overwriting header");
// Verify header was actually overwritten. Do this after reading tree states because it will bump tree generation.
verifyHeader(pageCache, newHeader);
}
}
use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.
the class GenericNativeIndexProviderTest method mustCompleteIndexDescriptorConfigurationsWithSpatialConfig.
@Test
void mustCompleteIndexDescriptorConfigurationsWithSpatialConfig() {
// Given
DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1);
// When
IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
// Then
IndexConfig sinfulIndexConfig = incompleteDescriptor.getIndexConfig();
IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
assertEquals(0, sinfulIndexConfig.entries().count(p -> true), "expected sinful index config to have no entries");
for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
}
}
use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"), databaseLayout.getDatabaseName(), NULL);
}
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
Throwable throwable = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof IllegalArgumentException).get();
assertEquals("Unknown store version 'bad'", throwable.getMessage());
} finally {
managementService.shutdown();
}
}
Aggregations