/// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessorManager"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group the event processors are associated with.  Events are read in the context of this group.</param>
        /// <param name="connectionString">TODO.</param>
        /// <param name="partitionManager">Interacts with the storage system with responsibility for creation of checkpoints and for ownership claim.</param>
        /// <param name="options">The set of options to use for the event processors.</param>
        /// <param name="onInitialize">A callback action to be called on <see cref="EventProcessorClient.InitializeProcessingForPartitionAsyncHandler" />.</param>
        /// <param name="onStop">A callback action to be called on <see cref="EventProcessorClient.ProcessingForPartitionStoppedAsyncHandler" />.</param>
        /// <param name="onProcessEvent">A callback action to be called on <see cref="EventProcessorClient.ProcessEventAsyncHandler" />.</param>
        /// <param name="onProcessException">A callback action to be called on <see cref="EventProcessorClient.ProcessErrorAsyncHandler" />.</param>
        ///
        public EventProcessorManager(string consumerGroup,
                                     string connectionString,
                                     PartitionManager partitionManager   = null,
                                     EventProcessorClientOptions options = null,
                                     Action <InitializePartitionProcessingContext> onInitialize = null,
                                     Action <PartitionProcessingStoppedContext> onStop          = null,
                                     Action <EventProcessorEvent> onProcessEvent       = null,
                                     Action <ProcessorErrorContext> onProcessException = null)
        {
            ConsumerGroup         = consumerGroup;
            Connection            = new EventHubConnection(connectionString);
            InnerPartitionManager = partitionManager ?? new MockCheckPointStorage();

            // In case it has not been specified, set the maximum receive wait time to 2 seconds because the default
            // value (1 minute) would take too much time.

            Options = options?.Clone() ?? new EventProcessorClientOptions();

            if (Options.MaximumReceiveWaitTime == null)
            {
                Options.MaximumReceiveWaitTime = TimeSpan.FromSeconds(2);
            }

            OnInitialize       = onInitialize;
            OnStop             = onStop;
            OnProcessEvent     = onProcessEvent;
            OnProcessException = onProcessException;

            EventProcessors = new List <EventProcessorClient>();
        }
