@Test void shouldReplaceExpiredSubscriptionsWithNewOnes() { ValidatorApiChannel validatorApiChannel = mock(ValidatorApiChannel.class); StableSubnetSubscriber stableSubnetSubscriber = new StableSubnetSubscriber(validatorApiChannel, new Random(), 1); stableSubnetSubscriber.onSlot(UInt64.valueOf(0)); ArgumentCaptor<Set<SubnetSubscription>> firstSubscriptionUpdate = ArgumentCaptor.forClass(Set.class); ArgumentCaptor<Set<SubnetSubscription>> secondSubscriptionUpdate = ArgumentCaptor.forClass(Set.class); verify(validatorApiChannel).subscribeToPersistentSubnets(firstSubscriptionUpdate.capture()); assertThat(firstSubscriptionUpdate.getValue()).hasSize(1); UInt64 firstUnsubscriptionSlot = firstSubscriptionUpdate.getValue().stream().findFirst().get().getUnsubscriptionSlot(); stableSubnetSubscriber.onSlot(firstUnsubscriptionSlot.minus(UInt64.ONE)); verifyNoMoreInteractions(validatorApiChannel); stableSubnetSubscriber.onSlot(firstUnsubscriptionSlot); verify(validatorApiChannel, times(2)) .subscribeToPersistentSubnets(secondSubscriptionUpdate.capture()); UInt64 secondUnsubscriptionSlot = secondSubscriptionUpdate.getValue().stream().findFirst().get().getUnsubscriptionSlot(); assertThat(firstUnsubscriptionSlot).isNotEqualByComparingTo(secondUnsubscriptionSlot); }
public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); void onSlot(UInt64 slot); void updateValidatorCount(final int validatorCount); }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); void onSlot(UInt64 slot); void updateValidatorCount(final int validatorCount);  }