Fix missing sorting

This commit is contained in:
Manfred Karrer 2018-10-16 12:40:10 -05:00
parent 254059b411
commit dabe6907e1
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
2 changed files with 9 additions and 3 deletions

View File

@ -99,6 +99,8 @@ public class ArbitratorSelection {
.count();
tuple.second.set(count);
});
arbitratorTuples.sort(Comparator.comparing(e -> e.first));
arbitratorTuples.sort(Comparator.comparingInt(e -> e.second.get()));
return arbitratorTuples.get(0).first;
}

View File

@ -30,9 +30,13 @@ public class ArbitratorSelectionTest {
@Test
public void testGetLeastUsedArbitrator() {
// We get least used selected
List<String> lastAddressesUsedInTrades = Arrays.asList("arb1", "arb2", "arb1");
Set<String> arbitrators = new HashSet<>(Arrays.asList("arb1", "arb2"));
String result = ArbitratorSelection.getLeastUsedArbitrator(lastAddressesUsedInTrades, arbitrators);
List<String> lastAddressesUsedInTrades;
Set<String> arbitrators;
String result;
lastAddressesUsedInTrades = Arrays.asList("arb1", "arb2", "arb1");
arbitrators = new HashSet<>(Arrays.asList("arb1", "arb2"));
result = ArbitratorSelection.getLeastUsedArbitrator(lastAddressesUsedInTrades, arbitrators);
assertEquals("arb2", result);
// if all are same we use first according to alphanumeric sorting