Beispiel #2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessorManager"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group the event processors are associated with.  Events are read in the context of this group.</param>
        /// <param name="client">The client used to interact with the Azure Event Hubs service.</param>
        /// <param name="partitionManager">Interacts with the storage system with responsibility for creation of checkpoints and for ownership claim.</param>
        /// <param name="options">The set of options to use for the event processors.</param>
        /// <param name="onInitialize">A callback action to be called on <see cref="PartitionProcessor.InitializeAsync" />.</param>
        /// <param name="onClose">A callback action to be called on <see cref="PartitionProcessor.CloseAsync" />.</param>
        /// <param name="onProcessEvents">A callback action to be called on <see cref="PartitionProcessor.ProcessEventsAsync" />.</param>
        /// <param name="onProcessError">A callback action to be called on <see cref="PartitionProcessor.ProcessErrorAsync" />.</param>
        ///
        public EventProcessorManager(string consumerGroup,
                                     EventHubClient client,
                                     PartitionManager partitionManager      = null,
                                     EventProcessorOptions options          = null,
                                     Action <PartitionContext> onInitialize = null,
                                     Action <PartitionContext, PartitionProcessorCloseReason> onClose = null,
                                     Action <PartitionContext, IEnumerable <EventData>, CancellationToken> onProcessEvents = null,
                                     Action <PartitionContext, Exception, CancellationToken> onProcessError = null)
        {
            ConsumerGroup = consumerGroup;
            InnerClient   = client;

            PartitionProcessorFactory = partitionContext =>
                                        new PartitionProcessor
                                        (
                onInitialize,
                onClose,
                onProcessEvents,
                onProcessError
                                        );

            InnerPartitionManager = partitionManager ?? new InMemoryPartitionManager();

            // In case it has not been specified, set the maximum receive wait time to 2 seconds because the default
            // value (1 minute) would take too much time.

            Options = options?.Clone() ?? new EventProcessorOptions();

            if (Options.MaximumReceiveWaitTime == null)
            {
                Options.MaximumReceiveWaitTime = TimeSpan.FromSeconds(2);
            }

            EventProcessors = new List <EventProcessor <PartitionProcessor> >();
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the Device Driver System.
        /// </summary>
        static public void Initialize()
        {
            // Create Device Manager
            deviceManager = new DeviceManager();

            // Create Interrupt Manager
            interruptManager = new InterruptManager();

            // Create the Device Driver Manager
            deviceDriverRegistry = new DeviceDriverRegistry(PlatformArchitecture.X86);

            // Create the PCI Controller Manager
            pciControllerManager = new PCIControllerManager(deviceManager);

            // Setup hardware abstraction interface
            var hardware = new Mosa.CoolWorld.x86.HAL.Hardware();

            // Set device driver system to the hardware HAL
            Mosa.HardwareSystem.HAL.SetHardwareAbstraction(hardware);

            // Set the interrupt handler
            Mosa.HardwareSystem.HAL.SetInterruptHandler(InterruptManager.ProcessInterrupt);

            partitionManager = new PartitionManager(deviceManager);
        }
        public void ConstructorValidatesThePartitionProcessorFactory()
        {
            EventHubClient   mockClient           = Mock.Of <EventHubClient>();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            Assert.That(() => new EventProcessor <PartitionProcessor>(EventHubConsumer.DefaultConsumerGroupName, mockClient, null, mockPartitionManager), Throws.InstanceOf <ArgumentException>());
        }
Beispiel #5
0
	// Use this for initialization
	void Start () {

        autorizedNotes = new List<string>();
        autorizedNotes.Add("z");
        autorizedNotes.Add("q");
        autorizedNotes.Add("s");
        autorizedNotes.Add("d");

        notez = Resources.Load ("Prefab/Note-z") as GameObject;
		noteq = Resources.Load ("Prefab/Note-q") as GameObject;
		notes = Resources.Load ("Prefab/Note-s") as GameObject;
		noted = Resources.Load ("Prefab/Note-d") as GameObject;
		note1 = Resources.Load ("Prefab/Note-1") as GameObject;
		note2 = Resources.Load ("Prefab/Note-2") as GameObject;
		player = GameObject.FindGameObjectWithTag ("Player");
		papaNote = new GameObject();
		papaNote.name = "PapaNote";
		sizeTab = 0;
		timer = 0;
		index = 0;
		noteSheet = new string[maxSize];
		dico = GameObject.FindGameObjectWithTag ("Dico").GetComponent<DicoSong>().tabSong;
		partition = GameObject.FindGameObjectWithTag ("Partition").GetComponent<PartitionManager>();

        animator = FindObjectOfType<PlayerController>().animator;

        cC = GameObject.FindGameObjectWithTag("Player").GetComponent<CharacterController>();
    }
 public ReadableOptionsMock(string consumerGroup,
                            EventHubClient eventHubClient,
                            Func <PartitionContext, PartitionProcessor> partitionProcessorFactory,
                            PartitionManager partitionManager,
                            EventProcessorOptions options) : base(consumerGroup, eventHubClient, partitionProcessorFactory, partitionManager, options)
 {
 }
        public void ConstructorValidatesTheEventHubClient()
        {
            Func <PartitionContext, PartitionProcessor> mockFactory = Mock.Of <Func <PartitionContext, PartitionProcessor> >();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            Assert.That(() => new EventProcessor <PartitionProcessor>(EventHubConsumer.DefaultConsumerGroupName, null, mockFactory, mockPartitionManager), Throws.InstanceOf <ArgumentException>());
        }
Beispiel #8
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessorManager"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group the event processors are associated with.  Events are read in the context of this group.</param>
        /// <param name="connectionString">The connection string to use for connecting to the Event Hubs namespace.</param>
        /// <param name="partitionManager">Interacts with the storage system with responsibility for creation of checkpoints and for ownership claim.</param>
        /// <param name="clientOptions">The set of options to use for the event processors.</param>
        /// <param name="onInitialize">A callback action to be called on <see cref="EventProcessorClient.PartitionInitializingAsync" />.</param>
        /// <param name="onStop">A callback action to be called on <see cref="EventProcessorClient.PartitionClosingAsync" />.</param>
        /// <param name="onProcessEvent">A callback action to be called on <see cref="EventProcessorClient.ProcessEventAsync" />.</param>
        /// <param name="onProcessError">A callback action to be called on <see cref="EventProcessorClient.ProcessErrorAsync" />.</param>
        ///
        public EventProcessorManager(string consumerGroup,
                                     string connectionString,
                                     PartitionManager partitionManager                    = null,
                                     EventProcessorClientOptions clientOptions            = null,
                                     Action <PartitionInitializingEventArgs> onInitialize = null,
                                     Action <PartitionClosingEventArgs> onStop            = null,
                                     Action <ProcessEventArgs> onProcessEvent             = null,
                                     Action <ProcessErrorEventArgs> onProcessError        = null)
        {
            ConnectionStringProperties connectionStringProperties = ConnectionStringParser.Parse(connectionString);

            FullyQualifiedNamespace = connectionStringProperties.Endpoint.Host;
            EventHubName            = connectionStringProperties.EventHubName;
            ConsumerGroup           = consumerGroup;
            ConnectionFactory       = () => new EventHubConnection(connectionString);
            InnerPartitionManager   = partitionManager ?? new MockCheckPointStorage();

            // In case it has not been specified, set the maximum wait time to 2 seconds because the default
            // value (1 minute) would take too much time.

            ClientOptions = clientOptions?.Clone() ?? new EventProcessorClientOptions();

            if (ClientOptions.MaximumWaitTime == null)
            {
                ClientOptions.MaximumWaitTime = TimeSpan.FromSeconds(2);
            }

            OnInitialize   = onInitialize;
            OnStop         = onStop;
            OnProcessEvent = onProcessEvent;
            OnProcessError = onProcessError;

            EventProcessors = new List <EventProcessorClient>();
        }
        public void creates_new_root_partition_on_first_epoch()
        {
            var reader = new FakeReader(withoutRecords: true);
            var writer = new FakeWriter();

            IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory());

            partitionManager.Initialize();

            Assert.Collection(writer.WrittenRecords,
                              r => {
                Assert.Equal(LogRecordType.PartitionType, r.RecordType);
                Assert.IsType <PartitionTypeLogRecord>(r);
                Assert.Equal("Root", ((PartitionTypeLogRecord)r).Record.StringPayload);
                Assert.Equal(partitionManager.RootTypeId, ((PartitionTypeLogRecord)r).Record.Header.RecordId);
                Assert.Equal(Guid.Empty, ((PartitionTypeLogRecord)r).Record.SubHeader.PartitionId);
            },
                              r => {
                Assert.Equal(LogRecordType.Partition, r.RecordType);
                Assert.IsType <PartitionLogRecord>(r);
                Assert.Equal("Root", ((PartitionLogRecord)r).Record.StringPayload);
                Assert.Equal(partitionManager.RootId, ((PartitionLogRecord)r).Record.Header.RecordId);
                Assert.Equal(partitionManager.RootTypeId, ((PartitionLogRecord)r).Record.SubHeader.PartitionTypeId);
                Assert.Equal(Guid.Empty, ((PartitionLogRecord)r).Record.SubHeader.ParentPartitionId);
            });

            Assert.True(writer.IsFlushed);
        }
