Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplicateTokenRequestForNewToken() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplicateTokenRequestForNewToken()
        {
            // given
            StorageEngine storageEngine = MockedStorageEngine();

            when(_storageEngineSupplier.get()).thenReturn(storageEngine);

            IdGeneratorFactory idGeneratorFactory = mock(typeof(IdGeneratorFactory));
            IdGenerator        idGenerator        = mock(typeof(IdGenerator));

            when(idGenerator.NextId()).thenReturn(1L);

            when(idGeneratorFactory.Get(any(typeof(IdType)))).thenReturn(idGenerator);

            TokenRegistry         registry         = new TokenRegistry("Label");
            int                   generatedTokenId = 1;
            ReplicatedTokenHolder tokenHolder      = new ReplicatedLabelTokenHolder(registry, (content, trackResult) =>
            {
                CompletableFuture <object> completeFuture = new CompletableFuture <object>();
                completeFuture.complete(generatedTokenId);
                return(completeFuture);
            }, idGeneratorFactory, _storageEngineSupplier);

            // when
            int?tokenId = tokenHolder.GetOrCreateId("name1");

            // then
            assertThat(tokenId, equalTo(generatedTokenId));
        }
Exemplo n.º 2
0
 public PropertyStore(File file, File idFile, Config configuration, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, DynamicStringStore stringPropertyStore, PropertyKeyTokenStore propertyKeyTokenStore, DynamicArrayStore arrayPropertyStore, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, configuration, IdType.PROPERTY, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Property(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
     this._stringStore            = stringPropertyStore;
     this._propertyKeyTokenStore  = propertyKeyTokenStore;
     this._arrayStore             = arrayPropertyStore;
     _allowStorePointsAndTemporal = recordFormats.HasCapability(Capability.POINT_PROPERTIES) && recordFormats.HasCapability(Capability.TEMPORAL_PROPERTIES);
 }
Exemplo n.º 3
0
        public virtual NeoStoreDataSource GetDataSource(DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, DependencyResolver otherCustomOverriddenDependencies)
        {
            ShutdownAnyRunning();

            StatementLocksFactory locksFactory   = mock(typeof(StatementLocksFactory));
            StatementLocks        statementLocks = mock(typeof(StatementLocks));

            Org.Neo4j.Kernel.impl.locking.Locks_Client locks = mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client));
            when(statementLocks.Optimistic()).thenReturn(locks);
            when(statementLocks.Pessimistic()).thenReturn(locks);
            when(locksFactory.NewInstance()).thenReturn(statementLocks);

            JobScheduler jobScheduler = mock(typeof(JobScheduler), RETURNS_MOCKS);
            Monitors     monitors     = new Monitors();

            Dependencies mutableDependencies = new Dependencies(otherCustomOverriddenDependencies);

            // Satisfy non-satisfied dependencies
            Config config = Dependency(mutableDependencies, typeof(Config), deps => Config.defaults());

            config.augment(default_schema_provider, EMPTY.ProviderDescriptor.name());
            LogService                  logService              = Dependency(mutableDependencies, typeof(LogService), deps => new SimpleLogService(NullLogProvider.Instance));
            IdGeneratorFactory          idGeneratorFactory      = Dependency(mutableDependencies, typeof(IdGeneratorFactory), deps => new DefaultIdGeneratorFactory(fs));
            IdTypeConfigurationProvider idConfigurationProvider = Dependency(mutableDependencies, typeof(IdTypeConfigurationProvider), deps => new CommunityIdTypeConfigurationProvider());
            DatabaseHealth              databaseHealth          = Dependency(mutableDependencies, typeof(DatabaseHealth), deps => new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance));
            SystemNanoClock             clock = Dependency(mutableDependencies, typeof(SystemNanoClock), deps => Clocks.nanoClock());
            TransactionMonitor          transactionMonitor        = Dependency(mutableDependencies, typeof(TransactionMonitor), deps => new DatabaseTransactionStats());
            DatabaseAvailabilityGuard   databaseAvailabilityGuard = Dependency(mutableDependencies, typeof(DatabaseAvailabilityGuard), deps => new DatabaseAvailabilityGuard(DEFAULT_DATABASE_NAME, deps.resolveDependency(typeof(SystemNanoClock)), NullLog.Instance));

            Dependency(mutableDependencies, typeof(DiagnosticsManager), deps => new DiagnosticsManager(NullLog.Instance));
            Dependency(mutableDependencies, typeof(IndexProvider), deps => EMPTY);

            _dataSource = new NeoStoreDataSource(new TestDatabaseCreationContext(DEFAULT_DATABASE_NAME, databaseLayout, config, idGeneratorFactory, logService, mock(typeof(JobScheduler), RETURNS_MOCKS), mock(typeof(TokenNameLookup)), mutableDependencies, mockedTokenHolders(), locksFactory, mock(typeof(SchemaWriteGuard)), mock(typeof(TransactionEventHandlers)), IndexingService.NO_MONITOR, fs, transactionMonitor, databaseHealth, mock(typeof(LogFileCreationMonitor)), TransactionHeaderInformationFactory.DEFAULT, new CommunityCommitProcessFactory(), mock(typeof(InternalAutoIndexing)), mock(typeof(IndexConfigStore)), mock(typeof(ExplicitIndexProvider)), pageCache, new StandardConstraintSemantics(), monitors, new Tracers("null", NullLog.Instance, monitors, jobScheduler, clock), mock(typeof(Procedures)), Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited, databaseAvailabilityGuard, clock, new CanWrite(), new StoreCopyCheckPointMutex(), RecoveryCleanupWorkCollector.immediate(), new BufferedIdController(new BufferingIdGeneratorFactory(idGeneratorFactory, Org.Neo4j.Kernel.impl.store.id.IdReuseEligibility_Fields.Always, idConfigurationProvider), jobScheduler), DatabaseInfo.COMMUNITY, new TransactionVersionContextSupplier(), ON_HEAP, Collections.emptyList(), file => EMPTY_WATCHER, new GraphDatabaseFacade(), Iterables.empty()));
            return(_dataSource);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void logModuleSetUpError()
        public virtual void LogModuleSetUpError()
        {
            Config             config             = Config.defaults();
            IdGeneratorFactory idGeneratorFactory = mock(typeof(IdGeneratorFactory));
            Exception          openStoresError    = new Exception("Can't set up modules");

            doThrow(openStoresError).when(idGeneratorFactory).create(any(typeof(File)), anyLong(), anyBoolean());

            CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
            AssertableLogProvider logProvider  = new AssertableLogProvider();
            SimpleLogService      logService   = new SimpleLogService(logProvider, logProvider);
            PageCache             pageCache    = PageCacheRule.getPageCache(Fs.get());
            Dependencies          dependencies = new Dependencies();

            dependencies.SatisfyDependencies(idGeneratorFactory, idTypeConfigurationProvider, config, logService);

            NeoStoreDataSource dataSource = DsRule.getDataSource(Dir.databaseLayout(), Fs.get(), pageCache, dependencies);

            try
            {
                dataSource.Start();
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertEquals(openStoresError, e);
            }

            logProvider.AssertAtLeastOnce(inLog(typeof(NeoStoreDataSource)).warn(equalTo("Exception occurred while setting up store modules. Attempting to close things down."), equalTo(openStoresError)));
        }
