public void BitMachineIdSet_ExhaustiveTests() { for (int length = 0; length < 15; length++) { for (int machineId = 0; machineId < length * 8; machineId++) { MachineIdSet set = new BitMachineIdSet(new byte[length], 0); set = set.Add(new MachineId(machineId)); set.Count.Should().Be(1, $"Set byte length={length}, Id(bit offset)={machineId}"); } } }
public void BinManagerExcludesMaster() { var amountMachines = 4; var machineMappings = Enumerable.Range(0, amountMachines).Select(i => new MachineMapping(new MachineLocation(i.ToString()), new MachineId(i))).ToArray(); var masterMapping = machineMappings[0]; var clusterState = new ClusterState(machineMappings[0].Id, machineMappings) { EnableBinManagerUpdates = true }; foreach (var mapping in machineMappings) { clusterState.AddMachine(mapping.Id, mapping.Location); } clusterState.SetMasterMachine(masterMapping.Location); clusterState.InitializeBinManagerIfNeeded(locationsPerBin: amountMachines, _clock, expiryTime: TimeSpan.Zero); var binMappings = clusterState.GetBinMappings().ThrowIfFailure(); foreach (var binMapping in binMappings) { // Master should not be there binMapping.Length.Should().Be(amountMachines - 1); binMapping.Should().NotContain(masterMapping.Id); } // Make sure this stays true after updates var inactiveMachines = new BitMachineIdSet(new byte[amountMachines], 0); inactiveMachines = inactiveMachines.SetExistenceBits(MachineIdCollection.Create(machineMappings[1].Id), true); clusterState.SetMachineStates(inactiveMachines).ShouldBeSuccess(); binMappings = clusterState.GetBinMappings().ThrowIfFailure(); foreach (var binMapping in binMappings) { // Master and inactive should not be there binMapping.Length.Should().Be(amountMachines - 2); binMapping.Should().NotContain(masterMapping.Id); } }
public void BitMachineIdSet_ExhaustiveTests() { for (int length = 0; length < 15; length++) { for (int machineId = 0; machineId < length * 8; machineId++) { MachineIdSet set = new BitMachineIdSet(new byte[length], 0); set = set.Add(new MachineId(machineId)); var index = set.GetMachineIdIndex(new MachineId(machineId)); index.Should().NotBe(-1, $"Id={new MachineId(machineId)}, Ids in set=[{string.Join(", ", set.EnumerateMachineIds())}]"); // We recreating a set each time, so the index is always 0. index.Should().Be(0); (set.EnumerateMachineIds().ToList()[index]).Should().Be(new MachineId(machineId)); set.Count.Should().Be(1, $"Set byte length={length}, Id(bit offset)={machineId}"); } } }
public void MachineIdSets_Are_TheSame_ExhaustiveTests() { // This test makes sure that the main functionality provides the same results for both BitMachineIdSet and ArrayMachineIdSet for (int length = 0; length < 15; length++) { MachineIdSet set = new BitMachineIdSet(new byte[length], 0); for (int machineId = 0; machineId < length * 8; machineId++) { set = set.Add(new MachineId(machineId)); var arrayIdSet = new ArrayMachineIdSet(set.EnumerateMachineIds().Select(i => (ushort)i.Index)); set.EnumerateMachineIds().Should().BeEquivalentTo(arrayIdSet.EnumerateMachineIds()); var indexFromArray = arrayIdSet.EnumerateMachineIds().ToList().IndexOf(new MachineId(machineId)); var index = set.GetMachineIdIndex(new MachineId(machineId)); index.Should().Be(indexFromArray); var index2 = arrayIdSet.GetMachineIdIndex(new MachineId(machineId)); index2.Should().Be(index); } } }