Beispiel #1
0
    public BaseSharedChannelBenchmark()
    {
        globalChannelMemoryRegionView = SharedMemoryRegionView.CreateNew <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize);
        sharedChannelMemoryMapView    = SharedMemoryMapView.CreateNew(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;
    }
Beispiel #2
0
        public SharedChannelTests()
        {
            // Load the registry settings assemblies.
            //
            _ = SettingsAssemblyInitializer.GetGlobalDispatchTable();

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

            MlosProxyInternal.GlobalMemoryRegion globalMemoryRegion = globalChannelMemoryRegionView.MemoryRegion();

            sharedChannel = new TestSharedChannel(sharedChannelMemoryMapView, globalMemoryRegion.ControlChannelSynchronization);
        }
        public void Insert()
        {
            // Create a shared memory map.
            //
            using var sharedMemoryRegionView      = SharedMemoryRegionView.CreateNew <MlosProxyInternal.SharedConfigMemoryRegion>(SharedMemoryMapName, SharedMemorySize);
            sharedMemoryRegionView.CleanupOnClose = true;

            // Create a shared config manager, and register created test shared memory map.
            //
            using var sharedConfigManager = new SharedConfigManager();
            sharedConfigManager.RegisterSharedConfigMemoryRegion(sharedMemoryRegionView);

            sharedConfigManager.CleanupOnClose = true;

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

                    sharedConfigManager.Insert(componentConfig);
                }

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

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

                    sharedConfigManager.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;

                    sharedConfigManager.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;

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

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

                    sharedConfigManager.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 = sharedConfigManager.Lookup(componentStatistics);
                }

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

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

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