private (MachineList, ClusterState, MachineReputationTracker, MachineMapping[]) Setup(MachineList.Settings settings, int amountMachines, int designatedLocations) { var context = new Context(Logger); var machines = Enumerable.Range(1, amountMachines).Select(n => (ushort)n).ToArray(); var machineIdSet = new ArrayMachineIdSet(machines); var machineMappings = machines.Select(m => new MachineMapping(new MachineLocation(m.ToString()), new MachineId(m))).ToArray(); var clusterState = new ClusterState(primaryMachineId: default, machineMappings);
public void TestSerializationFromArrayMachineIdSetToBitVersion() { var originalMachineIdSet = new ArrayMachineIdSet(Enumerable.Range(1, MachineIdSet.BitMachineIdSetThreshold + 1).Select(id => (ushort)id).ToArray()); var deserializedMachineIdSet = Copy(originalMachineIdSet); Assert.NotEqual(originalMachineIdSet.GetType(), deserializedMachineIdSet.GetType()); Assert.Equal(originalMachineIdSet.EnumerateMachineIds().OrderBy(x => x.Index), deserializedMachineIdSet.EnumerateMachineIds().OrderBy(x => x.Index)); }
public void ArrayMachineIdSet_ExhaustiveTests() { for (int length = 0; length < 15; length++) { for (int machineId = 0; machineId < length * 8; machineId++) { MachineIdSet set = new ArrayMachineIdSet(new ushort[0]); set = set.Add(new MachineId(machineId)); set.Count.Should().Be(1, $"Set byte length={length}, Id(bit offset)={machineId}"); } } }
public void ContentLocationEntryRoundtrip() { var model = MetadataServiceSerializer.TypeModel; CheckSerializationRoundtrip(model, ContentLocationEntry.Create( ArrayMachineIdSet.Create(new[] { new MachineId(12), new MachineId(23) }), 12345, DateTime.UtcNow, DateTime.UtcNow - TimeSpan.FromDays(1))); CheckSerializationRoundtrip(model, ContentLocationEntry.Create( MachineIdSet.Empty, 46456, new UnixTime(1))); }
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); } } }