Ejemplo n.º 1
0
        public void BitMachineIdSet_SetExistenceForEmptyTests()
        {
            var set1 = MachineIdSet.Empty;

            set1 = set1.Add(MachineId.FromIndex(1));
            set1[1].Should().BeTrue();
        }
        public Task FlushingCountsCorrectly()
        {
            ContentLocationDatabaseConfiguration configuration = new MemoryContentLocationDatabaseConfiguration
            {
                ContentCacheEnabled = true,
                // These ensure no flushing happens unless explicitly directed
                CacheFlushingMaximumInterval = Timeout.InfiniteTimeSpan,
                CacheMaximumUpdatesPerFlush  = 5,
                FlushPreservePercentInMemory = 0.5,
            };

            return(RunCustomTest(configuration, async(context, database) =>
            {
                // If the counting is done correctly, then writing 5 times to the same entry should trigger a single flush
                var shortHash = new ShortHash(ContentHash.Random());
                foreach (var i in Enumerable.Range(1, 4))
                {
                    database.LocationAdded(context, shortHash, MachineId.FromIndex(i), 200);
                }

                database.CacheUpdatesSinceLastFlush.Should().Be(4);
                database.LocationAdded(context, shortHash, new MachineId(5), 200);
                await database.FlushTask;

                database.Counters[ContentLocationDatabaseCounters.TotalNumberOfCacheFlushes].Value.Should().Be(1);
                database.CacheUpdatesSinceLastFlush.Should().Be(0);
            }));
        }
Ejemplo n.º 3
0
        public void MachineIdIndexShouldBePresent()
        {
            var set1 = MachineIdSet.Empty;

            set1 = set1.Add(MachineId.FromIndex(1));
            set1.GetMachineIdIndex(MachineId.FromIndex(1)).Should().Be(0);
            set1.GetMachineIdIndex(MachineId.FromIndex(2)).Should().Be(-1);
        }
Ejemplo n.º 4
0
        public void SetExistenceTests()
        {
            var set1 = MachineSet(1, 2);

            set1[1].Should().BeTrue();
            set1[2].Should().BeTrue();

            set1 = set1.Remove(MachineId.FromIndex(1));
            set1[1].Should().BeFalse();

            set1 = set1.Add(MachineId.FromIndex(1));
            set1[1].Should().BeTrue();
        }
Ejemplo n.º 5
0
        public Task ShutdownDoesNotProcessEnqueuedEvents()
        {
            // This test is "weird" in the sense that it relies on a "controlled" race condition. We need to check that
            // the master does not wait for events to finish processing to complete its shutdown. The way we do this is
            // force an arbitrary delay when processing events, and then make sure that we haven't processed any after
            // shutdown.
            //
            // * If we do it with a cancellation token on shutdown started, then we have a race condition, because the
            //   token will be triggered, and the item could be processed before shutdown finishes.
            // * If we do it with a separate lock, we'll need some sort of delay which will be equivalent to what we do
            //   now.
            // * We can't use a cancellation token on shutdown finished, because shutdown awaits for the action blocks
            //   to complete, and this means we have a deadlock.
            //
            // By doing things this way, we are relying on the fact that it is unlikely for a thread to not run for a
            // second. If we assume that's true, then the slowdown will resume after shutdown has started waiting, and
            // we will do the appropriate fast-return path.
            var configuration = new SlowedContentLocationEventStoreConfiguration()
            {
                Slowdown = TimeSpan.FromSeconds(1)
            };

            var eventHandler = new TestEventHandler();

            return(WithContentLocationEventStore(async(tracingContext, clock, fileSystem, eventStore) =>
            {
                var context = new OperationContext(tracingContext);
                var sequencePoint = new EventSequencePoint(clock.UtcNow);

                eventStore.StartProcessing(context, sequencePoint).ShouldBeSuccess();

                eventStore.AddLocations(context, MachineId.FromIndex(0), new[] { new ContentHashWithSize(ContentHash.Random(), 1) }).ShouldBeSuccess();

                (await eventStore.ShutdownAsync(context)).ShouldBeSuccess();

                eventHandler.EventsHandled.Should().Be(0);
            }, configuration, eventHandler));
        }
Ejemplo n.º 6
0
 private MachineIdSet CreateMachineIdSet(int startByteOffset, int length, params int[] setBits)
 {
     return(new BitMachineIdSet(new byte[length], startByteOffset).Add(setBits.Select(b => MachineId.FromIndex(b)).ToArray()));
 }