Beispiel #10
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ShortWaitTimeMock"/> class.
 /// </summary>
 ///
 /// <param name="consumerGroup">The name of the consumer group this event processor is associated with.  Events are read in the context of this group.</param>
 /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param>
 /// <param name="partitionProcessorFactory">Creates an instance of a class implementing the <see cref="IPartitionProcessor" /> interface.</param>
 /// <param name="partitionManager">Interacts with the storage system, dealing with ownership and checkpoints.</param>
 /// <param name="options">The set of options to use for this event processor.</param>
 ///
 public ShortWaitTimeMock(string consumerGroup,
                          EventHubClient eventHubClient,
                          Func <PartitionContext, CheckpointManager, IPartitionProcessor> partitionProcessorFactory,
                          PartitionManager partitionManager,
                          EventProcessorOptions options) : base(consumerGroup, eventHubClient, partitionProcessorFactory, partitionManager, options)
 {
 }
Beispiel #11
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessorManager"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group the event processors are associated with.  Events are read in the context of this group.</param>
        /// <param name="client">The client used to interact with the Azure Event Hubs service.</param>
        /// <param name="partitionManager">Interacts with the storage system with responsibility for creation of checkpoints and for ownership claim.</param>
        /// <param name="options">The set of options to use for the event processors.</param>
        /// <param name="onInitialize">A callback action to be called on <see cref="EventProcessorClient.InitializeProcessingForPartitionAsync" />.</param>
        /// <param name="onClose">A callback action to be called on <see cref="EventProcessorClient.ProcessingForPartitionStoppedAsync" />.</param>
        /// <param name="onProcessEvents">A callback action to be called on <see cref="EventProcessorClient.ProcessEventsAsync" />.</param>
        /// <param name="onProcessException">A callback action to be called on <see cref="EventProcessorClient.ProcessExceptionAsync" />.</param>
        ///
        public EventProcessorManager(string consumerGroup,
                                     EventHubConnection client,
                                     PartitionManager partitionManager      = null,
                                     EventProcessorClientOptions options    = null,
                                     Action <PartitionContext> onInitialize = null,
                                     Action <PartitionContext, PartitionProcessorCloseReason> onClose    = null,
                                     Action <PartitionContext, IEnumerable <EventData> > onProcessEvents = null,
                                     Action <PartitionContext, Exception> onProcessException             = null)
        {
            ConsumerGroup = consumerGroup;
            Connection    = client;

            InnerPartitionManager = partitionManager ?? new InMemoryPartitionManager();

            // In case it has not been specified, set the maximum receive wait time to 2 seconds because the default
            // value (1 minute) would take too much time.

            Options = options?.Clone() ?? new EventProcessorClientOptions();

            if (Options.MaximumReceiveWaitTime == null)
            {
                Options.MaximumReceiveWaitTime = TimeSpan.FromSeconds(2);
            }

            OnInitialize       = onInitialize;
            OnClose            = onClose;
            OnProcessEvents    = onProcessEvents;
            OnProcessException = onProcessException;

            EventProcessors = new List <EventProcessorClient>();
        }