Exemplo n.º 5
0
        public void GetCurrentId_ReturnsEmpty_WhenNextNeverCalled()
        {
            var idGenerator = IdGeneratorFactory.GetGuidIdGenerator();

            var sut = idGenerator.GetCurrentId();

            Assert.Equal(Guid.Empty, sut);
        }
Exemplo n.º 6
0
 // TODO: Clean up all the resolving, which now happens every time with special selection strategies.
 internal ReplicatedTokenHolder(TokenRegistry tokenRegistry, Replicator replicator, IdGeneratorFactory idGeneratorFactory, IdType tokenIdType, System.Func <StorageEngine> storageEngineSupplier, TokenType type, ReplicatedTokenCreator tokenCreator) : base(tokenRegistry)
 {
     this._replicator         = replicator;
     this._idGeneratorFactory = idGeneratorFactory;
     this._tokenIdType        = tokenIdType;
     this._type = type;
     this._storageEngineSupplier = storageEngineSupplier;
     this._tokenCreator          = tokenCreator;
 }
Exemplo n.º 7
0
        public void GetCurrentId_ReturnsSameAsPrevious()
        {
            var idGenerator = IdGeneratorFactory.GetIntIdGenerator(100);

            idGenerator.GetNextId();
            var sut = idGenerator.GetCurrentId();

            Assert.Equal(101, sut);
        }
