Exemplo n.º 1
0
    public BaseSharedChannelBenchmark()
    {
        globalChannelMemoryRegionView = SharedMemoryRegionView.Create <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize);
        sharedChannelMemoryMapView    = SharedMemoryMapView.Create(SharedChannelMemoryMapName, SharedMemorySize);

        MlosProxyInternal.GlobalMemoryRegion globalMemoryRegion = globalChannelMemoryRegionView.MemoryRegion();

        sharedChannel = new TestSharedChannel(sharedChannelMemoryMapView, globalMemoryRegion.ControlChannelSynchronization);

        settingsAssemblyManager.RegisterAssembly(typeof(MlosContext).Assembly);
        settingsAssemblyManager.RegisterAssembly(typeof(AssemblyInitializer).Assembly);

        // Preallocate class type messages to avoid heap allocations.
        //
        stringViewArray    = new StringViewArray();
        stringViewArray.Id = 1;
        stringViewArray.Strings[0].Value = "12345";
        stringViewArray.Strings[1].Value = "54321";
        stringViewArray.Strings[2].Value = "abc";
        stringViewArray.Strings[3].Value = "cba";
        stringViewArray.Strings[4].Value = "sbs";

        wideStringMultiMessage = new WideStringMultiMessage();
        wideStringMultiMessage.StringMessages[0].Id = 4;
        wideStringMultiMessage.StringMessages[0].Strings[0].Value = "Test_Name9876";
        wideStringMultiMessage.StringMessages[0].Strings[1].Value = "Test_Name19876";
        wideStringMultiMessage.StringMessages[0].Strings[2].Value = "Test_Name1239876";
        wideStringMultiMessage.StringMessages[0].Strings[3].Value = "Test_Name45659876";
        wideStringMultiMessage.StringMessages[0].Strings[4].Value = "Test_Name901239876";

        pointMessage.X = 4;
        pointMessage.Y = 5;
    }
Exemplo n.º 2
0
        public SharedChannelTests()
        {
            // Load the registry settings assemblies.
            //
            _ = SettingsAssemblyInitializer.GetGlobalDispatchTable();

            // Initialize shared channel.
            //
            globalChannelMemoryRegionView = SharedMemoryRegionView.Create <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize);
            sharedChannelMemoryMapView    = SharedMemoryMapView.Create(SharedChannelMemoryMapName, SharedMemorySize);

            MlosProxyInternal.GlobalMemoryRegion globalMemoryRegion = globalChannelMemoryRegionView.MemoryRegion();

            sharedChannel = new TestSharedChannel(sharedChannelMemoryMapView, globalMemoryRegion.ControlChannelSynchronization);
        }
Exemplo n.º 3
0
        public void Insert()
        {
            using var sharedMemoryRegionView      = SharedMemoryRegionView.Create <MlosProxyInternal.SharedConfigMemoryRegion>(SharedMemoryMapName, SharedMemorySize);
            sharedMemoryRegionView.CleanupOnClose = true;

            MlosProxyInternal.SharedConfigMemoryRegion sharedConfigMemoryRegion = sharedMemoryRegionView.MemoryRegion();

            var hashTable = new SharedConfigManager();

            hashTable.SetMemoryRegion(sharedConfigMemoryRegion);

            for (int i = 0; i < 500; i++)
            {
                {
                    TestComponentConfig config = default;
                    config.ComponentType = (uint)(i + 1);
                    config.Category      = 2;
                    config.Delay         = 5;

                    var componentConfig = ComponentConfig.Create(config);

                    hashTable.Insert(componentConfig);
                }

                {
                    var componentConfig = new ComponentConfig <TestComponentConfig, UnitTestProxy.TestComponentConfig>();

                    componentConfig.Config.ComponentType = (uint)(i + 1);
                    componentConfig.Config.Category      = 2;

                    hashTable.UpdateConfig(componentConfig);
                    Assert.Equal <double>(5, componentConfig.Config.Delay);
                }

                {
                    var componentConfig = new ComponentConfig <TestComponentStatistics, UnitTestProxy.TestComponentStatistics>();
                    componentConfig.Config.Id                = i;
                    componentConfig.Config.RefCount.Value    = 5;
                    componentConfig.Config.Counters[0].Value = 2;

                    hashTable.Insert(componentConfig);
                }
            }

            for (int i = 0; i < 500; i++)
            {
                {
                    var componentConfig = new ComponentConfig <TestComponentConfig, UnitTestProxy.TestComponentConfig>();

                    componentConfig.Config.ComponentType = (uint)(i + 1);
                    componentConfig.Config.Category      = 2;

                    hashTable.UpdateConfig(componentConfig);
                    Assert.Equal <double>(5, componentConfig.Config.Delay);
                }

                {
                    var componentConfig = new ComponentConfig <TestComponentStatistics, UnitTestProxy.TestComponentStatistics>();
                    componentConfig.Config.Id = i;

                    hashTable.UpdateConfig(componentConfig);

                    Assert.Equal <ulong>(5, componentConfig.Config.RefCount.Value);
                    Assert.Equal <ulong>(2, componentConfig.Config.Counters[0].Value);
                }

                {
                    var componentStatistics = new TestComponentStatistics()
                    {
                        Id = i
                    };
                    SharedConfig <UnitTestProxy.TestComponentStatistics> sharedConfig = hashTable.Lookup(componentStatistics);
                }

                {
                    TestComponentStatistics.CodegenKey codegenKey = default;
                    codegenKey.Id = i;

                    SharedConfig <UnitTestProxy.TestComponentStatistics> sharedConfig = hashTable.Lookup(codegenKey);

                    Assert.Equal <ulong>(5, sharedConfig.Config.RefCount.Load());
                    Assert.Equal <ulong>(2, sharedConfig.Config.Counters[0].Load());
                }
            }
        }