Beispiel #12
0
        private async Task InitializeAsync()
        {
            this.documentServiceLeaseStoreManager = await ChangeFeedProcessorCore <T> .InitializeLeaseStoreManagerAsync(this.documentServiceLeaseStoreManager, this.leaseContainer, this.leaseContainerPrefix, this.instanceName).ConfigureAwait(false);

            this.partitionManager = this.BuildPartitionManager();
            this.initialized      = true;
        }
Beispiel #13
0
 internal static unsafe void AssertMFTRecordCachingInvariance(PartitionManager manager)
 {
     if (null == manager)
     {
         throw new ArgumentNullException();
     }
     foreach (GenericPartition partition in manager.EnumeratePartitions())
     {
         if (!partition.ShouldCapture)
         {
             continue;
         }
         for (int index = 0; index < 5; index++)
         {
             GC.Collect();
             // We want to make sure the returned value is always the same pointer, otherwise
             // we will eat memory.
             NtfsMFTFileRecord c1 = GetMFTRecord(partition);
             NtfsMFTFileRecord c2 = GetMFTRecord(partition);
             if (!object.ReferenceEquals(c1, c2))
             {
                 throw new AssertionException("MFT file record caching is not GC resistant.");
             }
         }
     }
 }
Beispiel #14
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="MockEventProcessorClient" /> class.
        /// </summary>
        ///
        /// <param name="storageManager">The client responsible for interaction with durable storage, responsible for persisting checkpoints and load-balancing state.</param>
        /// <param name="consumerGroup">The name of the consumer group this processor is associated with.  Events are read in the context of this group.</param>
        /// <param name="fullyQualifiedNamespace">The fully qualified Event Hubs namespace to connect to.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="eventHubName">The name of the specific Event Hub to associate the processor with.</param>
        /// <param name="connectionFactory">A factory used to provide new <see cref="EventHubConnection" /> instances.</param>
        /// <param name="clientOptions">The set of options to use for this processor.</param>
        /// <param name="fakePartitionProcessing"><c>true</c> if <see cref="RunPartitionProcessingAsync" /> should be overridden; otherwise, <c>false</c>.</param>
        /// <param name="numberOfPartitions">The amount of partitions the associated Event Hub has.</param>
        ///
        internal MockEventProcessorClient(PartitionManager storageManager,
                                          string consumerGroup           = "consumerGroup",
                                          string fullyQualifiedNamespace = "somehost.com",
                                          string eventHubName            = "somehub",
                                          Func <EventHubConnection> connectionFactory = default,
                                          EventProcessorClientOptions clientOptions   = default,
                                          bool fakePartitionProcessing = true,
                                          int numberOfPartitions       = 3) : base(storageManager, consumerGroup, fullyQualifiedNamespace, eventHubName, connectionFactory, clientOptions)
        {
            StorageManager = storageManager;

            var partitionIds = Enumerable
                               .Range(1, numberOfPartitions)
                               .Select(p => p.ToString())
                               .ToArray();

            foreach (var partitionId in partitionIds)
            {
                EventPipeline[partitionId] = new ConcurrentQueue <EventData>();
            }

            FakeRunPartitionProcessingAsync = fakePartitionProcessing;

            ProcessErrorAsync += eventArgs =>
            {
                Exception[] newException = new Exception[] { eventArgs.Exception };
                ExceptionCalls.AddOrUpdate(
                    eventArgs.PartitionId,
                    newException,
                    (partitionId, value) => value.Concat(newException).ToArray());

                return(Task.CompletedTask);
            };

            ProcessEventAsync += eventArgs =>
            {
                EventData[] newEvent = new EventData[] { eventArgs.Data };
                ProcessEventCalls.AddOrUpdate(
                    eventArgs.Partition.PartitionId,
                    newEvent,
                    (partitionId, value) => value.Concat(newEvent).ToArray());

                return(Task.CompletedTask);
            };

            PartitionInitializingAsync += eventArgs =>
            {
                InitializeCalls.AddOrUpdate(eventArgs.PartitionId, 1, (partitionId, value) => value + 1);

                return(Task.CompletedTask);
            };

            PartitionClosingAsync += eventArgs =>
            {
                CloseCalls.AddOrUpdate(eventArgs.PartitionId, 1, (partitionId, value) => value + 1);
                StopReasons[eventArgs.PartitionId] = eventArgs.Reason;

                return(Task.CompletedTask);
            };
        }