Exemplo n.º 8
0
 public HaIdGeneratorFactory(DelegateInvocationHandler <Master> master, LogProvider logProvider, RequestContextFactory requestContextFactory, FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider)
 {
     this._fs = fs;
     this._idTypeConfigurationProvider = idTypeConfigurationProvider;
     this._localFactory          = new DefaultIdGeneratorFactory(fs, idTypeConfigurationProvider);
     this._master                = master;
     this._log                   = logProvider.getLog(this.GetType());
     this._requestContextFactory = requestContextFactory;
 }
        public void GetNext()
        {
            var g = new Mock <IIdGenerator>();
            var f = new IdGeneratorFactory();

            f.AddOrReplace(typeof(string), g.Object);
            f.GetNext <string>();
            g.Verify(gn => gn.GetNext(), Times.Once);
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private NodeStore newNodeStore(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException
        private NodeStore NewNodeStore(FileSystemAbstraction fs, PageCache pageCache)
        {
            _idGeneratorFactory = spy(new DefaultIdGeneratorFactoryAnonymousInnerClass(this, fs));
            StoreFactory factory = new StoreFactory(_testDirectory.databaseLayout("new"), Config.defaults(), _idGeneratorFactory, pageCache, fs, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            _neoStores = factory.OpenAllNeoStores(true);
            _nodeStore = _neoStores.NodeStore;
            return(_nodeStore);
        }
        public virtual string GetInitialUserId()
        {
            if (string.IsNullOrEmpty(_initialUserId))
            {
                _initialUserId = IdGeneratorFactory.GetMongoIdGenerator().GenerateId();
            }

            return(_initialUserId);
        }
Exemplo n.º 12
0
        public void GetCurrentId_ReturnsSameAsPrevious()
        {
            var idGenerator = IdGeneratorFactory.GetGuidIdGenerator();

            var id  = idGenerator.GetNextId();
            var sut = idGenerator.GetCurrentId();

            Assert.Equal(id, sut);
        }
Exemplo n.º 13
0
        public void AddOrReplace_Adds()
        {
            var f = new IdGeneratorFactory();

            f.GetGenerator(typeof(int)).ShouldBeNull();
            var g = new Mock <IIdGenerator>();

            f.AddOrReplace(typeof(int), g.Object);
            f.GetGenerator(typeof(int)).ShouldBe(g.Object);
        }
Exemplo n.º 14
0
        public void GetNumberOfIdsGenerated_ReturnsCorrectValue()
        {
            var idGenerator = IdGeneratorFactory.GetIntIdGenerator();

            idGenerator.GetNextId();
            idGenerator.GetNextId();

            var sut = idGenerator.GetNumberOfIdsGenerated();

            Assert.Equal(2, sut);
        }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseIdsInCluster() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReuseIdsInCluster()
        {
            _cluster = ClusterRule.startCluster();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong first = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong first = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong second = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong second = new MutableLong();

            CoreClusterMember leader1 = CreateThreeNodes(_cluster, first, second);
            CoreClusterMember leader2 = RemoveTwoNodes(_cluster, first, second);

            assumeTrue(leader1 != null && leader1.Equals(leader2));

            // Force maintenance on leader
            IdMaintenanceOnLeader(leader1);
            IdGeneratorFactory idGeneratorFactory = ResolveDependency(leader1, typeof(IdGeneratorFactory));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.id.IdGenerator idGenerator = idGeneratorFactory.get(org.neo4j.kernel.impl.store.id.IdType.NODE);
            IdGenerator idGenerator = idGeneratorFactory.Get(IdType.NODE);

            assertEquals(2, idGenerator.DefragCount);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node1id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node1id = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node2id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node2id = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node3id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node3id = new MutableLong();

            CoreClusterMember clusterMember = _cluster.coreTx((db, tx) =>
            {
                Node node1 = Db.createNode();
                Node node2 = Db.createNode();
                Node node3 = Db.createNode();

                node1id.Value = node1.Id;
                node2id.Value = node2.Id;
                node3id.Value = node3.Id;

                tx.success();
            });

            assumeTrue(leader1.Equals(clusterMember));

            assertEquals(first.longValue(), node1id.longValue());
            assertEquals(second.longValue(), node2id.longValue());
            assertEquals(idGenerator.HighestPossibleIdInUse, node3id.longValue());
        }
Exemplo n.º 16
0
        public void GetNextId_ReturnsNewValue()
        {
            var idGenerator = IdGeneratorFactory.GetGuidIdGenerator();

            var sutA = idGenerator.GetNextId();
            var sutB = idGenerator.GetNextId();

            Assert.NotEqual(sutA, sutB);
            Assert.NotEqual(Guid.Empty, sutA);
            Assert.NotEqual(Guid.Empty, sutB);
        }
Exemplo n.º 17
0
        public void GetNextId_ReturnsNewValue_WhenNoStartIdSupplied()
        {
            var idGenerator = IdGeneratorFactory.GetLongIdGenerator();

            var sutA = idGenerator.GetNextId();
            var sutB = idGenerator.GetNextId();
            var sutC = idGenerator.GetNextId();

            Assert.Equal(1, sutA);
            Assert.Equal(2, sutB);
            Assert.Equal(3, sutC);
        }
Exemplo n.º 18
0
        public void initializeEvolution(int populationSize, NeatGenome seedGenome)
        {
            if (seedGenome == null)
            {
                initializeEvolution(populationSize);
                return;
            }
            logOutput = new StreamWriter(outputFolder + "logfile.txt");
            IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);

            ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, experiment.DefaultNeatParameters, idgen)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters);
        }
