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 shouldDelayFreeingOfAggressivelyReusedIds()
        public virtual void ShouldDelayFreeingOfAggressivelyReusedIds()
        {
            // GIVEN
            MockedIdGeneratorFactory     actual     = new MockedIdGeneratorFactory();
            ControllableSnapshotSupplier boundaries = new ControllableSnapshotSupplier();
            BufferingIdGeneratorFactory  bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(actual, IdReuseEligibility_Fields.Always, new CommunityIdTypeConfigurationProvider());

            bufferingIdGeneratorFactory.Initialize(boundaries);
            IdGenerator idGenerator = bufferingIdGeneratorFactory.Open(new File("doesnt-matter"), 10, IdType.StringBlock, () => 0L, int.MaxValue);

            // WHEN
            idGenerator.FreeId(7);
            verifyNoMoreInteractions(actual.Get(IdType.StringBlock));

            // after some maintenance and transaction still not closed
            bufferingIdGeneratorFactory.Maintenance();
            verifyNoMoreInteractions(actual.Get(IdType.StringBlock));

            // although after transactions have all closed
            boundaries.SetMostRecentlyReturnedSnapshotToAllClosed();
            bufferingIdGeneratorFactory.Maintenance();

            // THEN
            verify(actual.Get(IdType.StringBlock)).freeId(7);
        }
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 shouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell()
        public virtual void ShouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell()
        {
            // GIVEN
            MockedIdGeneratorFactory actual = new MockedIdGeneratorFactory();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.time.FakeClock clock = org.neo4j.time.Clocks.fakeClock();
            FakeClock clock = Clocks.fakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long safeZone = MINUTES.toMillis(1);
            long safeZone = MINUTES.toMillis(1);
            ControllableSnapshotSupplier boundaries = new ControllableSnapshotSupplier();
            BufferingIdGeneratorFactory  bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(actual, t => clock.Millis() - t.snapshotTime() >= safeZone, new CommunityIdTypeConfigurationProvider());

            bufferingIdGeneratorFactory.Initialize(boundaries);

            IdGenerator idGenerator = bufferingIdGeneratorFactory.Open(new File("doesnt-matter"), 10, IdType.StringBlock, () => 0L, int.MaxValue);

            // WHEN
            idGenerator.FreeId(7);
            verifyNoMoreInteractions(actual.Get(IdType.StringBlock));

            // after some maintenance and transaction still not closed
            bufferingIdGeneratorFactory.Maintenance();
            verifyNoMoreInteractions(actual.Get(IdType.StringBlock));

            // although after transactions have all closed
            boundaries.SetMostRecentlyReturnedSnapshotToAllClosed();
            bufferingIdGeneratorFactory.Maintenance();
            // ... the clock would still say "nope" so no interaction
            verifyNoMoreInteractions(actual.Get(IdType.StringBlock));

            // then finally after time has passed as well
            clock.Forward(70, SECONDS);
            bufferingIdGeneratorFactory.Maintenance();

            // THEN
            verify(actual.Get(IdType.StringBlock)).freeId(7);
        }