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
//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));
        }