Exemplo n.º 19
0
        public void GetNextId_ReturnsNewValue_WhenStartIdSupplied()
        {
            var idGenerator = IdGeneratorFactory.GetIntIdGenerator(100);

            var sutA = idGenerator.GetNextId();
            var sutB = idGenerator.GetNextId();
            var sutC = idGenerator.GetNextId();

            Assert.Equal(101, sutA);
            Assert.Equal(102, sutB);
            Assert.Equal(103, sutC);
        }
Exemplo n.º 20
0
        public void AddOrReplace_Replaces()
        {
            var f = new IdGeneratorFactory();

            var g1 = new Mock <IIdGenerator>();

            f.AddOrReplace(typeof(int), g1.Object);

            var g2 = new Mock <IIdGenerator>();

            f.AddOrReplace(typeof(int), g2.Object);
            f.GetGenerator(typeof(int)).ShouldBe(g2.Object);
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void newLeaderShouldNotReuseIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void NewLeaderShouldNotReuseIds()
        {
            _cluster = ClusterRule.startCluster();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong first = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong first = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong second = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong second = new MutableLong();

            CoreClusterMember creationLeader = CreateThreeNodes(_cluster, first, second);
            CoreClusterMember deletionLeader = RemoveTwoNodes(_cluster, first, second);

            // the following assumption is not sufficient for the subsequent assertions, since leadership is a volatile state
            assumeTrue(creationLeader != null && creationLeader.Equals(deletionLeader));

            IdMaintenanceOnLeader(creationLeader);
            IdGeneratorFactory idGeneratorFactory        = ResolveDependency(creationLeader, typeof(IdGeneratorFactory));
            IdGenerator        creationLeaderIdGenerator = idGeneratorFactory.Get(IdType.NODE);

            assertEquals(2, creationLeaderIdGenerator.DefragCount);

            // Force leader switch
            _cluster.removeCoreMemberWithServerId(creationLeader.ServerId());

            // waiting for new leader
            CoreClusterMember newLeader = _cluster.awaitLeader();

            assertNotSame(creationLeader.ServerId(), newLeader.ServerId());
            IdMaintenanceOnLeader(newLeader);

            IdGeneratorFactory newLeaderIdGeneratorFactory = ResolveDependency(newLeader, typeof(IdGeneratorFactory));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.id.IdGenerator idGenerator = newLeaderIdGeneratorFactory.get(org.neo4j.kernel.impl.store.id.IdType.NODE);
            IdGenerator idGenerator = newLeaderIdGeneratorFactory.Get(IdType.NODE);

            assertEquals(0, idGenerator.DefragCount);

            CoreClusterMember newCreationLeader = _cluster.coreTx((db, tx) =>
            {
                Node node = Db.createNode();
                assertEquals(idGenerator.HighestPossibleIdInUse, node.Id);

                tx.success();
            });

            assumeTrue(newLeader.Equals(newCreationLeader));
        }
Exemplo n.º 22
0
        internal ModularDatabaseCreationContext(string databaseName, PlatformModule platformModule, DatabaseEditionContext editionContext, Procedures procedures, GraphDatabaseFacade facade)
        {
            this._databaseName = databaseName;
            this._config       = platformModule.Config;
            DatabaseIdContext idContext = editionContext.IdContext;

            this._idGeneratorFactory = idContext.IdGeneratorFactory;
            this._idController       = idContext.IdController;
            this._databaseLayout     = platformModule.StoreLayout.databaseLayout(databaseName);
            this._logService         = platformModule.Logging;
            this._scheduler          = platformModule.JobScheduler;
            this._globalDependencies = platformModule.Dependencies;
            this._tokenHolders       = editionContext.CreateTokenHolders();
            this._tokenNameLookup    = new NonTransactionalTokenNameLookup(_tokenHolders);
            this._locks = editionContext.CreateLocks();
            this._statementLocksFactory    = editionContext.CreateStatementLocksFactory();
            this._schemaWriteGuard         = editionContext.SchemaWriteGuard;
            this._transactionEventHandlers = new TransactionEventHandlers(facade);
            this._monitors = new Monitors(platformModule.Monitors);
            this._indexingServiceMonitor = _monitors.newMonitor(typeof(IndexingService.Monitor));
            this._physicalLogMonitor     = _monitors.newMonitor(typeof(LogFileCreationMonitor));
            this._fs = platformModule.FileSystem;
            this._transactionStats = editionContext.CreateTransactionMonitor();
            this._databaseHealth   = new DatabaseHealth(platformModule.PanicEventGenerator, _logService.getInternalLog(typeof(DatabaseHealth)));
            this._transactionHeaderInformationFactory = editionContext.HeaderInformationFactory;
            this._commitProcessFactory  = editionContext.CommitProcessFactory;
            this._autoIndexing          = new InternalAutoIndexing(platformModule.Config, _tokenHolders.propertyKeyTokens());
            this._indexConfigStore      = new IndexConfigStore(_databaseLayout, _fs);
            this._explicitIndexProvider = new DefaultExplicitIndexProvider();
            this._pageCache             = platformModule.PageCache;
            this._constraintSemantics   = editionContext.ConstraintSemantics;
            this._tracers    = platformModule.Tracers;
            this._procedures = procedures;
            this._ioLimiter  = editionContext.IoLimiter;
            this._clock      = platformModule.Clock;
            this._databaseAvailabilityGuard    = editionContext.CreateDatabaseAvailabilityGuard(_clock, _logService, _config);
            this._databaseAvailability         = new DatabaseAvailability(_databaseAvailabilityGuard, _transactionStats, platformModule.Clock, AwaitActiveTransactionDeadlineMillis);
            this._coreAPIAvailabilityGuard     = new CoreAPIAvailabilityGuard(_databaseAvailabilityGuard, editionContext.TransactionStartTimeout);
            this._accessCapability             = editionContext.AccessCapability;
            this._storeCopyCheckPointMutex     = new StoreCopyCheckPointMutex();
            this._recoveryCleanupWorkCollector = platformModule.RecoveryCleanupWorkCollector;
            this._databaseInfo               = platformModule.DatabaseInfo;
            this._versionContextSupplier     = platformModule.VersionContextSupplier;
            this._collectionsFactorySupplier = platformModule.CollectionsFactorySupplier;
            this._kernelExtensionFactories   = platformModule.KernelExtensionFactories;
            this._watcherServiceFactory      = editionContext.WatcherServiceFactory;
            this._facade          = facade;
            this._engineProviders = platformModule.EngineProviders;
        }
Exemplo n.º 23
0
        public void initializeEvolution(int populationSize, NeatGenome seedGenome)
        {
            if (seedGenome == null)
            {
                initializeEvolution(populationSize);
                return;
            }
            if (logOutput != null)
            {
                logOutput.Close();
            }
            logOutput = new StreamWriter(outputFolder + "logfile.txt");
            IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);

            ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, neatParams, idgen)), populationEval, neatParams);
        }
        public User[] GetUsers()
        {
            return(Seed(nameof(GetUsers), key =>
            {
                var users = new User[10];

                for (var i = 0; i < users.Length; i++)
                {
                    var user = new User
                    {
                        Name = $"Seed Name {i + 1}",
                        Passwd = "123456"
                    };

                    user.Id = i is 0 ? GetInitialUserId() : IdGeneratorFactory.GetMongoIdGenerator().GenerateId();
                    user.PopulateCreation(GetInitialUserId(), DateTimeOffset.UtcNow);

                    users[i] = user;
                }

                return users;
            }));
        }
