use of java.util.function.Function 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 java.util.function.Function in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps.
@Test
public void shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps() throws Exception {
// given
Function<Long, Command.NodeCommand> newNodeCommandFunction = (i) -> new Command.NodeCommand(new NodeRecord(i, false, false, -1, -1, -1), new NodeRecord(i, true, false, -1, -1, -1));
writeTxContent(logFile(1), 40L, newNodeCommandFunction.apply(1L));
writeTxContent(logFile(1), 41L, newNodeCommandFunction.apply(2L));
writeTxContent(logFile(1), 42L, newNodeCommandFunction.apply(3L));
writeTxContent(logFile(2), 43L, newNodeCommandFunction.apply(4L));
writeTxContent(logFile(2), 44L, newNodeCommandFunction.apply(5L));
writeTxContent(logFile(2), 45L, newNodeCommandFunction.apply(6L));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// when
checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, CHECK_TYPES);
// then
assertTrue(handler.txIdSequenceInconsistencies.isEmpty());
}
use of java.util.function.Function in project neo4j by neo4j.
the class ReadReplicaReplicationIT method aReadReplicShouldBeAbleToRejoinTheCluster.
@Test
public void aReadReplicShouldBeAbleToRejoinTheCluster() throws Exception {
int readReplicaId = 4;
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
cluster.coreTx(createSomeData);
cluster.addReadReplicaWithId(readReplicaId).start();
// let's spend some time by adding more data
cluster.coreTx(createSomeData);
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
cluster.removeReadReplicaWithMemberId(readReplicaId);
// let's spend some time by adding more data
cluster.coreTx(createSomeData);
cluster.addReadReplicaWithId(readReplicaId).start();
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
Function<ClusterMember, DbRepresentation> toRep = db -> DbRepresentation.of(db.database());
Set<DbRepresentation> dbs = cluster.coreMembers().stream().map(toRep).collect(toSet());
dbs.addAll(cluster.readReplicas().stream().map(toRep).collect(toSet()));
cluster.shutdown();
assertEquals(1, dbs.size());
}
use of java.util.function.Function in project neo4j by neo4j.
the class LegacyIndexTransactionStateImplTest method newLegacyIndexTxState.
private static LegacyIndexTransactionStateImpl newLegacyIndexTxState() {
IndexConfigStore indexConfigStore = mock(IndexConfigStore.class);
when(indexConfigStore.get(eq(Node.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
when(indexConfigStore.get(eq(Relationship.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
Function<String, IndexImplementation> providerLookup = s -> mock(IndexImplementation.class);
return new LegacyIndexTransactionStateImpl(indexConfigStore, providerLookup);
}
use of java.util.function.Function in project neo4j by neo4j.
the class HighlyAvailableKernelData method getClusterInfo.
public ClusterMemberInfo[] getClusterInfo() {
List<ClusterMemberInfo> clusterMemberInfos = new ArrayList<ClusterMemberInfo>();
Function<Object, String> nullSafeToString = from -> from == null ? "" : from.toString();
for (ClusterMember clusterMember : memberInfo.getMembers()) {
ClusterMemberInfo clusterMemberInfo = new ClusterMemberInfo(clusterMember.getInstanceId().toString(), clusterMember.getHAUri() != null, clusterMember.isAlive(), clusterMember.getHARole(), asArray(String.class, map(nullSafeToString, clusterMember.getRoleURIs())), asArray(String.class, map(nullSafeToString, clusterMember.getRoles())));
clusterMemberInfos.add(clusterMemberInfo);
}
return clusterMemberInfos.toArray(new ClusterMemberInfo[clusterMemberInfos.size()]);
}
Aggregations