Beispiel #15
0
    private void Start()
    {
        TrackCount = SongInfoCustom.Instance.currentSong.partitions[partitionId].tracks.Length;

        trackNextIndices   = new int[TrackCount];
        TracksColors       = new Color[TrackCount];
        nextLayerZ         = new float[TrackCount];
        queueForTracks     = new Queue <MusicNode> [TrackCount];
        previousMusicNodes = new MusicNode[TrackCount];
        for (int i = 0; i < TrackCount; i++)
        {
            //Init Variable for each track
            trackNextIndices[i]   = 0;
            queueForTracks[i]     = new Queue <MusicNode>();
            previousMusicNodes[i] = null;
            nextLayerZ[i]         = FirstLayerZ;
            TracksColors[i]       = PartitionManager.Instance.trackColor[i];
        }

        partitionManager = PartitionManager.Instance;
        songInfo         = SongInfoCustom.Instance.currentSong;
        //initialize arrays
        //TrackCount = SpawnOffset.Length;
        for (int i = 0; i < TrackCount; i++)
        {
        }
        tracksNode = songInfo.partitions[partitionId].tracks; //keep a reference of the tracks

        roleSprite.fillAmount = 0;
    }
        public void ConstructorValidatesTheConsumerGroup(string consumerGroup)
        {
            EventHubClient mockClient = Mock.Of <EventHubClient>();
            Func <PartitionContext, PartitionProcessor> mockFactory = Mock.Of <Func <PartitionContext, PartitionProcessor> >();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            Assert.That(() => new EventProcessor <PartitionProcessor>(consumerGroup, mockClient, mockFactory, mockPartitionManager), Throws.InstanceOf <ArgumentException>());
        }
 public ShortWaitTimeMock(PartitionManager partitionManager,
                          string consumerGroup,
                          string fullyQualifiedNamespace,
                          string eventHubName,
                          Func <EventHubConnection> connectionFactory,
                          EventProcessorClientOptions clientOptions) : base(partitionManager, consumerGroup, fullyQualifiedNamespace, eventHubName, connectionFactory, clientOptions)
 {
 }
 public ReadableOptionsMock(string consumerGroup,
                            PartitionManager partitionManager,
                            string fullyQualifiedNamespace,
                            string eventHubName,
                            TokenCredential credential,
                            EventProcessorClientOptions options = default) : base(consumerGroup, partitionManager, fullyQualifiedNamespace, eventHubName, credential, options)
 {
 }
        public void throws_on_unexpected_system_log_record_type()
        {
            var reader = new FakeReader(UnexpectedSystemLogRecord);

            IPartitionManager partitionManager = new PartitionManager(reader, new FakeWriter(), new LogV3RecordFactory());

            Assert.Throws <ArgumentOutOfRangeException>(() => partitionManager.Initialize());
        }
    void Awake()
    {
        instance = this;
        discoveredSongs = new Dictionary<string, bool>();
        constellations = new Dictionary<constellationType, List<string>>();
        
        InitConstellations();
		constel = GameObject.FindGameObjectsWithTag("Const");
    }
        private async Task InitializeAsync()
        {
            string monitoredContainerRid = await this.monitoredContainer.GetMonitoredContainerRidAsync(this.monitoredContainerRid);

            this.monitoredContainerRid            = this.monitoredContainer.GetLeasePrefix(this.changeFeedLeaseOptions, monitoredContainerRid);
            this.documentServiceLeaseStoreManager = await ChangeFeedProcessorCore <T> .InitializeLeaseStoreManagerAsync(this.documentServiceLeaseStoreManager, this.leaseContainer, this.monitoredContainerRid, this.instanceName).ConfigureAwait(false);

            this.partitionManager = this.BuildPartitionManager();
            this.initialized      = true;
        }
        /// <summary>
        ///   Provides test cases for the constructor tests.
        /// </summary>
        ///
        public static IEnumerable <object[]> ConstructorCreatesDefaultOptionsCases()
        {
            EventHubClient mockClient = Mock.Of <EventHubClient>();
            Func <PartitionContext, PartitionProcessor> mockFactory = Mock.Of <Func <PartitionContext, PartitionProcessor> >();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            yield return(new object[] { new ReadableOptionsMock(EventHubConsumer.DefaultConsumerGroupName, mockClient, mockFactory, mockPartitionManager), "no options" });

            yield return(new object[] { new ReadableOptionsMock(EventHubConsumer.DefaultConsumerGroupName, mockClient, mockFactory, mockPartitionManager, null), "null options" });
        }
        public void ConstructorCreatesTheIdentifier()
        {
            EventHubClient mockClient = Mock.Of <EventHubClient>();
            Func <PartitionContext, PartitionProcessor> mockFactory = Mock.Of <Func <PartitionContext, PartitionProcessor> >();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            var eventProcessor = new EventProcessor <PartitionProcessor>(EventHubConsumer.DefaultConsumerGroupName, mockClient, mockFactory, mockPartitionManager);

            Assert.That(eventProcessor.Identifier, Is.Not.Null);
            Assert.That(eventProcessor.Identifier, Is.Not.Empty);
        }
        public void reads_root_partition_only_once()
        {
            var reader = new FakeReader();
            var writer = new FakeWriter();

            IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory());

            partitionManager.Initialize();
            partitionManager.Initialize();

            Assert.Empty(writer.WrittenRecords);
            Assert.Equal(2, reader.ReadCount);
        }
        public void configures_record_factory_with_root_partition_id()
        {
            var reader        = new FakeReader();
            var recordFactory = new LogV3RecordFactory();

            IPartitionManager partitionManager = new PartitionManager(reader, new FakeWriter(), recordFactory);

            partitionManager.Initialize();

            var streamRecord = (LogV3StreamRecord)recordFactory.CreateStreamRecord(Guid.NewGuid(), 1, DateTime.UtcNow, 1, "stream-1");

            Assert.Equal(partitionManager.RootId, streamRecord.Record.SubHeader.PartitionId);
        }
