Ejemplo n.º 1
0
            internal void ComparePrimaryKey()
            {
                TestComponentConfig config = default;

                config.ComponentType = 1;
                config.Category      = 2;
                config.Delay         = 3.14;

                TestComponentConfig.CodegenKey configKey = default;
                configKey.ComponentType = 1;
                configKey.Category      = 2;

                TestComponentConfig.CodegenKey configInvalidKey = default;
                configInvalidKey.ComponentType = 1;
                configInvalidKey.Category      = 3;

                MlosUnitTestProxy.TestComponentConfig configProxy = default;

                unsafe
                {
                    IntPtr ptr = new IntPtr(&config);
                    configProxy.Buffer = ptr;
                }

                uint hashValue1 = configProxy.GetKeyHashValue <THash>();
                uint hashValue2 = configKey.GetKeyHashValue <THash>();
                uint hashValue3 = configInvalidKey.GetKeyHashValue <THash>();

                Assert.Equal(hashValue1, hashValue2);
                Assert.NotEqual(hashValue1, hashValue3);
            }
Ejemplo n.º 2
0
        public void VerifyMetadataHash()
        {
            TestComponentConfig config = default;
            ulong hashCode             = ((ICodegenKey)config).CodegenTypeHash();

            Assert.Equal <ulong>(0x92ab3b94501efa6c, hashCode);

            Point point         = default;
            ulong pointHashCode = ((ICodegenKey)point).CodegenTypeHash();

            Assert.Equal <ulong>(0x7b7fb0279242f8d7, pointHashCode);
        }
Ejemplo n.º 3
0
        public void VerifyMetadataHash()
        {
            TestComponentConfig config = default;
            ulong hashCode             = ((ICodegenKey)config).CodegenTypeHash();

            Assert.Equal <ulong>(expected: 0x92ab3b94501efa6c, actual: hashCode);

            Point point         = default;
            ulong pointHashCode = ((ICodegenKey)point).CodegenTypeHash();

            Assert.Equal <ulong>(expected: 0x80D34F1D0805C19D, actual: pointHashCode);
        }
Ejemplo n.º 4
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());
                }
            }
        }
Ejemplo n.º 5
0
        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());
                }
            }
        }