Exemplo n.º 25
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: NeoStores(org.neo4j.io.layout.DatabaseLayout layout, org.neo4j.kernel.configuration.Config config, org.neo4j.kernel.impl.store.id.IdGeneratorFactory idGeneratorFactory, org.neo4j.io.pagecache.PageCache pageCache, final org.neo4j.logging.LogProvider logProvider, org.neo4j.io.fs.FileSystemAbstraction fileSystemAbstraction, org.neo4j.io.pagecache.tracing.cursor.context.VersionContextSupplier versionContextSupplier, org.neo4j.kernel.impl.store.format.RecordFormats recordFormats, boolean createIfNotExist, StoreType[] storeTypes, java.nio.file.OpenOption[] openOptions)
        internal NeoStores(DatabaseLayout layout, Config config, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, FileSystemAbstraction fileSystemAbstraction, VersionContextSupplier versionContextSupplier, RecordFormats recordFormats, bool createIfNotExist, StoreType[] storeTypes, OpenOption[] openOptions)
        {
            this._layout                 = layout;
            this._metadataStore          = layout.MetadataStore();
            this._config                 = config;
            this._idGeneratorFactory     = idGeneratorFactory;
            this._pageCache              = pageCache;
            this._logProvider            = logProvider;
            this._fileSystemAbstraction  = fileSystemAbstraction;
            this._versionContextSupplier = versionContextSupplier;
            this._recordFormats          = recordFormats;
            this._createIfNotExist       = createIfNotExist;
            this._openOptions            = openOptions;

            VerifyRecordFormat();
            _stores = new object[StoreType.values().length];
            try
            {
                foreach (StoreType type in storeTypes)
                {
                    GetOrCreateStore(type);
                }
            }
            catch (Exception initException)
            {
                try
                {
                    Close();
                }
                catch (Exception closeException)
                {
                    initException.addSuppressed(closeException);
                }
                throw initException;
            }
            _initializedStores = storeTypes;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes the EA with an initial population generated from a single seed genome.
        /// </summary>
        public void initializeEvolution(int populationSize, NeatGenome seedGenome)
        {
            if (seedGenome == null)
            {
                initializeEvolution(populationSize);
                return;
            }

            LogOutput                 = Logging ? new StreamWriter(Path.Combine(OutputFolder, "log.txt")) : null;
            FinalPositionOutput       = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "final-position.txt")) : null;
            ArchiveModificationOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "archive-mods.txt")) : null;
            ComplexityOutput          = new StreamWriter(Path.Combine(OutputFolder, "complexity.txt"));
            ComplexityOutput.WriteLine("avg,stdev,min,max");
            if (FinalPositionLogging)
            {
                FinalPositionOutput.WriteLine("x,y");
                ArchiveModificationOutput.WriteLine("ID,action,time,x,y");
            }
            IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);

            EA = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, experiment.DefaultNeatParameters, idgen)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters);
            EA.outputFolder = OutputFolder;
            EA.neatBrain    = NEATBrain;
        }
Exemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void reusePreviouslyFreedIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReusePreviouslyFreedIds()
        {
            _cluster = ClusterRule.startCluster();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong first = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong first = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong second = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong second = new MutableLong();

            CoreClusterMember creationLeader = CreateThreeNodes(_cluster, first, second);
            CoreClusterMember deletionLeader = RemoveTwoNodes(_cluster, first, second);

            assumeTrue(creationLeader != null && creationLeader.Equals(deletionLeader));
            IdGeneratorFactory idGeneratorFactory = ResolveDependency(creationLeader, typeof(IdGeneratorFactory));

            IdMaintenanceOnLeader(creationLeader);
            IdGenerator creationLeaderIdGenerator = idGeneratorFactory.Get(IdType.NODE);

            assertEquals(2, creationLeaderIdGenerator.DefragCount);

            // Restart and re-elect first leader
            _cluster.removeCoreMemberWithServerId(creationLeader.ServerId());
            _cluster.addCoreMemberWithId(creationLeader.ServerId()).start();

            CoreClusterMember leader = _cluster.awaitLeader();

            while (leader.ServerId() != creationLeader.ServerId())
            {
                _cluster.removeCoreMemberWithServerId(leader.ServerId());
                _cluster.addCoreMemberWithId(leader.ServerId()).start();
                leader = _cluster.awaitLeader();
            }

            IdMaintenanceOnLeader(leader);
            IdGeneratorFactory leaderIdGeneratorFactory = ResolveDependency(leader, typeof(IdGeneratorFactory));

            creationLeaderIdGenerator = leaderIdGeneratorFactory.Get(IdType.NODE);
            assertEquals(2, creationLeaderIdGenerator.DefragCount);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node1id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node1id = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node2id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong       node2id     = new MutableLong();
            CoreClusterMember reuseLeader = _cluster.coreTx((db, tx) =>
            {
                Node node1 = Db.createNode();
                Node node2 = Db.createNode();

                node1id.Value = node1.Id;
                node2id.Value = node2.Id;

                tx.success();
            });

            assumeTrue(leader.Equals(reuseLeader));

            assertEquals(first.longValue(), node1id.longValue());
            assertEquals(second.longValue(), node2id.longValue());
        }
Exemplo n.º 28
0
 public RelationshipStore(File file, File idFile, Config configuration, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, configuration, IdType.RELATIONSHIP, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Relationship(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
 }
Exemplo n.º 29
0
 public LabelTokenStore(File file, File idFile, Config config, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, DynamicStringStore nameStore, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, config, IdType.LABEL_TOKEN, idGeneratorFactory, pageCache, logProvider, nameStore, TYPE_DESCRIPTOR, recordFormats.LabelToken(), recordFormats.StoreVersion(), openOptions)
 {
 }
Exemplo n.º 30
0
 internal TheStore(File file, File idFile, Config configuration, IdType idType, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, RecordFormat <TheRecord> recordFormat, params OpenOption[] openOptions) : base(file, idFile, configuration, idType, idGeneratorFactory, pageCache, logProvider, "TheType", recordFormat, NoStoreHeaderFormat.NoStoreHeaderFormatConflict, "v1", openOptions)
 {
 }