Beispiel #26
0
        private async Task InitializeAsync()
        {
            string monitoredDatabaseAndContainerRid = await this.monitoredContainer.GetMonitoredDatabaseAndContainerRidAsync();

            string leaseContainerPrefix = this.monitoredContainer.GetLeasePrefix(this.changeFeedLeaseOptions.LeasePrefix, monitoredDatabaseAndContainerRid);

            if (this.documentServiceLeaseStoreManager == null)
            {
                this.documentServiceLeaseStoreManager = await DocumentServiceLeaseStoreManagerBuilder.InitializeAsync(this.leaseContainer, leaseContainerPrefix, this.instanceName).ConfigureAwait(false);
            }

            this.partitionManager = this.BuildPartitionManager();
            this.initialized      = true;
        }
        public void reads_root_partition_once_initialized()
        {
            var rootPartitionId     = Guid.NewGuid();
            var rootPartitionTypeId = Guid.NewGuid();
            var reader = new FakeReader(rootPartitionId, rootPartitionTypeId);
            var writer = new FakeWriter();

            IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory());

            partitionManager.Initialize();

            Assert.Empty(writer.WrittenRecords);
            Assert.Equal(rootPartitionId, partitionManager.RootId);
            Assert.Equal(rootPartitionTypeId, partitionManager.RootTypeId);
        }
