public ADRFunctionTest() { var adrStrategy = new Mock <ILoRaADRStrategy>(MockBehavior.Strict); adrStrategy .Setup(x => x.ComputeResult(It.IsNotNull <LoRaADRTable>(), It.IsAny <float>(), It.IsAny <DataRateIndex>(), It.IsAny <int>(), It.IsAny <DataRateIndex>())) .Returns((LoRaADRTable table, double snr, int dr, int power, int maxDr) => { return(table.Entries.Count >= LoRaADRTable.FrameCountCaptureCount ? new LoRaADRResult() { NumberOfFrames = table.Entries.Count } : null); }); adrStrategy.Setup(x => x.DefaultNbRep).Returns(1); adrStrategy.Setup(x => x.DefaultTxPower).Returns(0); adrStrategy.Setup(x => x.MinimumNumberOfResult).Returns(20); var strategyProvider = new Mock <ILoRaADRStrategyProvider>(MockBehavior.Strict); strategyProvider .Setup(x => x.GetStrategy()) .Returns(adrStrategy.Object); this.adrStore = new LoRaADRInMemoryStore(); this.adrManager = new LoRaADRServerManager(this.adrStore, strategyProvider.Object, new LoRaInMemoryDeviceStore(), NullLogger <LoRaADRServerManager> .Instance); this.adrExecutionItem = new ADRExecutionItem(this.adrManager); }
public FunctionBundlerTest() { var strategy = new Mock <ILoRaADRStrategy>(MockBehavior.Strict); strategy.Setup(x => x.DefaultNbRep).Returns(1); strategy.Setup(x => x.DefaultTxPower).Returns(0); strategy.Setup(x => x.MinimumNumberOfResult).Returns(20); strategy .Setup(x => x.ComputeResult(It.IsAny <LoRaADRTable>(), It.IsAny <float>(), It.IsAny <DataRateIndex>(), It.IsAny <int>(), It.IsAny <DataRateIndex>())) .Returns((LoRaADRTable table, float snr, DataRateIndex upstreamDr, int minTxPower, DataRateIndex maxDr) => { return(new LoRaADRResult { CanConfirmToDevice = true, DataRate = upstreamDr, TxPower = 0 }); }); var strategyProvider = new Mock <ILoRaADRStrategyProvider>(MockBehavior.Strict); strategyProvider .Setup(x => x.GetStrategy()) .Returns(strategy.Object); // .Returns(new LoRaADRStandardStrategy()); var cacheStore = new LoRaInMemoryDeviceStore(); this.adrStore = new LoRaADRInMemoryStore(); this.adrManager = new LoRaADRServerManager(this.adrStore, strategyProvider.Object, cacheStore, NullLogger <LoRaADRServerManager> .Instance); this.adrExecutionItem = new ADRExecutionItem(this.adrManager); var items = new IFunctionBundlerExecutionItem[] { new DeduplicationExecutionItem(cacheStore), this.adrExecutionItem, new NextFCntDownExecutionItem(new FCntCacheCheck(cacheStore)), new PreferredGatewayExecutionItem(cacheStore, new NullLogger <PreferredGatewayExecutionItem>(), null), }; this.functionBundler = new FunctionBundlerFunction(items); }
public async System.Threading.Tasks.Task TestADRAsync(string testName, DevEui devEUI, IList <LoRaADRTableEntry> tableEntries, RadioMetadata radioMetadata, bool expectDefaultAnswer, LoRaADRResult expectedResult) { this.output.WriteLine($"Starting test {testName}"); var region = TestUtils.TestRegion; ILoRaADRStrategyProvider provider = new LoRaADRStrategyProvider(NullLoggerFactory.Instance); using var inMemoryStore = new LoRaADRInMemoryStore(); var loRaADRManager = new Mock <LoRaADRManagerBase>(MockBehavior.Loose, inMemoryStore, provider, NullLogger <LoRaADRManagerBase> .Instance) { CallBase = true }; _ = loRaADRManager.Setup(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>())).ReturnsAsync(1U); // If the test does not expect a default answer we trigger default reset before if (!expectDefaultAnswer) { _ = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(radioMetadata.DataRate), radioMetadata.DataRate, region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry() { Snr = 0, FCnt = 1, DevEUI = devEUI, GatewayCount = 1, GatewayId = "gateway" }); } for (var i = 0; i < tableEntries.Count; i++) { await loRaADRManager.Object.StoreADREntryAsync(tableEntries[i]); } var adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(radioMetadata.DataRate), radioMetadata.DataRate, region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate); Assert.Equal(expectedResult.DataRate, adrResult.DataRate); Assert.Equal(expectedResult.NbRepetition, adrResult.NbRepetition); Assert.Equal(expectedResult.TxPower, adrResult.TxPower); Assert.Equal(expectedResult.FCntDown, adrResult.FCntDown); loRaADRManager.Verify(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>()), Times.AtLeastOnce, "NextFCntDown"); this.output.WriteLine($"Test {testName} finished"); }
public async System.Threading.Tasks.Task CheckADRReturnsDefaultValueIfCacheCrash() { var devEUI = TestEui.GenerateDevEui(); var region = RegionManager.EU868; ILoRaADRStrategyProvider provider = new LoRaADRStrategyProvider(NullLoggerFactory.Instance); var datarate = DataRateIndex.DR5; using var inMemoryStore = new LoRaADRInMemoryStore(); var loRaADRManager = new Mock <LoRaADRManagerBase>(MockBehavior.Loose, inMemoryStore, provider, NullLogger <LoRaADRManagerBase> .Instance) { CallBase = true }; _ = loRaADRManager.Setup(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>())).ReturnsAsync(1U); // setup table with default value _ = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry() { Snr = 0, FCnt = 1, DevEUI = devEUI, GatewayCount = 1, GatewayId = "gateway" }); // Add measurement and compute new ADR for (uint i = 0; i < 21; i++) { await loRaADRManager.Object.StoreADREntryAsync( new LoRaADRTableEntry() { DevEUI = devEUI, FCnt = i, GatewayCount = 1, GatewayId = "mygateway", Snr = 50 }); } var adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate); Assert.Equal(DR5, adrResult.DataRate); Assert.Equal(7, adrResult.TxPower); Assert.Equal(1, adrResult.NbRepetition); // reset cache and check we get default values _ = await loRaADRManager.Object.ResetAsync(devEUI); adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry() { Snr = 0, FCnt = 1, DevEUI = devEUI, GatewayCount = 1, GatewayId = "gateway" }); Assert.Equal(DR5, adrResult.DataRate); Assert.Equal(0, adrResult.TxPower); Assert.Equal(1, adrResult.NbRepetition); loRaADRManager.Verify(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>()), Times.AtLeastOnce, "NextFCntDown"); }