Esempio 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));
        }
Esempio n. 2
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;
 }
Esempio n. 3
0
        internal static TokenRegistry CreatePopulatedTokenRegistry(string tokenType, int[] tokenIds)
        {
            TokenRegistry      tokenRegistry = new TokenRegistry(tokenType);
            IList <NamedToken> tokens        = new List <NamedToken>();

            foreach (int propertyId in tokenIds)
            {
                tokens.Add(new NamedToken(tokenType + propertyId, propertyId));
            }
            tokenRegistry.InitialTokens = tokens;
            return(tokenRegistry);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStoreInitialTokens()
        public virtual void ShouldStoreInitialTokens()
        {
            // given
            TokenRegistry         registry    = new TokenRegistry("Label");
            ReplicatedTokenHolder tokenHolder = new ReplicatedLabelTokenHolder(registry, null, null, _storageEngineSupplier);

            // when
            tokenHolder.InitialTokens = asList(new NamedToken("name1", 1), new NamedToken("name2", 2));

            // then
            assertThat(tokenHolder.AllTokens, hasItems(new NamedToken("name1", 1), new NamedToken("name2", 2)));
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnExistingTokenId()
        public virtual void ShouldReturnExistingTokenId()
        {
            // given
            TokenRegistry         registry    = new TokenRegistry("Label");
            ReplicatedTokenHolder tokenHolder = new ReplicatedLabelTokenHolder(registry, null, null, _storageEngineSupplier);

            tokenHolder.InitialTokens = asList(new NamedToken("name1", 1), new NamedToken("name2", 2));

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

            // then
            assertThat(tokenId, equalTo(1));
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateTokenId()
        public virtual void ShouldCreateTokenId()
        {
            // given
            TokenRegistry registry = new TokenRegistry("Label");
            ReplicatedTokenStateMachine stateMachine = new ReplicatedTokenStateMachine(registry, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            stateMachine.InstallCommitProcess(mock(typeof(TransactionCommitProcess)), -1);

            // when
            sbyte[] commandBytes = commandBytes(TokenCommands(_expectedTokenId));
            stateMachine.ApplyCommand(new ReplicatedTokenRequest(LABEL, "Person", commandBytes), 1, r =>
            {
            });

            // then
            assertEquals(_expectedTokenId, ( int )registry.GetId("Person"));
        }
Esempio n. 7
0
 public ReplicatedTokenStateMachine(TokenRegistry tokenRegistry, LogProvider logProvider, VersionContextSupplier versionContextSupplier)
 {
     this._tokenRegistry  = tokenRegistry;
     this._versionContext = versionContextSupplier.VersionContext;
     this._log            = logProvider.getLog(this.GetType());
 }
Esempio n. 8
0
        /// <summary>
        /// Gets the token associated with the given text
        /// </summary>
        /// <param name="reg">Token registry</param>
        /// <param name="text">Token text</param>
        /// <returns>Token, or -1 if not found</returns>
        private int GetToken(TokenRegistry[] reg, string text)
        {
            int index = Array.BinarySearch(reg, text.ToLower());

            if (index >= 0)
                return (reg[index].Token);

            return (-1);
        }
Esempio n. 9
0
        public CoreStateMachinesModule(MemberId myself, PlatformModule platformModule, File clusterStateDirectory, Config config, RaftReplicator replicator, RaftMachine raftMachine, Dependencies dependencies, LocalDatabase localDatabase)
        {
            StateStorage <IdAllocationState>        idAllocationState;
            StateStorage <ReplicatedLockTokenState> lockTokenState;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.lifecycle.LifeSupport life = platformModule.life;
            LifeSupport life = platformModule.Life;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.FileSystemAbstraction fileSystem = platformModule.fileSystem;
            FileSystemAbstraction fileSystem  = platformModule.FileSystem;
            LogService            logging     = platformModule.Logging;
            LogProvider           logProvider = logging.InternalLogProvider;

            lockTokenState = life.Add(new DurableStateStorage <>(fileSystem, clusterStateDirectory, LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal(new MemberId.Marshal()), config.Get(replicated_lock_token_state_size), logProvider));

            idAllocationState = life.Add(new DurableStateStorage <>(fileSystem, clusterStateDirectory, ID_ALLOCATION_NAME, new IdAllocationState.Marshal(), config.Get(id_alloc_state_size), logProvider));

            ReplicatedIdAllocationStateMachine idAllocationStateMachine = new ReplicatedIdAllocationStateMachine(idAllocationState);

            IDictionary <IdType, int> allocationSizes = GetIdTypeAllocationSizeFromConfig(config);

            ReplicatedIdRangeAcquirer idRangeAcquirer = new ReplicatedIdRangeAcquirer(replicator, idAllocationStateMachine, allocationSizes, myself, logProvider);

            IdTypeConfigurationProvider = new EnterpriseIdTypeConfigurationProvider(config);
            CommandIndexTracker commandIndexTracker = dependencies.SatisfyDependency(new CommandIndexTracker());

            FreeIdCondition         = new IdReusabilityCondition(commandIndexTracker, raftMachine, myself);
            this.IdGeneratorFactory = CreateIdGeneratorFactory(fileSystem, idRangeAcquirer, logProvider, IdTypeConfigurationProvider);

            TokenRegistry relationshipTypeTokenRegistry = new TokenRegistry(Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_RELATIONSHIP_TYPE);

            System.Func <StorageEngine>           storageEngineSupplier       = () => localDatabase.DataSource().DependencyResolver.resolveDependency(typeof(StorageEngine));
            ReplicatedRelationshipTypeTokenHolder relationshipTypeTokenHolder = new ReplicatedRelationshipTypeTokenHolder(relationshipTypeTokenRegistry, replicator, this.IdGeneratorFactory, storageEngineSupplier);

            TokenRegistry propertyKeyTokenRegistry = new TokenRegistry(Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_PROPERTY_KEY);
            ReplicatedPropertyKeyTokenHolder propertyKeyTokenHolder = new ReplicatedPropertyKeyTokenHolder(propertyKeyTokenRegistry, replicator, this.IdGeneratorFactory, storageEngineSupplier);

            TokenRegistry labelTokenRegistry            = new TokenRegistry(Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_LABEL);
            ReplicatedLabelTokenHolder labelTokenHolder = new ReplicatedLabelTokenHolder(labelTokenRegistry, replicator, this.IdGeneratorFactory, storageEngineSupplier);

            ReplicatedLockTokenStateMachine replicatedLockTokenStateMachine = new ReplicatedLockTokenStateMachine(lockTokenState);

            VersionContextSupplier      versionContextSupplier = platformModule.VersionContextSupplier;
            ReplicatedTokenStateMachine labelTokenStateMachine = new ReplicatedTokenStateMachine(labelTokenRegistry, logProvider, versionContextSupplier);

            ReplicatedTokenStateMachine propertyKeyTokenStateMachine = new ReplicatedTokenStateMachine(propertyKeyTokenRegistry, logProvider, versionContextSupplier);

            ReplicatedTokenStateMachine relationshipTypeTokenStateMachine = new ReplicatedTokenStateMachine(relationshipTypeTokenRegistry, logProvider, versionContextSupplier);

            PageCursorTracerSupplier          cursorTracerSupplier     = platformModule.Tracers.pageCursorTracerSupplier;
            ReplicatedTransactionStateMachine replicatedTxStateMachine = new ReplicatedTransactionStateMachine(commandIndexTracker, replicatedLockTokenStateMachine, config.Get(state_machine_apply_max_batch_size), logProvider, cursorTracerSupplier, versionContextSupplier);

            dependencies.SatisfyDependencies(replicatedTxStateMachine);

            LocksFactory lockFactory = createLockFactory(config, logging);

            LocksSupplier = () => CreateLockManager(lockFactory, config, platformModule.Clock, replicator, myself, raftMachine, replicatedLockTokenStateMachine);

            RecoverConsensusLogIndex consensusLogIndexRecovery = new RecoverConsensusLogIndex(localDatabase, logProvider);

            CoreStateMachines = new CoreStateMachines(replicatedTxStateMachine, labelTokenStateMachine, relationshipTypeTokenStateMachine, propertyKeyTokenStateMachine, replicatedLockTokenStateMachine, idAllocationStateMachine, new DummyMachine(), localDatabase, consensusLogIndexRecovery);

            CommitProcessFactory = (appender, applier, ignored) =>
            {
                localDatabase.RegisterCommitProcessDependencies(appender, applier);
                return(new ReplicatedTransactionCommitProcess(replicator));
            };

            this.TokenHolders = new TokenHolders(propertyKeyTokenHolder, labelTokenHolder, relationshipTypeTokenHolder);
            dependencies.SatisfyDependencies(TokenHolders);
        }
Esempio n. 10
0
 public TokenParser(TokenRegistry tokenRegistry)
 {
     this._tokenRegistry = tokenRegistry;
 }
Esempio n. 11
0
 internal SimpleTokenHolder(TokenRegistry tokenRegistry) : base(tokenRegistry)
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of a Grammar, initially empty.
 /// </summary>
 /// <param name="tokenRegistry">The token registry to use to verify referenced tokens types are defined.</param>
 public Grammar(TokenRegistry tokenRegistry)
 {
     this.tokenRegistry = tokenRegistry;
     this.expressionLookup = new Dictionary<string, ExpressionDefinition>();
 }