Beispiel #28
0
        void OneTimeInit()
        {
            SessionStateSection config = RuntimeConfig.GetAppConfig().SessionState;

            s_configPartitionResolverType           = config.PartitionResolverType;
            s_configStateConnectionString           = config.StateConnectionString;
            s_configStateConnectionStringFileName   = config.ElementInformation.Properties["stateConnectionString"].Source;
            s_configStateConnectionStringLineNumber = config.ElementInformation.Properties["stateConnectionString"].LineNumber;
            s_configCompressionEnabled = config.CompressionEnabled;

            if (_partitionResolver == null)
            {
                String stateConnectionString = config.StateConnectionString;

                SessionStateModule.ReadConnectionString(config, ref stateConnectionString, "stateConnectionString");

                s_singlePartitionInfo = (StateServerPartitionInfo)CreatePartitionInfo(stateConnectionString);
            }
            else
            {
                s_usePartition     = true;
                s_partitionManager = new PartitionManager(new CreatePartitionInfo(CreatePartitionInfo));
            }

            s_networkTimeout = (int)config.StateNetworkTimeout.TotalSeconds;

            string appId  = HttpRuntime.AppDomainAppId;
            string idHash = Convert.ToBase64String(CryptoUtil.ComputeSHA256Hash(Encoding.UTF8.GetBytes(appId)));

            // Make sure that we have a absolute URI, some hosts(Cassini) don't provide this.
            if (appId.StartsWith("/", StringComparison.Ordinal))
            {
                s_uribase = appId + "(" + idHash + ")/";
            }
            else
            {
                s_uribase = "/" + appId + "(" + idHash + ")/";
            }

            // We only need to do this in one instance
            s_onAppDomainUnload = new EventHandler(OnAppDomainUnload);
            Thread.GetDomain().DomainUnload += s_onAppDomainUnload;

            s_oneTimeInited = true;
        }
