use of org.neo4j.kernel.impl.store.id.IdGeneratorFactory in project neo4j by neo4j.
the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.
@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {
private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
@Override
public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
if (idType == IdType.LABEL_TOKEN) {
IdGenerator generator = generators.get(idType);
if (generator == null) {
IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {
@Override
public long nextId() {
// Same exception as the one thrown by IdGeneratorImpl
throw new UnderlyingStorageException("Id capacity exceeded");
}
};
generators.put(idType, generator);
}
return generator;
}
return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
}
};
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {
@Override
protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
return new GraphDatabaseBuilder.DatabaseCreator() {
@Override
public GraphDatabaseService newDatabase(Map<String, String> config) {
return newDatabase(Config.embeddedDefaults(config));
}
@Override
public GraphDatabaseService newDatabase(@Nonnull Config config) {
return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {
@Override
protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {
@Override
protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
return idFactory;
}
};
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
}
}.initFacade(storeDir, config, dependencies, this);
}
};
}
};
}
};
return dbFactory.newImpermanentDatabase();
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorFactory in project neo4j by neo4j.
the class TestJumpingIdGenerator method testIt.
@Test
public void testIt() throws Exception {
int sizePerJump = 1000;
IdGeneratorFactory factory = new JumpingIdGeneratorFactory(sizePerJump);
IdGenerator generator = factory.get(IdType.NODE);
for (int i = 0; i < sizePerJump / 2; i++) {
assertEquals(i, generator.nextId());
}
for (int i = 0; i < sizePerJump - 1; i++) {
long expected = 0x100000000L - sizePerJump / 2 + i;
if (expected >= 0xFFFFFFFFL) {
expected++;
}
assertEquals(expected, generator.nextId());
}
for (int i = 0; i < sizePerJump; i++) {
assertEquals(0x200000000L - sizePerJump / 2 + i, generator.nextId());
}
for (int i = 0; i < sizePerJump; i++) {
assertEquals(0x300000000L - sizePerJump / 2 + i, generator.nextId());
}
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorFactory in project neo4j by neo4j.
the class ReplicatedTokenHolderTest method shouldReplicateTokenRequestForNewToken.
@Test
public void shouldReplicateTokenRequestForNewToken() throws Exception {
// given
StorageEngine storageEngine = mockedStorageEngine();
when(dependencies.resolveDependency(StorageEngine.class)).thenReturn(storageEngine);
IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
IdGenerator idGenerator = mock(IdGenerator.class);
when(idGenerator.nextId()).thenReturn(1L);
when(idGeneratorFactory.get(any(IdType.class))).thenReturn(idGenerator);
TokenRegistry<Token> registry = new TokenRegistry<>("Label");
int generatedTokenId = 1;
ReplicatedTokenHolder<Token> tokenHolder = new ReplicatedLabelTokenHolder(registry, (content, trackResult) -> {
CompletableFuture<Object> completeFuture = new CompletableFuture<>();
completeFuture.complete(generatedTokenId);
return completeFuture;
}, idGeneratorFactory, dependencies);
// when
Integer tokenId = tokenHolder.getOrCreateId("name1");
// then
assertThat(tokenId, equalTo(generatedTokenId));
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorFactory in project neo4j by neo4j.
the class RsdrMain method openStore.
private static StoreFactory openStore(FileSystemAbstraction fileSystem, File storeDir, Config config, PageCache pageCache) {
IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem);
NullLogProvider logProvider = NullLogProvider.getInstance();
return new StoreFactory(storeDir, config, idGeneratorFactory, pageCache, fileSystem, logProvider);
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorFactory in project neo4j by neo4j.
the class NeoStoreDataSourceTest method logModuleSetUpError.
@Test
public void logModuleSetUpError() throws Exception {
Config config = Config.embeddedDefaults(stringMap());
IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
Throwable openStoresError = new RuntimeException("Can't set up modules");
doThrow(openStoresError).when(idGeneratorFactory).create(any(File.class), anyLong(), anyBoolean());
CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
AssertableLogProvider logProvider = new AssertableLogProvider();
SimpleLogService logService = new SimpleLogService(logProvider, logProvider);
PageCache pageCache = pageCacheRule.getPageCache(fs.get());
NeoStoreDataSource dataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), idGeneratorFactory, idTypeConfigurationProvider, pageCache, config, mock(DatabaseHealth.class), logService);
try {
dataSource.start();
fail("Exception expected");
} catch (Exception e) {
assertEquals(openStoresError, e);
}
logProvider.assertAtLeastOnce(inLog(NeoStoreDataSource.class).warn(equalTo("Exception occurred while setting up store modules. Attempting to close things down."), equalTo(openStoresError)));
}
Aggregations