Beispiel #29
0
        public IJournalCore ToJournal()
        {
            var meta        = CreateJournalMetadata(_config);
            var fileFactory = new CompositeFileFactory(_config.FileFlags);

            if (_server != null)
            {
                var partMan = new PartitionManager(meta, _access, fileFactory, _server);
                return(new JournalCore(meta, partMan));
            }
            else
            {
                var server  = new AsyncJournalServer(_serverTasksLatency);
                var partMan = new PartitionManager(meta, _access, fileFactory, server);
                partMan.OnDisposed += server.Dispose;
                return(new JournalCore(meta, partMan));
            }
        }
        private PartitionManager CreatePartitionManager <T>(EPartitionType pariPartitionType,
                                                            DisposableTempDir dir,
                                                            ICompositeFileFactory compositeFileFactory,
                                                            EFileAccess access,
                                                            string[] paritions,
                                                            params string[] symbols)
        {
            CreateSubDirs(paritions, dir.DirName);
            JournalMetadata meta = CreateMetadata <T>(pariPartitionType, dir.DirName,
                                                      symbols);
            var txLog = new Mock <ITxLog>();

            txLog.Setup(s => s.Get()).Returns(new TxRec {
                JournalMaxRowID = RowIDUtil.ToRowID(1, 10)
            });

            var part = new PartitionManager(meta, access, compositeFileFactory, new AsyncJournalServer(TimeSpan.FromSeconds(1)), txLog.Object);

            return(part);
        }
        public void creates_root_partition_in_case_it_partially_failed_previously()
        {
            var rootPartitionTypeId = Guid.NewGuid();
            var reader = new FakeReader(rootPartitionId: null, rootPartitionTypeId);
            var writer = new FakeWriter();

            IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory());

            partitionManager.Initialize();

            Assert.True(partitionManager.RootId.HasValue);
            Assert.Equal(rootPartitionTypeId, partitionManager.RootTypeId);
            Assert.Collection(writer.WrittenRecords,
                              r => {
                Assert.Equal(LogRecordType.Partition, r.RecordType);
                Assert.IsType <PartitionLogRecord>(r);
                Assert.Equal("Root", ((PartitionLogRecord)r).Record.StringPayload);
                Assert.Equal(partitionManager.RootId, ((PartitionLogRecord)r).Record.Header.RecordId);
                Assert.Equal(partitionManager.RootTypeId, ((PartitionLogRecord)r).Record.SubHeader.PartitionTypeId);
                Assert.Equal(Guid.Empty, ((PartitionLogRecord)r).Record.SubHeader.ParentPartitionId);
            });
        }
        public void ConstructorClonesOptions()
        {
            EventHubClient mockClient = Mock.Of <EventHubClient>();
            Func <PartitionContext, PartitionProcessor> mockFactory = Mock.Of <Func <PartitionContext, PartitionProcessor> >();
            PartitionManager mockPartitionManager = Mock.Of <PartitionManager>();

            var options = new EventProcessorOptions
            {
                InitialEventPosition   = EventPosition.FromOffset(55),
                MaximumMessageCount    = 43,
                MaximumReceiveWaitTime = TimeSpan.FromMinutes(65)
            };

            var eventProcessor = new ReadableOptionsMock(EventHubConsumer.DefaultConsumerGroupName, mockClient, mockFactory, mockPartitionManager, options);
            EventProcessorOptions clonedOptions = eventProcessor.Options;

            Assert.That(clonedOptions, Is.Not.Null, "The constructor should have set the options.");
            Assert.That(clonedOptions, Is.Not.SameAs(options), "The constructor should have cloned the options.");
            Assert.That(clonedOptions.InitialEventPosition, Is.EqualTo(options.InitialEventPosition), "The constructor should have the correct initial event position.");
            Assert.That(clonedOptions.MaximumMessageCount, Is.EqualTo(options.MaximumMessageCount), "The constructor should have the correct maximum message count.");
            Assert.That(clonedOptions.MaximumReceiveWaitTime, Is.EqualTo(options.MaximumReceiveWaitTime), "The constructor should have the correct maximum receive wait time.");
        }